this post was submitted on 06 Jul 2024
1547 points (99.4% liked)

Programmer Humor

19817 readers
47 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
top 50 comments
sorted by: hot top controversial new old
[–] [email protected] 233 points 5 months ago (4 children)

Same with BIOS descriptions.

FGTSAB switch [toggles the FGTSAB setting]

infuriating

[–] [email protected] 41 points 5 months ago (4 children)

It's so bad it's almost artistic

load more comments (4 replies)
[–] [email protected] 41 points 5 months ago
[–] [email protected] 14 points 5 months ago (3 children)

Yup, my first thought as well. While those days are thankfully over, those braindead BIOS "help" messages remain etched into my mind forever.

load more comments (3 replies)
load more comments (1 replies)
[–] [email protected] 130 points 5 months ago (5 children)

Best comment ever was "It used to work like this but person at client demanded it work like that on this date" when the client complained it shouldn't work like that.

[–] [email protected] 137 points 5 months ago (2 children)

That's basically what comments are most useful for. When you're doing something that's not obvious, and want to make sure the "why" doesn't get lost to time.

[–] [email protected] 96 points 5 months ago (2 children)

// I'm not really that dumb, there is a reason.

[–] [email protected] 42 points 5 months ago

// narrator: the reason was management

[–] [email protected] 36 points 5 months ago* (last edited 5 months ago) (1 children)
// I told them I'd do this but only if they gave me time next sprint to fix it  - 12-03-1997
[–] [email protected] 16 points 5 months ago

[flashbacks to the backlog being wiped out because “the client already signed off on the release”]

[–] [email protected] 13 points 5 months ago (2 children)

I spent a year making my company's iOS apps accessible (meaning usable for the blind and people with vision disabilities). I had to do a lot of weird shit either because of bugs in Apple's VoiceOver technology or because of the strange way in which our code base was broken up into modules (some of which I did not have access to) and I would always put in comments explaining why I was doing what I was doing. The guy doing code review and merges would always just remove my comments (without any other changes) because he felt that not only were comments unnecessary but also they were a "code smell" indicating professional incompetence. I feel sorry for whoever had to deal with that stuff at a later point.

load more comments (2 replies)
[–] [email protected] 68 points 5 months ago

The best comments are "why" comments, the runner up is "how" comments if high-level enough, and maybe just don't write "what" comments at all because everyone reading your code knows how to read code.

[–] [email protected] 17 points 5 months ago

this seems like a great idea as it provides proof in writing just in case the stakeholder complains later on about the thing you implemented at their request

[–] [email protected] 13 points 5 months ago (1 children)

That’s actually the perfect comment, because if anyone ever comes back to fuck with you about it, it’s explained right there. Then you turn it right back around on management and watch them run around like chickens with their heads cut off.

load more comments (1 replies)
load more comments (1 replies)
[–] [email protected] 114 points 5 months ago (5 children)
/*
 * Gets stupidFuckingInteger
 *
 * @returns stupidFuckingInteger
*/
public double getStupidFuckingInteger() {
    return stupidFuckingInteger;
}

[–] [email protected] 38 points 5 months ago* (last edited 5 months ago) (1 children)

The lack of a return type declaration makes this sooo good.

[–] [email protected] 32 points 5 months ago* (last edited 5 months ago) (1 children)

It has the return type declared to be double.

[–] [email protected] 19 points 5 months ago

I cannot read. Even better.

[–] [email protected] 19 points 5 months ago

This being a double physically hurts

[–] [email protected] 16 points 5 months ago (1 children)

Makes sense, people looking for int would find a double

load more comments (1 replies)
load more comments (2 replies)
[–] [email protected] 78 points 5 months ago* (last edited 5 months ago) (1 children)

//@TODO document this function later

15 years later

load more comments (1 replies)
[–] [email protected] 74 points 5 months ago (6 children)

Comments should explain "why", the code already explains "what".

[–] [email protected] 63 points 5 months ago* (last edited 5 months ago) (3 children)

The allowable exception is when the what is a what the fuck, as in you had to use a hack so horrible that it requires an apology comment

[–] [email protected] 15 points 5 months ago

Absolutely, although I see that as part of why

Why is there a horrible hack here? Because stupid reason...

load more comments (2 replies)
[–] [email protected] 28 points 5 months ago (3 children)

Inline comments yes.

Function/Class/Module doc comments should absolutely explain "what".

load more comments (3 replies)
load more comments (4 replies)
[–] [email protected] 62 points 5 months ago (20 children)

I had a old job that told me that code is "self documenting" if you write it "good enough". And that comments were unnecessary.

It always annoyed the heck out of me. Comments are imo more helpful than hurtful typically.

Is it just me? Or am I weird? Lol.

[–] [email protected] 52 points 5 months ago* (last edited 5 months ago)

Document intentions and decisions, not code.

[–] [email protected] 39 points 5 months ago (1 children)

Code should always by itself document the "how" of the code, otherwise the code most likely isn't good enough. Something the code can never do is explain the "why" of the code, something that a lot of programmers skip. If you ever find yourself explaining the "how" in the comments, maybe run through the code once more and see if something can be simplified or variables can get more descriptive names.

For me, that's what was originally meant with self-documenting code. A shame lazy programmers hijacked the term in order to avoid writing any documentation.

[–] [email protected] 15 points 5 months ago (1 children)

lazy programmers

I don't think they're lazy, I think they're not good writers. Not being able to write well is very common among programmers (not having to communicate with written language is one reason a lot of people go into coding) and in my experience the Venn diagrams for "not a good writer" and "thinks comments are unnecessary" overlap perfectly.

load more comments (1 replies)
[–] [email protected] 29 points 5 months ago* (last edited 5 months ago) (2 children)

Comment should describe "why?", not "how?", or "what?", and only when the "why?" is not intuitive.

The problem with comments arise when you update the code but not the comments. This leads to incorrect comments, which might do more harm than no comments at all.

E.g. Good comment: "This workaround is due to a bug in xyz"

Bad comment: "Set variable x to value y"

Note: this only concerns code comments, docstrings are still a good idea, as long as they are maintained

load more comments (2 replies)
[–] [email protected] 13 points 5 months ago

Code is the what. Comments are the why.

Few things worse than an out of date comment.

[–] [email protected] 11 points 5 months ago* (last edited 5 months ago) (3 children)

In my opinion, it strongly depends on what you're coding.

Low-level code where you need to initialize array indices to represent certain flags? ~~Absolutely comment the living shit out of that.~~ → See response.
High-level code where you're just plumbing different libraries? Hell no, the code is just as easily readable as a comment.

I do also think that, no matter where you lie in this spectrum, there is always merit to improving code to reduce the need for documentation:

  • Rather than typing out the specification, write a unit/integration test.
  • Rather than describing that a function should only be called in a certain way, make it impossible to do it wrongly by modelling this in your type system.
  • Rather than adding a comment to describe what a block of code does, pull it out into a separate function.
  • Rather than explaining how a snippet of code works, try to simplify it, so this becomes obvious.

The thing with documentation is that it merely makes it easier to learn about complexity, whereas a code improvement may eliminate this complexity or the need to know about it, because the compiler/test will remember.

This does not mean you should avoid comments like they're actively bad. As many others said, particularly the "why" is not expressable in code. Sometimes, it is also genuinely not possible to clean up a snippet of code enough that it becomes digestable.
But it is still a good idea, when you feel the need to leave a comment that explains something else than the "why", to consider for a moment, if there's not some code improvement you should be doing instead.

load more comments (3 replies)
[–] [email protected] 11 points 5 months ago

Code is not self documenting when decision trees are created based on some methodology that's not extremely obvious

load more comments (14 replies)
[–] [email protected] 49 points 5 months ago (12 children)

I write such comments because I have to.

Company policy.

Also we have to specify every line of code and what it should do.......

[–] [email protected] 55 points 5 months ago

Lol leave. That is so many levels of braindead.

[–] [email protected] 26 points 5 months ago (1 children)

I would smash everything into a handful of overly-complicated lines.

[–] [email protected] 12 points 5 months ago (2 children)

I loved doing this is school, just trying to mess up my teachers.

load more comments (2 replies)
load more comments (10 replies)
[–] [email protected] 30 points 5 months ago* (last edited 5 months ago) (1 children)

/********** Setting up the fkuArray **********/

fkuArray = array(...

[–] [email protected] 17 points 5 months ago

Well, fku that array indeed.

[–] [email protected] 18 points 5 months ago (5 children)

Good code is self-explanatory. You should only comment your code if it does something unexpectedly complicated.

That being said, it's always a good idea to write a manual, about how to use the code. Don't document how it works, because those who can code will understand it anyways, and those who can't, have no need to understand it.

[–] [email protected] 34 points 5 months ago (2 children)

Good code is self-explanatory. You should only comment your code if it does something unexpectedly complicated.

The code shows what is being done. The comments should explain the why.

[–] [email protected] 14 points 5 months ago* (last edited 5 months ago) (1 children)

Yes. This 1000x. I hate it at work when I come across code that was written 3 years ago that has literally no traces of why it's there and a quick summary of what it does. Especially because that code is always the most abbreviated spaghetti you've ever seen. People should stop thinking (their) code documents itself because 99.999% of programmers cannot do it right.

I really like the Google way of coding: assume the person reading the code is the most 1337 programmer ever, BUT that this person knows absolutely nothing about the project

load more comments (1 replies)
load more comments (1 replies)
[–] [email protected] 13 points 5 months ago (11 children)

Hard disagree. It's a lot easier and faster to understand a function that is prefaced with a small line of text explaining what it does rather than trying to figure it out yourself.

It's not about whether you can understand the code or not, it's about efficiency and clarity.

load more comments (11 replies)
load more comments (3 replies)
[–] [email protected] 16 points 5 months ago (1 children)

I got a media failed to load error at first and thought that was the joke

load more comments (1 replies)
[–] [email protected] 16 points 5 months ago (2 children)
load more comments (2 replies)
[–] [email protected] 12 points 5 months ago* (last edited 5 months ago) (2 children)

The code is self explanatory

/s needed apparently

[–] [email protected] 15 points 5 months ago

The words of the machine are sacred, Only the impure need explanation

The Flesh is Weak

load more comments (1 replies)
load more comments
view more: next ›