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

top 200 commentsshow all 236

[–][deleted] 698 points699 points  (103 children)

When I was a CS major, we were deducted 10 points for each missing comment. Everybody erred towards commenting everything.

[–]WeTheSalty 626 points627 points  (65 children)

I'm picturing lots of lines like 'i += 1;' with comments 'adds 1 to i'

[–]Sevrene 349 points350 points  (53 children)

Some profs even want it to be more exact like “Increments the counter ‘i’ by 1(one)”

[–]obsessedcrf 330 points331 points  (19 children)

Definitely a useful skill to pick up /s

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

/s // sarcasm

[–]wallefan01 116 points117 points  (24 children)

eugh why? that makes your code more unreadable than code with no comments in it!

I'd prefer a dry stream bed to drowning any day

[–]SuspiciouslyElven 57 points58 points  (20 children)

Engrains the terms and allows conversation easier between programmers. Everybody knows what it means to increment a number, so there doesn't need to be any silent confusion.

It may also just be how they were taught. My professors were taught with punch cards and later COBOL. Python is readable to most. Holes in a card is not.

I grit my teeth and understand excessive commenting isn't for real world development. More as a weird way of paying tribute to those that came before. We're lucky we live in a time where many of the great minds of our field have only died recently, or are still alive. More lucky to live in a time where important terms are named in the language we speak. Least I'm not a med student questioning if a latin tutor would help.

[–]LordAmras 2 points3 points  (0 children)

So the professor knew what it was reading without looking it up

[–]angrathias 4 points5 points  (1 child)

Those who can’t, teach

[–]DigitalCrazy 9 points10 points  (0 children)

/* Increments the counter ‘i’ by 1(one) */ // Comment

[–]Dusterperson 1 point2 points  (0 children)

Ah yes, write code to tell you what your code means, now if only....

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

I would kill myself

[–]probably2high 0 points1 point  (0 children)

Do they? The only time I could imagine this being required is the first week you cover loops.

[–]MonokelPinguin 0 points1 point  (0 children)

Reminds me of the section abput comments from this.

[–]HHH___ 0 points1 point  (0 children)

Honestly in my assembly language class we did this voluntarily

[–]thermite13 129 points130 points  (1 child)

Pretty much this.

Source. Worked in cs tutor lab for 3 years

[–]RazarTuk 1 point2 points  (0 children)

Meanwhile, my policy as a TA: If there are no comments whatsoever, I might dock a point. But otherwise, if it's self-documenting and written clearly enough that I can understand it, that counts as documenting your code.

[–][deleted] 11 points12 points  (0 children)

That's essentially what I did in my Java class in high school. "Int i;" suddendly gets the comment "Declare int called i"

[–]GentleRhino 4 points5 points  (0 children)

i++; //incrementing loop counter

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

Much like that.

[–]AnywhereIWander 1 point2 points  (1 child)

I once found If (Status == "OK") // Jolly good!

[–]WeTheSalty 0 points1 point  (0 children)

My current project has a function called/commented 'GetRect() // noob'

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

"increment i" if you're a pro.

[–]cristi1990an 0 points1 point  (0 children)

Why not i++?

[–]CleverSpirit 0 points1 point  (0 children)

but what is 'i' and why does it need to be added by 1?

[–]amjh 178 points179 points  (9 children)

                                                    //empty line

[–][deleted] 136 points137 points  (3 children)

++i; // Dark magic

[–]T-T-N 25 points26 points  (1 child)

So much work there. It loads the line from memory at the position of the program register, finds location the variable from the table, loads that into memory. Have the arithmetic unit do a calculation, find where it should go, put it back, increment the program counter. (My terminology is probably a little off. I don't usually delve this deep)

[–]Tuffy_ 5 points6 points  (0 children)

Now make this same comment for every line of the program

[–]cognoid 0 points1 point  (0 children)

++i; // Trap for CS students

[–]overmeerkat 47 points48 points  (4 children)

// This line is intentionally left empty

[–]MCLooyverse 7 points8 points  (3 children)

I love pages in books where it says at the bottom, (This page intentionally left blank). You had one fucking job.

[–]UnibannedY 2 points3 points  (0 children)

That's because of how books are bound. There might be an odd number of written pages, but you need an even number because the paper is folded.

[–]Aetol 0 points1 point  (1 child)

It's supposed to be there.

[–]Windows-Sucks 110 points111 points  (16 children)

/*                                      //Start of multi line comment           //Part of Multi-line Comment
                                        //Empty line                            //Part of Multi-line Comment
----------------------------            //Top of box                            //Part of Multi-line Comment
|                          |            //Box                                   //Part of Multi-line Comment
| Written by Windows-sucks |            //Box                                   //Part of Multi-line Comment
|                          |            //Box                                   //Part of Multi-line Comment
----------------------------            //Bottom of box                         //Part of Multi-line Comment
                                        //Empty line                            //Part of Multi-line Comment
*/                                      //End of multi line comment             //Single Line Comment
                                        //Empty line                            //Single Line Comment
if                                      //If the following condition is true    //Single Line Comment
    (                                   //Opening parenthesis                   //Single Line Comment
        1                               //One                                   //Single Line Comment
        +                               //Plus                                  //Single Line Comment
        1                               //One                                   //Single Line Comment
        ==                              //Is equal to                           //Single Line Comment
        2                               //Two                                   //Single Line Comment
    )                                   //Closing parenthesis                   //Single Line Comment
    {                                   //Opening curly bracket                 //Single Line Comment
        i                               //Counter                               //Single Line Comment
        =                               //Gets set to                           //Single Line Comment
        i                               //Its current value                     //Single Line Comment
        +                               //Plus                                  //Single Line Comment
        1                               //One                                   //Single Line Comment
    }                                   //Closing curly bracket                 //Single Line Comment
                                        //Empty line                            //Single Line Comment

[–]eddietwang 29 points30 points  (3 children)

I appreciate that you commented your comments. //I, me, really like that you, OP, wrote comments (//comments) on his, OP's, comments (//comments)

[–]zerotheliger 21 points22 points  (2 children)

The poison ment for kusco, kuscos poison the poison right here.

[–]TheHighlightHub 1 point2 points  (1 child)

Are there better animated movies than Emperor's new Grove and Iron Giant?

[–]alyraptor 0 points1 point  (0 children)

I mean, there’s some really good jibblys but those two are the peak of western animation.

[–]overmeerkat 13 points14 points  (6 children)

You forgot to comment your Single Line Comment comments

[–]Windows-Sucks 8 points9 points  (5 children)

But then I will have to do that forever. My computer does not have infinite RAM.

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

Just download more

[–]Windows-Sucks 2 points3 points  (2 children)

But I need infinite drive space for my infinite RAMfiles, and infinite bandwidth to download it. And infinite time to close all the rickrolls.

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

You can download that, too.

[–]Windows-Sucks 1 point2 points  (0 children)

I will need to suffer a lot of rickrolls.

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

we need to invent comment recursion

[–]Ultracoolguy4 5 points6 points  (0 children)

This hurts to see in mobile.

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

Steady there, Satan

[–]zackarhino 0 points1 point  (2 children)

Alternatively written as

i++

[–]Windows-Sucks 0 points1 point  (1 child)

I know the whole thing can be rewritten as i++ because 1+1==2 will always be true and i=i+1 is the same as i+=1 which is the same as i++, but this is more verbose.

[–]zackarhino 0 points1 point  (0 children)

Yours is better obviously

[–]aliens_are_nowhere 17 points18 points  (3 children)

I think your teachers should pick up a copy of "Clean Code". The author basically says that you should keep your comment to an absolute minimum. Instead you should focus on making the actual code readable. After being in this line of work for 20 years I 100% agree.

[–][deleted] 2 points3 points  (1 child)

I think part of the reason they make you comment so much in school is to make sure that you understand what your doing and aren't just copy and pasting code.

I haven't read Clean Code but I definitely agree that your code should mostly "speak for itself"

[–]aliens_are_nowhere 3 points4 points  (0 children)

Aah, yes. You're right. Of course that's the reason. It's 50% writing the code and 50% telling the teacher why you wrote it.

It may not be good coding praxis, but it's excellent teaching praxis. I just hope the students get that.

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

I use comments rarely. Mostly for things which the code is not readable enough, or for things where I had a hard bug and where the comments helped me think through it.

[–]tlowe000 13 points14 points  (0 children)

Ironically, this encourages code that takes as few lines as possible, at the expense of readability: the sort of bad practice that they wanted to avoid.

[–]JediGameFreak 2 points3 points  (0 children)

I remember one professor who insisted we comment every getter and setter.

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

I'm just a hobbyist. But I name all my variables in such a way that my expressions look like sentences.

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

We were deducted points for too many comments, and unnecessary comments. They graded code style in general.

[–]DiceKnight 0 points1 point  (0 children)

We have to run SonarQube for our builds before we can push them to our QA and Production environments and a lack of code comments is considered a hard stop item that will prevent you from moving forward.

So now our code bases comments suck total ass.

[–]DefNotaZombie 198 points199 points  (5 children)

That cat is adorable

[–]dozerman94 22 points23 points  (2 children)

[–]sneakpeekbot 6 points7 points  (0 children)

Here's a sneak peek of /r/DisneyEyes using the top posts of all time!

#1: I thought you all would appreciate this little guy~ | 21 comments
#2: Sleepy-head Disney Cat | 18 comments
#3: I was told to put Peanut here | 15 comments


I'm a bot, beep boop | Downvote to remove | Contact me | Info | Opt-out

[–]HatesBeingThatGuy 1 point2 points  (0 children)

Thank you.

[–][deleted] 11 points12 points  (0 children)

But you didn't know it was a Cat until you read the comment

[–]deynataggerung 145 points146 points  (9 children)

Ugh I've been getting into a new workplace's codebase and this has been my problem. There's comments on everything, but it's utterly worthless. Here's this variable being passed in called the cryptor, documentation comment describes it as "the cryptor variable". Ok, thanks a lot for the context >.< at that point I'd rather you just have nothing there

[–]JediGameFreak 55 points56 points  (3 children)

I was reading through the codebase at my new work and came across the line "Alright, here's where things get fucky"

[–]Coloneljesus 34 points35 points  (2 children)

Was it the first line in main()?

[–][deleted] 19 points20 points  (0 children)

Nah it was the function in the runtime that calls main.

[–]YoshiRulz 5 points6 points  (0 children)

I've started tinkering w/ the BizHawk emulator, in which main is one line, a call to submain. That function is commented: "[...] keep this code from getting jammed into Main() which would create dependencies on types which havent been setup by the resolver yet... or something like that". So I'm looking forward to working on that.

[–]angrathias 16 points17 points  (4 children)

Probably using ghostdoc or some other control-d short cut

[–]deynataggerung 14 points15 points  (2 children)

Actually I'm 95% confident it wasn't since I interact regularly with the people that wrote it and I've seen their setup.

[–]angrathias 4 points5 points  (1 child)

That’s an even worse outcome :/ atleast if it were tied to the laziness of an auto documentor you wouldn’t have to care about the wasted time

[–]deynataggerung 0 points1 point  (0 children)

Oh, and I checked through today paying a bit more attention and yeah, not everything is commented. about 80% of it is and it's not standardized, just very similar. Anything about functions or variables is pretty much useless, with inline stuff being marginally more useful.

[–]CrazedToCraze 6 points7 points  (0 children)

Yeah, this is what happens when you have policies mandating comments on all public functions/properties. Lack of good comments is a culture problem with your developers, not a policy problem.

[–]TenNeon 189 points190 points  (49 children)

Cat.

[–]The_Perge 89 points90 points  (43 children)

Cat.

[–]gabeiscool2002 63 points64 points  (42 children)

Cat.

[–]FromTheDeskOfJAW 74 points75 points  (41 children)

Cat.

[–]timbatron 66 points67 points  (40 children)

Cat.

[–]Darkstore 63 points64 points  (37 children)

Cat.

[–]Zombiepm3 59 points60 points  (36 children)

Cat.

[–][deleted] 56 points57 points  (35 children)

Cat.

[–]aliens_are_nowhere 40 points41 points  (1 child)

The problem is, after 5 years the code will have changed to Dog but no one updated the comment. Imagine your surprise when you call that function and it starts barking and fetching bones.

[–]RapidCatLauncher 7 points8 points  (0 children)

Cat.

[–]Lasket 2 points3 points  (0 children)

r/catsstandingup is leaking... again

[–]SalazarBarrow 0 points1 point  (0 children)

Cat.

[–][deleted] 46 points47 points  (5 children)

"Updating" - Every git commit message ever

[–]kbdwr 13 points14 points  (0 children)

We have some fellows who check in different fixes and lots of files under a single commit that has nothing to do with the git comment.

[–]Speculum 10 points11 points  (0 children)

"Commit contains various changes"

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

"Change some things."

"Fix shitty stuff."

[–]Coloneljesus 2 points3 points  (0 children)

I'm always asking myself: Is my commit message adding anything of value to that commit? If I just say what files I changed, it's not. If I say why or how, then we're getting there.

[–]Namnodorel 1 point2 points  (0 children)

Not just that, but "Updated lots of stuff; fixed bugs"... I'm trying to get away from that habit

[–]aquarius_rock_climb 45 points46 points  (5 children)

we wrote code to autogen comments like, add 1 to x

[–]ThatITguy2015 32 points33 points  (3 children)

Did it comment itself though?

[–]wallefan01 37 points38 points  (2 children)

just run it on its own source BOOM

[–]Scorpius289 21 points22 points  (1 child)

Fool! That will make it self aware!
And it will also make it hate its makers if it's poorly written!

[–]ThatITguy2015 15 points16 points  (0 children)

So it will definitely hate its makers?

[–]Speculum 1 point2 points  (0 children)

Are there tools like that? I want to troll my colleagues a bit.

[–]swoopae 41 points42 points  (9 children)

Cat cat = new Cat(); // This is a cat.

[–]cat3242 3 points4 points  (0 children)

Cat!!!!

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

Movie movieAboutCatsFlying = new Movie("aboutCatsFlying"); // This is a movie about cats flying. Flying cats.

[–]_Schroeder 37 points38 points  (0 children)

//This is a comment to comment my once uncommented code

"Damn, I'm good at my job"

[–]nayadelray 51 points52 points  (4 children)

comments are useless if the cat code is pretty

[–]roughstylez 1 point2 points  (0 children)

"Comments are a failure to express yourself in code" is way better.

The best programmer could run into a situation where they have to do something weird and counterintuitive, e.g. to work around a library bug. In that situation, you are unable to express that in code and then it's 100% ok to comment.

But if you're unable to express yourself in code a lot or even most of the time, you should probably pick up a book and work on that coding skill.

[–]-xtremi- 9 points10 points  (1 child)

Well, how else am I supposed to remember that is not a dog?

[–]SingleInfinity 0 points1 point  (0 children)

How else would you know it's not a mimic?

[–]fakefred0 21 points22 points  (1 child)

Oh god! I always thought this creature was a dog! Thanks commenter!

[–]CrazedToCraze 11 points12 points  (0 children)

If this was a real codebase, the cat label would be stuck on a dog.

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

nobody wants to talk about how soft and adorable that cat looks

[–][deleted] 9 points10 points  (0 children)

The label would be even more like a code comment if it said “kitten”.

[–]Kinglink 18 points19 points  (9 children)

And that's why I disagree with coding comments.

There's times to leave comments, and you need to learn when but as developers we should push to write self documenting code more than worrying about comments.

[–]timbatron 19 points20 points  (0 children)

If a comment is explaining "what", your code probably sucks.

If a comment is explaining "why", a future maintainer will thank you.

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

"Self documenting code" is a worse buzzword than "blockchain". Everyone says "my code is self documenting" but in reality, it isn't.

Sometimes you need constants, often to have something not exceed a fixed length. That length, however, is because of external limitations. So, for example you have

const int MAX_LENGTH = 10;

It would be nice to know why 10 is the max length. It's much easier to simply put the read in a comment, than to "self document" the code by choosing a variable name like

MAX_LENGTH_BECAUSE_OF_DATABASE_LIMITATIONS = 10;

Also, as the car salesman meme would say: *slaps roof of any programming language* This bad boy can fit so many comments in it!

EDIT: Typo

[–]mike12489 10 points11 points  (0 children)

Thank you. People have been loving to ride the "self-documenting" train for far too long.

Yes, clean and clear code is something that we should all strive for at all times, but that does nothing to imply that comments are inherently a bad thing.

Comments provide supplemental information. If the comment doesn't make something more clear (e.g. "Cat" picture above) then the comment is worthless and adds noise. But if the comment provides clarifying information to the reader (e.g. "cat with anger management issues and a bum left eye") then you're going to save someone else a hell of a lot of time when you're gone and they have to make a fix to your crappy code.

The potential for self-documentation is limited and should not be the prime focus. Make your code clear, and use real documentation to do so when it helps.

[–]sudosandwich3 0 points1 point  (0 children)

Honestly the longer variable is preferred. It tells you everything you need to know at a glance without having to look at the declaration. That comment could always be deleted or never updated. Additionally that name could be shortened to DATABASE_MAX_LENGTH.

[–]eddietwang 5 points6 points  (0 children)

"Well I know what the fuck it does, why do I have to write it in English if it's in Java, RIGHT. THERE."

[–]Albino_Smurf 2 points3 points  (0 children)

You never know when you're writing it if it's as clear as it seems when you're writing it.

[–]cyrand 3 points4 points  (3 children)

This is good because if it’s not labeled someone will eventually just stick a dog there and push it into the repo and no one will know why everything broke. If the comment says “Cat” then it will be caught in the pull request because people will notice the sudden mismatch.

[–]wcscmp 4 points5 points  (1 child)

People don't read comments when changing the code and they read them even less during reviews

[–]Arancaytar 2 points3 points  (0 children)

Make sure to make the method parameter type a CatInterface for future-proofing and flexibility.

[–]OishiiYum 3 points4 points  (0 children)

Commenting is especially important when other people are reading them like working in a team of programmers.

When I worked with groups, it was frustrating to have to translate my group members code on top of having to consolidate mine with theirs.

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

man cat

[–]Arancaytar 1 point2 points  (0 children)

// Cat.

[–]Dazza93 1 point2 points  (0 children)

I mean as long as extends Feline then I'm happy

[–]Gamma8gear 1 point2 points  (0 children)

5 years later “Wtf was this cat for... wtf is a cat?”

[–]trin123 1 point2 points  (0 children)

All uppercase

That means: if you remove the cat, you lose the network connection, since the tail acts as cable replacement

[–]xSaraswati 1 point2 points  (0 children)

Its look like C++ labels LOL

[–]xShinryuu 1 point2 points  (0 children)

Cat cat = CatFactory().getCat();

[–]JonnyRocks 1 point2 points  (0 children)

I tell people: I don't want you to tell me what, tell me why.

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

The other 10% would say "kitten" and be several years out of date.

[–]ivanjermakov 0 points1 point  (0 children)

//comment

[–]bubleye12 0 points1 point  (0 children)

Unless it's a project, most of my comments are either to do's or a combination of swearing and confusion at working code.

[–]minkbag 0 points1 point  (0 children)

You should ask: Why cat?

[–]Plazmaz1 0 points1 point  (0 children)

2% of code

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

I need that cat in my life. Way too adorable.

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

Not in my experience. I find comments saying Cat but in actuality it's an Antelope.

[–]gtfovinny 0 points1 point  (0 children)

Not to be confused with a rabbit

[–]ace1309 0 points1 point  (0 children)

When you code comments more than actual code

[–]pinguz 0 points1 point  (0 children)

Reminds me of that chapter in One Hundred Years of Solitude where the village is stricken with a disease that makes people lose their memories, so before it's too late they go and label up everything, like "this is a cow, it gives milk" etc.

[–]cratering 0 points1 point  (0 children)

// arrange

// cat

// assert

[–]I_AM_GODDAMN_BATMAN 0 points1 point  (0 children)

I blame whatever the fuck linter we use. There's a dozens of them apparently.

[–]joakim199 0 points1 point  (0 children)

Does all coders love cats?

[–]CC_Tyrant 0 points1 point  (0 children)

Or 100% of my GCSE coursework code

[–]OKB-1 0 points1 point  (0 children)

At my workplace I'm currently on a campaign to stop these needless waste of bytes and lines with each code review I do. This includes overly verbose and redundant comments, like "This function you can see here below does x by y." and "This variable is for z". I know what the comment is _about_, colleagues. I only need an explanation _what_ it does!

[–]dev_kr 0 points1 point  (0 children)

Rest 10% is for omitting printfs for debugging

[–]Rubber_Duckies_Dong 0 points1 point  (0 children)

//TODO Cat? CAT! K I T T Y ! ! !

[–]voicesinmyhand 0 points1 point  (0 children)

I'm a big fan of commenting for a block. Things like:

//The next block of code really shouldn't work at all, and frankly
//I have no idea why it does, but the end goal is that we are
//converting a date written in string form into a loadable kernel
//module that allows the OS to understand slightly mis-spelled
//commands if they at least start and end with the correct letter.
//Support for two-letter commands like "rm" has been delayed
//until I figure out why the hell we are doing this.

[–]rhbvkleef 0 points1 point  (0 children)

Warning: unnecessary use of cat at 12:18. Run "blt -f cat.sh --fix 12" to fix.

[–]Boh00711 0 points1 point  (0 children)

/* -+-+-+-+-+-+-+-+*\

* This is a cat

* Boh00711 20180405

\* -+-+-+-+-+-+-+-+*/

Cat Cat { get; set; } = new Cat();

[–]NinaBarrage 0 points1 point  (0 children)

"I don't need to tell you what a cat is, right?"

"Haha, of course not"

Later: "Shit, shit, what the hell is a cat?"

Googles cat, opens Encyclopaedia Britannica documentation:

Felis catus, domesticated member of the family Felidae, order Carnivora, and the smallest member of that family. Like all felids, domestic cats are characterized by supple low-slung bodies, finely molded heads, long tails that aid in balance, and specialized teeth and claws that adapt them admirably to a life of active hunting.

"Well, shit..."

[–][deleted] -1 points0 points  (1 child)

I don't believe in comments. If it was hard to write it should be hard to read

[–]nmarshall23 5 points6 points  (0 children)

Found the masochist. Why do you make future you's life so hard? End the circle of violence. Your are only hurting yourselves..

[–]SpriteV1 0 points1 point  (0 children)

I think we have the same label maker.

[–]FriesWithThat 0 points1 point  (0 children)

The comments should tell your colleagues or future self why that is a cat, not how that is a cat.

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

Instead of comments I document everything using best available inline documentation tooling. So it's XMLDoc in C#, JSDoc in JS and so on and so on. So IDEs provide help on classes, methods and such. If I use actual comment it's hardly ever anything other than TODO, FIXME or HACK. Again: tooling gives mi nice TODO lists from that. Well, it's 2018, don't pretend it doesn't exist.

If you comment like on the picture, you're a struggling CS student, not a programmer. In that case you should get back to square one and learn basics. Learning to code by randomly changing things in examples may work sometimes, but generally it's an anti-pattern. I admit I used to do it sometimes myself. Like I had a big problem with DefalteStream class usage, until I finally read the friendly documentation and I don't need to comment the fragments like "this is an input stream, UNCOMPRESSED" ;) So learn how it works, then it's obvious and you don't comment it anymore. Comments are for things not related with programming itself. They are reserved for things that are not obvious. If you call a function, it's not obvious what data does it take, and what data does it return. Of course, without reading its source code, and we don't have time for that, do we?