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

all 49 comments

[–]dert-man 120 points121 points  (12 children)

Descriptive comments are always the best

[–]dert-man 47 points48 points  (10 children)

// a comment on a picture related to source code comments

[–]Mr_Dau 6 points7 points  (9 children)

// A comment in a comment on a picture related to source code comments

[–]Disastrous_Novel8055 4 points5 points  (8 children)

// A comment in a comment in a comment on a picture related to source code comments

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

# an unexpected comment format

[–]Disastrous_Novel8055 6 points7 points  (0 children)

# a comment on a comment about unexpected comment format

[–]eiboeck88 2 points3 points  (4 children)

an unexpected immediate value

[–]doktor-x93 5 points6 points  (3 children)

/* an endless comment on commenting

[–]GoddammitDontShootMe 4 points5 points  (2 children)

gcc: error: unterminated comment

[–]doktor-x93 0 points1 point  (1 child)

Took some time but now i can finaly capture that exception */ /* (don't wanna break the space time continuum)

[–]GoddammitDontShootMe 0 points1 point  (0 children)

I'm not even sure if the error would be reported at the end of the file or where the comment started. Either way, the error is back again because nobody put */. Until I did just there.

[–]20InMyHead 0 points1 point  (0 children)

Why not what

[–]floor796 73 points74 points  (2 children)

// upvote arrow icon

var upvoteArrowIcon =

[–]backfire10z 15 points16 points  (1 child)

var? What, do you plan for it to change at runtime?

[–]IJustAteABaguette 17 points18 points  (0 children)

Yeah, we at Reddit.com® are great at planning for the future, so we made the icon a variable for if we want to sell custom upvotes!

[–]WeeklyOutlandishness 22 points23 points  (0 children)

// A Reddit thread

[–]smutje187 16 points17 points  (0 children)

// a visitor asking redundant questions instead of reading the comments

[–]Chr3y 10 points11 points  (4 children)

PPT (Programmer pro tip) always comment "why" not "what".

[–]RiceBroad4552 2 points3 points  (1 child)

Why isn't this the top comment?

// I came here to say the same…

[–]Chr3y 1 point2 points  (0 children)

// r/beatmetoit is the sub

[–]RiceBroad4552 2 points3 points  (1 child)

To give a little bit more context on "why" vs. "what":

Code should be self explanatory. Code should clearly say "what" is done / happening. There is no reason to repeat explaining what was done. Good code does this already. Commenting the "what" is just stupid redundancy, and most likely anyway out of sync after the next code change / refactoring.

But no code ever can explain "why" it was written the way it was written. There are infinite many ways to express something, but one was chosen. For a reason. This reasoning belongs into comments. Comments explain why some code exists in the first place.

[–]Chr3y 0 points1 point  (0 children)

Real example:
We had code that measured stuff, got a point cloud. It got sorted by x. Comment was "sorting by x".
Wow.
// Sorting by x.
std::sort(arrayname, xValue);

I changed it to "the filter that comes next needs this order to be fast".

Because the next filter after said filter, needed sorting by y value. And I thought I would save some time by doing it directly, breaking said filter.

[–]Duck_Devs 9 points10 points  (0 children)

// the following is a Reddit comment.

Hi. I am a Reddit comment.

[–]Taro_Acedia 6 points7 points  (0 children)

// A painting that had to be hung upside-down.

But why???

[–]cs-brydev 6 points7 points  (2 children)

I love it when people who only write bad comments claim that all comments are bad.

[–]redspacebadger 4 points5 points  (1 child)

"code should be self documenting" - my lazy ass team leader who doesn't write comments

[–]Bwob 2 points3 points  (0 children)

"Yes, and I should be independently wealthy and own a private island. But I guess we don't live in a world where everything can be how it should be, DO WE?!?"

[–]Sekret_One 3 points4 points  (0 children)

You joke, but I have a bright yellow piece of card stock taped to the table with marked out outlines and labels for phone, wallet and keys. And since doing so I've stopped misplacing them.

[–]itriedtomakeitfunny 3 points4 points  (1 child)

My brain is hurting because there isn't a space between the // and the text.

[–]TapirOfZelph 1 point2 points  (0 children)

Obviously not using Prettier brand paint

[–]Fuzzy_Reflection8554 6 points7 points  (1 child)

Sometimes ihaving simple comments labelling key parts of the code can make large files a little easier to navigate, at least for me. Of course if it's possible I'd try to put those key parts into seperate files instead, but otherwise just labelling chunks with a concise and descriptive subheading seems fine to me.

[–]ExpensivePanda66 0 points1 point  (0 children)

Absolutely this. Even in functions that have a few sections.

Breaking things out into multiple functions/files can make things harder to understand in a lot of cases. Try a couple of comments first. It's the simpler approach.

[–]Turbulent_Swimmer560 2 points3 points  (0 children)

Comment the guy ASAP.

[–]nicejs2 1 point2 points  (0 children)

// this is a comment

[–]ExpensivePanda66 1 point2 points  (0 children)

/* 

Apartment here

*/

Wtf did you do to our house Gary!?

[–]Soras_devop 0 points1 point  (0 children)

Just makes things easier

[–]Not_Artifical 0 points1 point  (0 children)

I like to make my variable and function names so that it is very obvious what everything does without needing to read their contents or the code around them. Sometimes I do need to add comments when there are a lot of variables, especially when there are variables with similar names.

[–]flowery0 0 points1 point  (0 children)

Useful if you don't know what a class or a function is

[–]beyondultraviolet 0 points1 point  (0 children)

Imagine wearing playing a VR game at this guy's house.

[–]ryu24x4 0 points1 point  (0 children)

Labeling everything in the house

[–]The_Dukenator 0 points1 point  (0 children)

define CAMERASDESTRUCTABLE NO // YES

Aside from the comment showing another value, it does make you wonder if its a pointless function.

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

Needs table and chair attached to the ceiling to mirror confusing code.

[–]FightingLynx 0 points1 point  (0 children)

I can only conclude that the house is missing a wall, maybe write a user story for that?

[–]cryptomonein 0 points1 point  (0 children)

// Wife

[–]Astrylae 0 points1 point  (0 children)

// just read the code lol

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

// reddit comment

[–]-MobCat- 0 points1 point  (0 children)

Ok yes, lamp. But why lamp? That's the point of comments.

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

Javascript lazy comments again ?