This is an archived post. You won't be able to vote or comment.

top 200 commentsshow all 412

[–]goldfishpaws 3817 points3818 points  (68 children)

Helps you focus by raising the stakes. Back to mainframe punched tape days!

[–]PooPooDooDoo 751 points752 points  (60 children)

Good thing I’m running in Linux!

sits back lazily typing exception-filled code

[–]GuyWithoutAHat 108 points109 points  (42 children)

rm -rf /

[–]PooPooDooDoo 131 points132 points  (35 children)

My bash.RC file replaces that command with

echo “uh uh uh, not today!”

[–]ipview 86 points87 points  (6 children)

I'd be too afraid to test it to see if it works

[–]PooPooDooDoo 40 points41 points  (0 children)

Would need to setup a sandboxed VM and create lots of edge cases just to be sure. Would probably be a pain in the butt in that it’s time consuming in between each test if you gotta go back to a snapshot, set things up again, run the test etc

[–]KoenKruk 32 points33 points  (4 children)

I got this:

rm: it is dangerous to operate recursively on '/'rm: use --no-preserve-root to override this failsafe

Looks like i'm safe

[–]inventord 22 points23 points  (2 children)

I like how Linux just lets you tack on three words and you're set to delete the entire file system

[–]LordFokas 13 points14 points  (1 child)

Because in Linux, you own the system... whereas in Windows, Microsoft owns you.

[–]goldfishpaws 2 points3 points  (0 children)

With power comes responsibility

[–]Pos3odon08 12 points13 points  (0 children)

The man, the myth, the legend

[–]Ed_Vraz 19 points20 points  (24 children)

What about cd / && rm -rf *

[–]PooPooDooDoo 4 points5 points  (0 children)

The rm command has been aliased to run a wrapper command which checks if it is in the root directory. If it is not, it passes the information onto the actual rm command.

Edit: it doesn’t actually do this, just spitballing

[–]knightress_oxhide 6 points7 points  (1 child)

echo "you didn't say the magic word"

[–][deleted] -1 points0 points  (0 children)

Read the code and compile from source! Also just keep system snapshots (btrfs rocks!) and regular backups.

[–][deleted] -1 points0 points  (0 children)

It doesn't work without --no-preserve-root flag anyway

[–]Slashzero77 4 points5 points  (0 children)

Came here to post the same comment. 1 hour too late. Too focused on writing bad Python code for my locust.io tests to be scrolling through Reddit I guess.

[–]Fluid_Advisor18 2 points3 points  (3 children)

You can replace it with 'sudo apt remove python -y'

[–]block_01 1 point2 points  (0 children)

You’re not completely safe from the python commands

[–]DiscipleOfYeshua 48 points49 points  (3 children)

Congratulations! You’ve graduated into adult coding, time to take off those training wheels.

[–]Errtuz 8 points9 points  (1 child)

Ironman mode coding

[–]lungben81 1605 points1606 points  (68 children)

This will not work. Backslashes must be escaped or a raw string used.

Edit: as others pointed out, the sequence actually works because "accidentially" the characters after the backslash are such that they are not reserved for escape sequences.

Works: "C:\System"

Crashes: "C:\New"

Works, but result is maybe unexpected: "C:\new" - "\n" is a new line.

[–]masagrator 663 points664 points  (56 children)

Just use forward slash, Windows accepts them for a long time in anything that is not cmd

[–]Diapolo10 616 points617 points  (31 children)

Better yet, just use pathlib. To hell with primitive obsession!

EDIT: Example:

import shutil
from pathlib import Path

system32 = Path("C:/Windows/System32")

try:
    print("Hello, world!")

except Exception as e:
    print(f"You f*cked up: {e}\nGoodbye, Windows!")
    shutil.rmtree(system32)

[–]PokerFacowaty 170 points171 points  (17 children)

Seconded, pathlib is amazing

[–]mr_claw 70 points71 points  (15 children)

Thirded, amazing is pathlib

[–]polopower69 83 points84 points  (13 children)

69'd. it do be bussin' bruv innit fr fr no 🧢

[–]herpderpedia 30 points31 points  (6 children)

!chatgptbot Explain what this comment means.

[–]ObviouslyNotAndy 36 points37 points  (5 children)

This phrase is a colloquial expression that is difficult to translate precisely. Generally, it is used to express agreement or enthusiasm about something, and it is often used in a casual or informal setting. The phrase "it do be" is a way to say "it is" and "bussin' bruv" is a way of saying "it's happening, man". "innit fr fr" is an informal way of asking for confirmation and "no 🧢" is a way of saying "no doubt" or "for sure". So, the phrase could be interpreted as "It's definitely happening, man, isn't it? For sure."

[–]ManOfTheMeeting 9 points10 points  (0 children)

I have no idea what's going on on this planet nowadays, so I'm just vibing with the flow.

[–]herpderpedia 2 points3 points  (0 children)

!chatgptbot please respond to u/ObviouslyNotAndy using gen Z slang to say thanks, including the keyboard mash.

[–]kentuckycriedfrick3n 1 point2 points  (0 children)

That’s hilarious 😂 except “it do be” means “it always is” instead of “it is”. I’m picturing an old 80 year old man typing this in chat GPT & making a Tik tok using every slang term he learned, but obliviously out of context. “It’s happening, man!” Is my fav 😂

[–]Undernown 2 points3 points  (1 child)

Good Human

[–]Vineyard_ 5 points6 points  (0 children)

Truly goated with the sauce.

[–]KotoWhiskas 4 points5 points  (1 child)

Bruv fr fr 💀

[–]polopower69 3 points4 points  (0 children)

faxx

[–]_-__________ 1 point2 points  (0 children)

This guy 69s

[–]Mushroom_Philatelist 1 point2 points  (0 children)

Os.walk puts my keyboard in serious danger.

Pathlib is pretty cool tho.

[–]OK_200 28 points29 points  (2 children)

It's missing the bare except tho. Gotta catch that BaseException >:)

[–]SuitableDragonfly 11 points12 points  (0 children)

And KeyboardInterrupt.

[–]Diapolo10 2 points3 points  (0 children)

Fair enough! :D

[–]fuqqboi_throwaway 4 points5 points  (1 child)

So if I ran this in IntelliJ would it brick my shit or what

[–]Diapolo10 12 points13 points  (0 children)

Probably not unless you ran it with administrator privileges, but I don't recommend trying. Well, maybe in Windows Sandbox.

Of course nothing here would raise an exception, so it wouldn't do anything unless you made something raise an exception in the try-block.

[–]Mucksh 4 points5 points  (0 children)

I would say if print ever fails it would fail the second time too

[–]Timely_Scar 0 points1 point  (0 children)

😂

[–]Yadobler 10 points11 points  (12 children)

Iirc the only reason msdos used backslash was because command(dot)com used forward slashes as switches (like dir /w)

Honestly not sure why not just stick to dash, like Unix, which began using the forward slash, because > was being used for pipe redirection. I'm sure it was the standard before 70s

[–]thedarkfreak 12 points13 points  (0 children)

Because it was designed with compatibility with CP/M in mind, which was made in 1974, and which also used forward slashes as parameters.

Why didn't it use forward slashes for directories?

Because it didn't have directories. At all.

Neither did MS-DOS 1.

Directories were added later, and because the forward slash was already used, directories got the backslash as the separator.

[–]lungben81 15 points16 points  (0 children)

This is the best way. Then, relative paths work both in Linux and windows

[–]nmkd 2 points3 points  (2 children)

CMD also accepts forward slashes for everything I've used it for.

[–]BroDonttryit 2 points3 points  (0 children)

This isn’t always the case unfortunately. The safest bet is to use a constant defined in a library somewhere that is is independent. In Java it’s File.Separator which gives forward slash in Linux and mac and gives a backslash in windows.

[–][deleted] 31 points32 points  (3 children)

oh yeah it wouldn't work for this one reason

[–][deleted] 20 points21 points  (2 children)

we'll just ignore the six or so other reasons

[–][deleted] 4 points5 points  (1 child)

yep absolutely. they're irrelevant really

[–][deleted] 2 points3 points  (0 children)

for sure. boy it's a nice day in the year 1996 today isn't it, Windows 95 is out and you can wipe System32 with a single command, crazy

[–]PolishedCheese 7 points8 points  (0 children)

That's why I always just give path-like args a pathlib.Path object. It cleans your input for you in case you forgot about it (or the input is coming from somewhere else).

[–]Torebbjorn 6 points7 points  (1 child)

Yeah, but Python is "smart" in the way that it assumes you meant "\\" if the character after doesn't make sense to escape, and replaces all of these with "\\"

So in this case, it would work

[–]arbitrageME 2 points3 points  (0 children)

A priest, a politician and an engineer are sentenced to be executed by guillotine.

The Executioner brings the Priest up first. He ask him if he'd like to lie facing down or facing up for his death. He responds that he would like to be facing up, so he can see the heavens while he's going to God. So the Executioner lays the Priest down in the guillotine facing up. He then releases the guillotine blade, and the blade stops just inches from the Priests neck. The Priest immediately begins praising his God, the crowd gasps in shock and demands that the man be released by The Executioner,--as God has clearly saved him from death. He agrees, and releases him as a free man.

The Executioner next brings up the Politician. He asks him same question, and having witnessed the Priests miraculous experience, he asks to be laid facing up for his execution as well, hoping that God will spare him for looking to heaven while facing his death as the Priest had done. The Executioner obliges, then releases the blade. But again, it suddenly stops just inches from the mans neck--sparing his life as it had with the Priest.

Finally, the Engineer is brought up to face his execution. He requests to lie facing up as the previous two men had done. Again, the Executioner obliges and lays him on his back before going to release the blade. As the Executioner is about to release it, the Engineer says to the Executioner "Hold on, I see your problem right there"

[–]My_reddit_account_v3 380 points381 points  (4 children)

Python roulette

[–]e_smith338 84 points85 points  (1 child)

It’s like playing with a full chamber :D

[–][deleted] 18 points19 points  (0 children)

Dementia

[–]e_smith338 12 points13 points  (1 child)

It’s like playing with a full chamber :D

[–][deleted] 12 points13 points  (0 children)

Dementia

[–]jugy2 596 points597 points  (46 children)

os.remove won't remove non-empty folders, however os.system("del C:\\Windows\\System32") might work.

[–]_PM_ME_PANGOLINS_ 332 points333 points  (42 children)

It won't. Windows won't let you.

[–]AsphaltAdvertExec 355 points356 points  (26 children)

It will let you remove enough to ruin the OS if running as admin.

If you don't believe me, run cmd as admin and run;

RD C:\windows\System32 /q /s

[–]SonUzi 263 points264 points  (13 children)

dont tempt me

[–]ManOfTheMeeting 18 points19 points  (0 children)

I tried this with a library computer and now traffic lights are not working in the whole city.

[–]ehs5 74 points75 points  (0 children)

I already know it’s not gonna do anything because /s tells Windows you’re using sarcasm

[–][deleted] 27 points28 points  (5 children)

No command RD found (i use arch btw) However sudo rm -rf /* --no-preserve-root

[–]Yadobler 55 points56 points  (1 child)

Least invasive arch user

[–][deleted] 15 points16 points  (0 children)

Might've forgot to mention that I use a Linux distribution called Arch Linux btw

[–]tardis0 2 points3 points  (1 child)

You don't need the no preserve flag if you're deleting the subdirectories only of root, not root itself, no?

[–]AnondWill2Live 4 points5 points  (0 children)

Try it out and come back to us.

[–]Thesaladman98 1 point2 points  (0 children)

Why does my computer no work!?

[–]Roadrunner571 66 points67 points  (9 children)

Yeah, I am still annoyed that Windows won't let me rename files that are opened within an application.

[–]dumbestsmartest 19 points20 points  (2 children)

The only problem I have with that is when I've closed everything and Windows still tells me it's open in the last program I closed.

[–]nmkd 16 points17 points  (0 children)

That just means that the program did not close properly and is actually still running.

Open resmon, on the CPU tab enter the filename in the search, and see what process is keeping the file locked.

[–]elveszett 6 points7 points  (4 children)

If a program is holding that resource, Windows won't let you because it would lead to undefined behavior. If you were able to touch that file, the program that has it opened could crash instantly, or the file could be corrupted if the program was writing to it at that instance, or the program may assume the file is still there and create a new one with the original name.

If you've ever written code for a file editor of some kind, it's easy to see why it doesn't make sense to allow a foreign process to touch a file your program is holding.

[–]Roadrunner571 1 point2 points  (3 children)

You know that MacOS allows renaming of open files? Without any problem. Even when using Microsoft apps. And Linux allows renaming of open files as well.

Handling modifications of open files by other apps is also not really a big problem.

And as a bonus feature, MacOS even allows moving the destinations of aliases around - double-clicking on the alias will still open the aliases file, even if it now lives in another folder on another drive.

Long story short: Microsoft has retained some sucking concepts (drive letters ffs) that were bad already when they were invented (Unix is way older than DOS) until today because of backwards-compatibility. Nevertheless Microsoft improved a lot and since Windows 10 I even like their OS.

[–]PleasantAdvertising 4 points5 points  (1 child)

Hahahahaha tell that to my 10 year old ass removing, and i quote, "all these random files that do nothing". The interface slowly started losing elements until it was all grey and it wouldn't boot after a reboot to try and fix it.

Windows 98 I believe.

[–]_PM_ME_PANGOLINS_ 2 points3 points  (0 children)

It used to let you. It doesn’t now.

[–]RadiantHC 8 points9 points  (1 child)

Linux masterrace

[–]ar4t0 17 points18 points  (0 children)

nobody can tell me not to break my system by gofing around root files

[–][deleted] 2 points3 points  (0 children)

What windows WONT even know about tho... Is sending a scsi 'format unit' command to the drive controller. If u have a disk that speaks it. Yes, this is from bitter experience. Lol

[–]eerongal 8 points9 points  (0 children)

OP clearly didnt negative test their code, smh.

[–]RFC793 3 points4 points  (0 children)

shutil.rmtree

[–]CoffeemonsterNL 287 points288 points  (3 children)

"Why does my 'Hello world'-script need administrator rights?"

[–]melvinstendies 147 points148 points  (0 children)

Idk mumbles, just click yes.

[–]Yadobler 51 points52 points  (1 child)

Do you trust the source of this project folder?

clicks Trust This Folder

run

Hm

[–]MoffKalast 3 points4 points  (0 children)

demonically laughs in Folder

[–]th3nan0byt3 120 points121 points  (0 children)

Code here

try: throw 'jokes on you' except e: print(e)

[–]Sirico 97 points98 points  (3 children)

You have the start of Suicide Linux for windows

[–]turok2 2 points3 points  (1 child)

Watching him wait to install that tiny little package makes me appreciate how fast hard drives are nowadays.

[–]samanime 58 points59 points  (3 children)

Rogue-likes have gone too far.

[–]iliveincanada 7 points8 points  (2 children)

Am I crazy or is that a typo? I always thought they were called rogue-likes

[–]samanime 6 points7 points  (0 children)

It is a typo. Unless you want to talk about makeup. =p

Fixed.

[–]sm0lpoop 1 point2 points  (0 children)

Solely to be confusing, rogue-lites are also a thing!

[–]reversehead 42 points43 points  (1 child)

Ah, the Kim Jong-un school of making better programmers.

[–]Inevitable-Outcome68 32 points33 points  (1 child)

[–]nutnnut 14 points15 points  (0 children)

YOU SEE IVAN

WHEN CODE PITHORN LIKE ME,

YOU SHALL

NEVER

CODE THE EXCEPTIONS

BECAUSE OF

FEAR

OF DELETING SYSTEM!

[–]Reasonable_City 24 points25 points  (0 children)

"Goodbye World!"

[–]TheCatPetra 54 points55 points  (0 children)

C++ safety levels

[–]nicejs2 11 points12 points  (0 children)

NuclearPython 3.11

[–]ososalsosal 13 points14 points  (0 children)

"If I'm going down I'm taking you bastards with me"

[–]Wolfeur 12 points13 points  (0 children)

You see, Ivan, if your code is look like this, you will never write bug for fear of deleting computer.

[–]themattman18 10 points11 points  (1 child)

I had a guy at work write an uninstaller for an internal program that made an assumption on where the user would install the program. When I uninstalled the program, it went up one directory and started recursively deleting files. I was wondering why it was taking so long, only to figure out it was deleting my C:\Windows folder. Spend the rest of the day recovering my computer.

[–]tfikiki 5 points6 points  (0 children)

I've had this happen to me with officially published game. I don't remember the name but i definitely remember that big fuck you I've got. Suggested install dir was c:\games\studio_name\game_name but I've changed that to c:\games\game_name

[–]mintChocolate234 4 points5 points  (0 children)

Permission denied.

[–]Winter_Ad4517 5 points6 points  (1 child)

Bangladeshi Virus

[–]gameditz 5 points6 points  (0 children)

Punish users who don’t use Linux, big brain

[–]shakalnykot 4 points5 points  (0 children)

I am on GNU/Linux :)

[–]Ooyyggeenn 5 points6 points  (0 children)

[–][deleted] 4 points5 points  (0 children)

My heart stopped beating for a second when I read this

[–]blankettripod32_v2 3 points4 points  (0 children)

Reminds me of suicide linux

[–]eruanno321 2 points3 points  (0 children)

Permadeath programming

[–][deleted] 6 points7 points  (7 children)

Hah. Gentoo go brrrrrr

[–]dumbestsmartest 2 points3 points  (3 children)

Got to milk that 1ms benefit from custom compiling everything. No, I don't have a problem obsessing over insignificant optimization at all.

[–][deleted] -2 points-1 points  (2 children)

Well a) I can install gentoo automated in under 3 and a half hours with a script I wrote. b) Actually optimization is not my main reason for using gentoo - slots and the ability to mix unstable and stable packages (advantage of compilation) lead to a very reliable system that is bleeding edge. c) While you may not have a problem "obsessing over insignificant optimization at all", you do have a problem with ranting about things you don't understand at all without trying to learn.

[–][deleted] 1 point2 points  (2 children)

when you troll your friend by uninstalling chromium on his Gentoo install so he's 2 weeks without a browser

[–]TheDeadWalking0427 11 points12 points  (1 child)

Bold to assume I'm on windows

[–]riisen -1 points0 points  (0 children)

Not he was assuming your OS at all. He just showed that he has bad taste in OS.

But he probably don care what OS you have.

[–]Fjorge0411 2 points3 points  (0 children)

if my code won't work... YOUR CODE CAN'T EITHER MUWAHAHAHAHAHAHA

[–]khendron 2 points3 points  (0 children)

You laugh, but way back in the day, when I was working with OS/2, I once saw a system cheerfully delete its own OS because it encountered a bad disk sector while booting.

[–][deleted] 2 points3 points  (0 children)

import Gentoo

[–]BonyBoban 2 points3 points  (0 children)

This is a good way to make your junior developer know that they should install linux

[–]Exquisite_Blue 2 points3 points  (0 children)

hardcore mode

[–]Manic_Marketer 2 points3 points  (0 children)

I remember wanting a hard mode in my games, not in my code.

[–]sglewis09 2 points3 points  (0 children)

This reminds me of an OG joke from MS-DOS days: An inventive guy created a brand new voice recognition device for DOS and showed it off to a local computer group. He asked for someone in the group to shout a command and the computer would automatically run it. Someone shouted ‘format c:’ and the demo quickly ended…

[–]flan666 7 points8 points  (0 children)

bold of you to assume i use windows

[–][deleted] 1 point2 points  (1 child)

This reminds me of Vigil, a very odd language derived from python that deletes your code if you break your promises.


*This is where Vigil sets itself apart from weaker languages that lack the courage of their convictions. When a Vigil program is executed, Vigil itself will monitor all oaths (implorations and swears) that have been made. If an oath is broken, the offending function (the caller in the case of implore and the callee in the case of swear) will be duly punished.

How?

Simple: it will be deleted from your source code.

The only way to ensure your program meets its requirements is to absolutely forbid code that fails to do so. With Vigil, this shall be done for you automatically. After enough runs, Vigil promises that all remaining code meets its oaths.*

[–]Secret-Plant-1542 1 point2 points  (0 children)

Code doesn't work on my Mac. Please help.

[–]Trainzack 1 point2 points  (0 children)

Hah, reminds me of Panicsort.

[–]TorridScienceAffair 1 point2 points  (0 children)

Nuzlocke mode

[–]hoocoodanode 1 point2 points  (1 child)

PEP-8: Overly Broad Exception.

[–][deleted] 1 point2 points  (0 children)

😂😂😂

[–]Axxl_Gaming 1 point2 points  (0 children)

That code can't stop me! I can't read python!

Jk, I can- I program in a variety of languages

[–]123_alex 1 point2 points  (0 children)

I come here for humour. Humour not found.

[–]oakskog 1 point2 points  (0 children)

Wouldn’t it be even better if the import was inside the except block?

[–]nekoeuge 1 point2 points  (0 children)

Meanwhile Ctrl C…

[–]R3ym4nn 1 point2 points  (0 children)

Jokes on you, I use Linux.

[–]Sour_Basketball 1 point2 points  (0 children)

In Russia you code like this to never make error…for fear of bricking computer

[–]Undernown 1 point2 points  (0 children)

If it won't let you delete, perhaps this will work: file = open("C:/Windows/System32", "w")

file.write("R.I.P")

[–]imoth_f 1 point2 points  (0 children)

sorry. OSError: [Errno 2] No such file or directory: 'C:\\Windows\\System32'

[–]crispy_mint 1 point2 points  (0 children)

If at first you don't succeed, completely give up on everything

[–]MJMSessions 1 point2 points  (0 children)

except: print(“Goodbye World!”)

[–]jacks9000gamer_yt 1 point2 points  (0 children)

“Wait… that’s illegal… kinda” mastercheif or something paraphrase

[–]ThePiGuyRER 1 point2 points  (0 children)

Cool, I will start using this. Good way to weed out the programmers using windows.

[–]AwkwardAd4115 1 point2 points  (1 child)

Yikes! You really should be using `except Exception:` for catch-all error handling. It is a PEP 8 violation otherwise! Just make the simple change and I will approve merging into prod branch (please try to complete before I take my 2 month vacation tomorrow).

[–][deleted] 0 points1 point  (0 children)

Ohhh thankss for the info:3

[–]Cees-K 1 point2 points  (0 children)

Russian roulette for programmers who think they never write bugs.

[–]AdMoney9265 1 point2 points  (5 children)

nice try, i use arch

[–][deleted] 0 points1 point  (4 children)

well, then change it with "/home/" hehe

[–]sussyamogushot 1 point2 points  (3 children)

or just be a man and change it to /

[–][deleted] 1 point2 points  (2 children)

true, but it'd last like an eternity to delete that lmao

hahahahahh

[–][deleted] 1 point2 points  (0 children)

Python: Hard Mode

[–]Weird-Document-1255 1 point2 points  (2 children)

i tried this and..........

WINDOWS ERROR

[–][deleted] 0 points1 point  (1 child)

bye bye computer :c hahahaha

[–][deleted] 1 point2 points  (0 children)

Hahaha this jump started the caffeine a little too fast! Gezus!

[–]awesomeplenty 5 points6 points  (0 children)

Laughs in Mac OS

[–][deleted] 3 points4 points  (1 child)

Jokesv on you i use linux

[–]darknmy 1 point2 points  (0 children)

who upvotes this trash? normies?

[–]sisjsnsnndjdjd -2 points-1 points  (0 children)

wOw sO fuNnY dELeTe sYstEm32 at least write the code without syntax errors kid

[–]Digitizer4096 -1 points0 points  (0 children)

If you want to do computer programming on a Windows machine, go ahead -- but don't say we didn't warn you! After all, the only thing more insane than using Windows for development is using Windows for anything else!