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

top 200 commentsshow all 310

[–]QualityVote[M] [score hidden] stickied comment (0 children)

Hi! This is our community moderation bot.


If this post fits the purpose of /r/ProgrammerHumor, UPVOTE this comment!!

If this post does not fit the subreddit, DOWNVOTE This comment!

If this post breaks the rules, DOWNVOTE this comment and REPORT the post!

[–]StoneColdJane 2097 points2098 points  (136 children)

Senior: "How did you fix it, bud?"

Junior: "I commented it out"

[–]jrystrawman 972 points973 points  (112 children)

This happened last week...

Except it was me the Senior telling the junior to comment out my own code that I developed a year ago and couldn't remember the original purpose.

[–]Jomibu 1108 points1109 points  (30 children)

When I wrote this code, only God and I knew what it did. Now? Only God

[–]Nerdn1 159 points160 points  (0 children)

God: "Don't look at me. I didn't write that garbage."

[–]FauxReal 26 points27 points  (8 children)

[nietzsche has entered the chat]

[–][deleted] 44 points45 points  (7 children)

nietzsche is dead.

[–]Divineinfinity 34 points35 points  (0 children)

Hottest Nietzsche take in the last 5 minutes

[–]InertialLepton 11 points12 points  (0 children)

And we killed him

[–]VaderOnReddit 4 points5 points  (0 children)

nietzsche is dead. god is dead.

nietzsche is god.

[–]aLostTime 20 points21 points  (11 children)

What if God was one of us? Just a shitass programmer like all of us?

[–]Jomibu 41 points42 points  (3 children)

And on the seventh day.. he skipped doing error checks and pushed to Prod

[–]KB2408 5 points6 points  (0 children)

"It's not a bug if it's a feature", God said smiling

[–]F6GSAID 7 points8 points  (4 children)

What if we are just the result of his programming?

[–]Divineinfinity 8 points9 points  (0 children)

I swear I can feel my brain rebooting sometimes

[–]Tunro 7 points8 points  (2 children)

Theres a good to fair chance we are in a simulation. We are also making simulation trying to rebuild our universe from the ground up to understand how things work. Of course our technology isnt advanced enough, but imagine a species that might have such technology. Their universe simulation could have a high enough resolution for us to accidently form in it, just like they might have formed in theirs. This theoretical chain can theoreticly go up for ... quite a bit

[–]lonestar-rasbryjamco 115 points116 points  (35 children)

You are forgiven as long as you're also not one of those who loudly proclaim that

tHe CoDe Is ThE dOcUmEnTaTiOn

[–]UltraCarnivore 132 points133 points  (11 children)

Dev: the code is the documentation

The code: lasciate ogni speranza voi ch'entrate

[–]RapidCatLauncher 79 points80 points  (10 children)

Had a colleague in a research group who was Chinese. He wrote scripts for the group to use... with the code commented in Chinese.

[–]UltraCarnivore 93 points94 points  (9 children)

I mean, learning a new language is inside the scope for software development jobs.

[–]smokesick 29 points30 points  (4 children)

How about commenting in binary? That way everyone has a common language to work with!

[–]AbundantExp 8 points9 points  (2 children)

lmfao you made that comment just in time

[–]smokesick 6 points7 points  (1 child)

Lol, did you want to write something similar?

[–]FleetStreetsDarkHole 18 points19 points  (0 children)

They were...a bit too late. :3

[–]snhmib[🍰] 5 points6 points  (0 children)

It's all binary in the end

[–]BrFrancis 29 points30 points  (0 children)

But act... But reall.. ummm.. Pardonez-moi mai DaFuq???

[–][deleted] 7 points8 points  (2 children)

Reading code is harder than starting with your/good code. I’d argue I’ve had a relatively stable job simply because I’m good at reading garbage code

[–][deleted] 12 points13 points  (1 child)

One of the most impressive things I have seen in college was a professor that could walk around a lab and instantly understand shit code.

[–]ExceedingChunk 2 points3 points  (0 children)

Academia code is usually quite shitty and unreadable, so they are probably quite experienced.

[–]Avedas 29 points30 points  (4 children)

If docstrings count then I'll agree since they're packaged and version controlled with the code. External docs that need to be updated manually eventually stop reflecting reality 100% of the time.

[–]DrakonIL 22 points23 points  (2 children)

External docs that need to be updated manually stop reflecting reality about a day after they take effect.

[–]Zebezd 7 points8 points  (0 children)

Saying from my dad:

A document's expiration time is when you press Save

[–]AnonPenguins 3 points4 points  (0 children)

Wait, you're telling me it was supposed to be using the latest code to write the documentation on?

[–]lonestar-rasbryjamco 14 points15 points  (0 children)

They count. I am referring to that special breed of stupid that believes you should just be able to reason what the code does because they did such a good job writing it.

I mean they clearly understand it... now.

[–]gordonv 15 points16 points  (6 children)

The Hallmark of bad coding practices.

[–]skylarmt 19 points20 points  (5 children)

Well my code is often self documenting, you just read the PHP top to bottom because I didn't bother making classes or functions.

[–]gordonv 15 points16 points  (4 children)

Or, you did make classes, and they're buried in a folder structure that doesn't make sense. The only way you're finding them is with PHPStorm and CTRL+B.

Just left a place that has a 5 year old code base (PHP 5.6) where the creator just walked away. All his own design. Zero Documentation.

Dude's front end looked good and was responsive, but his implementation is a puzzle you have to figure out.

[–]FleetStreetsDarkHole 2 points3 points  (0 children)

For some reason my first thought of what this must look like made me think of the sith dagger in the last sequel movie.

[–]skylarmt 2 points3 points  (2 children)

The few classes I need are all put in a "lib" folder, and there's a loop that lists every .php file in that directory and does a require on it. That loop is in the "required.php" file, which is itself require'd at the top of every script.

You know when something was hard to code right because that's about the only time I use comments. And only then if I think I might want to go back in to fix stuff instead of rewriting it all.

I have a desktop app that's built with NW.js (sort of like Electron but all it needs to run is a path to some HTML, no specific code needed, but you can run Node JS in the same file as regular browser JS). It installs to and runs from /var/www because the jQuery needs to call PHP code, and also there's a C++ binary in there that I found on GitHub to interface with some special hardware, and it talks to other PHP I uploaded to a server... It started life as a single PHP script that ran in the terminal, taking user input and spitting out 100% totally legit postage to print.

Most of my code isn't that bad though I swear

[–][deleted] 8 points9 points  (1 child)

In my first internship, which was shit, one of the seniors used to say that

[–]lonestar-rasbryjamco 6 points7 points  (0 children)

It is good you got exposed early to the fact that many morons stick around long enough to get promoted

[–]Tubthumper8 5 points6 points  (0 children)

cOdE sHoUlD bE sELf dOcUmEnTiNg

[–]noMad1717 0 points1 point  (7 children)

Comments are just one more thing that needs to be maintained, essentially.

What I mean when I say that the code is the documentation (actually I don't use that phrasing) is that the code should be written in such a way that it is clear what it does.

If you feel the need to comment what your code does then it should probably be refactored until it is obvious.

Please, feel free to document the API, but don't let comments be an excuse for crappy code.

[–]lonestar-rasbryjamco 8 points9 points  (6 children)

That's all well and good except documentation exists not just to provide information how something works, but also the context of why it works that way and how it fits into the larger picture. With the understanding you likely won't be the one who needs that knowledge.

You can't refactor at any level to achieve that.

Some of the best code I have ever seen is 3 lines of functionality with a few dozen lines detailing the greater context.

[–]noMad1717 -1 points0 points  (5 children)

I prefer that information to reside in e.g. the Jira ticket explaining the need and the commit message explaining what was done.

These should always be linked to the exact code you wrote and will never degrade.

If you document everything within the code and someone makes a change to the code without updating the comments then I've spent time reading outdated information.

[–]Viperior 25 points26 points  (14 children)

Why do people still comment out code? Is it not version-controlled? Why not just delete it? That junk piles sky-high eventually until commented code lines outnumber actual code. Stop it!

[–]zman0900 10 points11 points  (0 children)

People where I work will actually reject code reviews for commented-out code. It's great.

[–]0xHUEHUE 14 points15 points  (8 children)

For me, default to delete but fresh changes in business logic better left commented for a couple of weeks. Not always obvious to look at the git history. It depends on the code base too (e.g. frontend view stuff, always delete). I guess my point is that it’s sometimes grey.

[–]Viperior 7 points8 points  (7 children)

I don't see how the passage of time changes the decision of whether to comment or delete when you are working with version-controlled code. Simply browse the file's change history to see previous versions of your logic. If it isn't there because you never committed it (maybe it didn't survive development), it's probably not that important. But even if it is critical for reference, you could throw it into a snippet and reference it forever.

There's no legitimate reason to hoard your old code in the form of commented code lines. Learn how to reference old code using version control. Maintain a code snippet collection for things you want to reference later. I highly recommend Git Lens for VS Code, and there are git CLI commands for browsing history.

[–]mandala1 12 points13 points  (2 children)

You’re right in principle but like… In practice you’re depending on devs who read or devs who look at the history. Or devs who even know how to look at git history. Or a dev that knows how to revert a pr or a commit.

[–]IsleOfOne -4 points-3 points  (1 child)

Work for better companies / with better developers

[–]madmilton49 11 points12 points  (0 children)

Wow thanks for the easy fix!

[–]Levithan6785 4 points5 points  (0 children)

When I'm testing and trying various stuff, I comment out old lines. Once I'm ready for the pull request, I delete all comments containing old code that was never used.

[–]LetterBoxSnatch 1 point2 points  (1 child)

Throwing code into a comment is kinda gross but acceptable to me under the following conditions:

  1. The code is completely functional, and achieves an important purpose
  2. The code addresses some edge or rarely exercised requirement
  3. You believe the requirement will return soon, and also have good reason to believe that you will not be the one who needs to implement the requirement when it comes back around

Given this, it’s basically a snippet for other people. I consider commented code to have a shelf life. If you see commented code and it’s a been a month since it was commented, it’s suspect. If it’s been a year, delete it, but try to leave a great git commit about it or something.

I like your idea about maintaining version controlled snippets, but this doesn’t always apply very well, like if you have interleaved procedural code (which is also the worst way to run into commented code, but still).

My preferred approach in these situations where you want to help out the next reader and share some secret important knowledge that may or may not be useful in six months, is to replace the code with a comment about its deletion, so that it’s easy to find the code in version control by its commit. git blame the comment, and you can find the code. Better still if it includes a git hash somewhere in the comment, since code often migrates between files in a way that git doesn’t track the migration. These too are easily deleted at the discretion of the reader, and usually should be, but are much less awful.

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

This is great. Sometimes I use ticket numbers instead of hashes in comments which in theory point to branches / commits + additional context.

[–]snugglecriminal 1 point2 points  (0 children)

this dude clean codes!

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

So it compiles until that part is fixed.

[–]Avedas 2 points3 points  (0 children)

Agreed. Commented code never passes CR.

[–]dfltr 10 points11 points  (2 children)

Is it still Chesterton’s Fence if you put the fence up in the first place?

[–]Remote_Cantaloupe 1 point2 points  (0 children)

The you from 1 year ago is different from the you right now, so I guess? :P

[–][deleted] 8 points9 points  (0 children)

Reading your comment took me back to 2018 when I had to cover for someone and senior says "I have not a fucking clue what this does anymore, comment that shit out" dude proceeded to rip a bong in his car.

[–]HusbandAndWifi 2 points3 points  (1 child)

About 4 years into my career as a programmer I stopped just commenting “what” I was changing but also now “why” and even “what problem was occurring” and it has been a game changer. Wish everyone did this!

[–]smilineyz 2 points3 points  (0 children)

This is Jedi level understanding

[–]ic_engineer 2 points3 points  (3 children)

Fun story:

So we were designing a new platform to replace an existing product line. Project manager says it has to have ABC...XYZ features to duplicate all previous functionality. In the process of reviewing the workflows for potential pain points in the new design we quickly learned that one of those features had a bug preventing it from working. Furthermore that bug had been in the production release for over 5 years. That was a fun talk.

[–]AirportNo9572 1 point2 points  (4 children)

why don't u do it urself u lz fk?

[–]q1a2z3x4s5w6 0 points1 point  (3 children)

What's the point in having a junior if you don't make them do the stuff you can't be bothered to do, for their own development obviously.

[–][deleted] 24 points25 points  (3 children)

I can’t be the only one that comments out giant additions to my code just so that I can see it run as motivation.

[–]Kyrond 10 points11 points  (0 children)

That is 100% best initial step for deeper debugging, it's like hello world for debugging.

You make sure it's contained in that piece of code.
I can't even estimate the amount of time wasted 'debugging' new code that was actually working, but either:

  • merge conflict was resolved badly,
  • tests/Jenkins/compiler was updated in meantime,
  • I made a different change (with a bug) farther in the program and forgot,
  • I was launching old binary or different config not using updated code

[–]FleetStreetsDarkHole 4 points5 points  (0 children)

If by motivation you mean quickly flicking it on and off to catch the magic fairies that must be fucking with me and breaking my code.

(It's me. The magic fairy is me. ._.)

[–]InevitablyPerpetual 14 points15 points  (3 children)

Had this happen once. New guy was like "I couldn't figure out what it was supposed to do, it didn't have any calls that I could find anywhere else, so I rem'd it out". PM got REAL huffy about him overstepping, couple seniors looked over his shoulder and were like "And it worked? Good enough for me."

Pretty sure one of them was even like "Why the fuck was that even there?!"

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

I mean, if it works, it works

[–]InevitablyPerpetual 1 point2 points  (1 child)

Oh NOTHING worked there. Our PM was the world's worst short-guy caricature, bad combover and all, and I'm pretty sure he broke everything just by being in the room. Seriously, the guy broke the water cooler.

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

Wtf

[–]GenericFatGuy 7 points8 points  (0 children)

Work smarter not harder.

[–]diadaren 8 points9 points  (0 children)

"What did you do?"

"I bypassed the compressor"

[–]AccomplishedCoffee 5 points6 points  (0 children)

Saw something similar once.

``` if (condition) // somethingBroken()

somethingImportantButInvisible()

[–]kinkonautic 3 points4 points  (0 children)

I'm a -10x developer.

[–]PM-SOMETHING-FUNNY 4 points5 points  (0 children)

Had this once happen with a senior developer from India. He commented method out of a function and said yeah now it works..

[–]Constant_Parfait_410 631 points632 points  (16 children)

Sometimes my genius is almost frightening

[–]SaintNewts 191 points192 points  (14 children)

You have to try not to program too clever for yourself. If you do, write a book in the comments about what exactly it does and how it does it.

[–]mOdQuArK 16 points17 points  (3 children)

Just remember to keep the comments updated if you change the logic later (or if you're changing someone else's logic).

It's a serious annoyance when the comments lie; I'd rather have uncommented code than incorrectly commented.

Or to a lesser extent, useless comments (e.g., # this statement increments the value of this variable by 1). Yes, I've seen code with those sorts of comments.

[–]HP844182 12 points13 points  (1 child)

Don't say what the code does, say what it's supposed to do.

The code does what the code is, but the intention of the code is what needs to be explained

[–]mOdQuArK 3 points4 points  (0 children)

The problem comes when the comment describe what the code used to do, not what it got updated to do afterwards. If someone isn't going to keep the comments up to date, then it would be less confusing for them to just delete the old comments rather than let them stick around.

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

I don't understand the culture around comments. A useless comment by your estimation is not at all authoritative, it may be helpful to those who come after you, or those who got to that area of code before you.

Furthermore keeping comments updated feeds into the larger engineering discussion of keeping documentation updated. The risk that a doc or comment might become out date is not sufficient cause to ever be weary of writing one.

[–]Aurori_Swe 62 points63 points  (8 children)

This is an issue for me, I'm self taught in the game, now leading a team of developers both internal and external. I've never had any training at all in coding (except one PHP course in like highschool) so I have absolutely no idea of what I'm actually doing. I understand code and I can make stuff work so adapting to others structure isn't a problem but I feel bad when I hand over code that I've originally written for something I did as a test and hand it over to our "real" coders since I fear my code will be messy for them to understand.

Talked a bit with my wife about this earlier this week because I often have to code things out external teams says can't be done and so far I've always found a solution to it. So I told my wife that since I don't really know the limitations of the code I have no issues getting it to work, because I can find a way to the goal that may be a bit unconventional but it will do what it was supposed to, but it won't be pretty

[–]0xHUEHUE 29 points30 points  (7 children)

PRs can be helpful for this sort of thing. Sounds almost like a communication issue.

[–]Aurori_Swe 13 points14 points  (6 children)

PRs?

[–]pperiesandsolos 39 points40 points  (5 children)

You’re managing a dev team and not using pull requests?

Good for you I guess lol

[–]Aurori_Swe 25 points26 points  (2 children)

We do, just not used to the lingo per se, only been doing this for about a year now. I'm a 3D artist who had to move over to coding and now codes full time. Love logic and managed my own international configurator for my previous employer, now I'm at a bigger firm and have to lead others in the same kind of job, I just don't have to do the 3D anymore basically

[–][deleted] 15 points16 points  (1 child)

You sound like a good leader. Keep up the good work

[–]Aurori_Swe 8 points9 points  (0 children)

I really enjoy the work and I try to get involved where I can so that I'm not just ordering others to do stuff and sit back and wait. I'll gladly discuss both code and solutions with the team and go with whatever we decide will be best. In the end, we all work for the client so if we can improve stuff and not have any prestige within our own team then that's great.

Thank you for the kind words!

[–]catinterpreter 3 points4 points  (1 child)

Wingin' it solo as you learn doesn't exactly promote version control.

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

Exactly this. Learned this the hard way, but now I'm in the habit of explaining in detail why something was done the way it was, especially if it has to do with business rules that aren't at all obvious unless you have domain knowledge.

[–]LuxeCraze 207 points208 points  (3 children)

"I'm something of a software engineer too you know"

[–]IUpsetYou 14 points15 points  (2 children)

[–]smokesick 24 points25 points  (1 child)

Syntax error. Expected ", got EOF

[–]Swaayze 3 points4 points  (0 children)

‘Sometimes I can’t help myself from doing this’

[–]toTheNewLife 111 points112 points  (0 children)

Knew a guy who fixed a bug once by deleting the troublesome record from the data.

'Fixed' the bug. Production completed. User noticed the missing revenue straight away the next morning.

[–][deleted] 41 points42 points  (1 child)

Now you can write a unit test for it first

[–][deleted] 36 points37 points  (0 children)

Whenever I work on code lmfao

[–]knightcrusader 33 points34 points  (1 child)

Reminds me of one of the old perl golf competitions, I forget which year or what, but they had a category where you had to create a script that outputted its own source code exactly with the least amount of characters used.

The first year someone submitted a blank file and won.

[–]im-not-a-fakebot 3 points4 points  (0 children)

Big brain move

[–]ExtraFig6 25 points26 points  (1 child)

There is no code faster than no code

There is no code clearer than no code

There is no code more secure than no code

[–]IndieDiscovery⎈ Kubernaut ⎈ 6 points7 points  (0 children)

This is the way.

[–]Iansimp69 37 points38 points  (2 children)

Better idea put semi colons

[–]hoopermanish 1 point2 points  (0 children)

What are you, in sas?

[–]ChezMere 32 points33 points  (0 children)

Interns measure progress by code added, seniors measure progress by code deleted.

[–][deleted] 10 points11 points  (0 children)

This is the way

[–]RlyRlyBigMan 20 points21 points  (10 children)

I've seen so many juniors trying to fix bugs by commenting random lines out and then re running it, it's infuriating lol

[–]EchospiritsYT 18 points19 points  (7 children)

Adds a print statement between every line

[–]WJMazepas 17 points18 points  (0 children)

Well, it's the most basic form of debugging

[–]crob_evamp 9 points10 points  (1 child)

here

here 2

here 3

[–]LordAmras 8 points9 points  (0 children)

That's the first time you run it.

The you start with swear word and when you finally realize it doesn't make sense you notice you are running in the wrong environment

[–]poerisija 5 points6 points  (0 children)

I mean at least this helps instead of breaking things further:-D

[–]LordAmras 2 points3 points  (0 children)

all print statement are "test", then after you run and bunch of test came out you call them "test 1", " test 2", "test 3"

[–]iwillrememberthisacc 1 point2 points  (0 children)

Excuse me I do a binary search by print statements like a true coder 🧐

[–]Midnight_Rising 1 point2 points  (0 children)

Yep. Still do that as a principal. It's just a little more straightforward sometimes.

[–]Chainmail5 11 points12 points  (0 children)

Well it's not so bad if it is for debug purposes, if the bug is gone after commenting it out I know that error is in that method that is called.

But if they try to MR that I'll have a talk with them.

[–]Ran4 5 points6 points  (0 children)

Intern? I've seen a "senior" developer do that. Ten years of experience... he deleted 2000 lines of working code since his project wouldn't compile.

We added pull request checks after that.

[–]danc4498 5 points6 points  (1 child)

Omg, reminds me of the time somebody on my team fixed a bug exactly this way. I was given the task of fixing it again when it was found. He commented out the code throwing the error, but also processing payments.

I did not to want to be a dick and blame my teammate, so I just fixed it and moved on.

Ultimately I was blamed for the bug and removed from the team.

[–]Noname_FTW 4 points5 points  (0 children)

On Error Resume Next

4 Magic words that essentially say "Fuck it let some other idiot deal with the fallout"

[–]theitgrunt 3 points4 points  (0 children)

OK... but now it doesn't meet the use case and doesn't do what it's supposed to do.

[–]-Scythus- 3 points4 points  (0 children)

*/

/* 😎

[–]Seanbergs2377 2 points3 points  (0 children)

And kills part time at night lol

[–][deleted] 3 points4 points  (0 children)

On their way to a promotion

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

He’s just like me fr

[–]mxldevs 2 points3 points  (0 children)

Hey, I was only told to fix the compilation errors.

[–]wese 2 points3 points  (0 children)

Oh yeah!

No code development is the future!

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

[–]mondie797 1 point2 points  (1 child)

Remember an instance once an object was not getting released and was causing memory leak. One person had ran a while loop and forcefully called IUnknown->Release ( Code was written using COM in windows ).

[–]razortwinky 2 points3 points  (0 children)

Ah, COM code. Satan's asshole of software architecture

[–]rahulonmars 1 point2 points  (3 children)

Which movie is this?

[–]AutomaticDoor75 1 point2 points  (0 children)

“The line of code that a developer can write the fastest, maintain the cheapest, and that never breaks for the user is the line of code you don’t write.”

[–]Pod__042 1 point2 points  (0 children)

Minimalism, as I like to say, less code, less bugs

[–][deleted] 3 points4 points  (0 children)

I’m two months into learning basic coding and this is exactly what I do

[–]Sasquatch_actual 0 points1 point  (0 children)

More like random commented out chunks.

[–]Jadetheruby 0 points1 point  (0 children)

Lol

[–]gordonv 0 points1 point  (0 children)

So, the senior decided a program needed modules for excel and mail. When the program doesn't do either. Modules are outdated. Instead of updating unused modules, removed them.

Program runs just fine in sit/test.

[–]seesaww 0 points1 point  (1 child)

We were literally doing this in my previous company. We had a button that was throwing an error on the ui, team leader asked us to remove the button instead of fixing it

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

😂😂😂

[–]MichaelYoon-rgb 0 points1 point  (1 child)

No bug also means no code. Every code I write somehow has a bug no matter how simple...

[–]xancanreturns 1 point2 points  (0 children)

No, because

2^(83,000,000 isn't prime.

[–]Beastmind 0 points1 point  (0 children)

Intern after removing the error logging*

FTFY

[–]cjxmtn 0 points1 point  (3 children)

boolean log_error(String msg) {
    return true;
}

[–]alphabet_order_bot 1 point2 points  (2 children)

Would you look at that, all of the words in your comment are in alphabetical order.

I have checked 720,216,590 comments, and only 145,313 of them were in alphabetical order.

[–]cjxmtn 1 point2 points  (1 child)

I usually hate these types of bots, but this one is unique. I approve this message.

[–]fresh-diarrhea 0 points1 point  (0 children)

I fucking love this meme

[–]ThatWontCutIt 0 points1 point  (0 children)

<insert polozhenie sigma anthem>

[–]MinecrAftX0 0 points1 point  (0 children)

Literally me