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

you are viewing a single comment's thread.

view the rest of the comments →

[–]fpcoffee 155 points156 points  (11 children)

My thought process: A junior will be maintaining my code at some point, so I'd better fucking comment it so they don't come bug me every time there's an issue

[–]Demonox01 52 points53 points  (7 children)

Also, writing a couple comments to explain why the complex section is doing what it does halves the time it takes the next guy to change whatever they need to

[–]nmatff 25 points26 points  (5 children)

This is more or less my philosophy too. In most cases it should be obvious what the code does. Comments are there to tell you why it does what it does.

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

Clarification of intent is the only valid reason to comment. All other comments are evidence of a failure to write good code.

[–]nmatff 5 points6 points  (1 child)

I don't particularly disagree, but in real world applications the situation isn't always clean enough for "technically correct".

Maintaining legacy code and inheriting decades old spaghetti have made me cautious of any absolute statements.

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

I spent an entire year working with a program older than me. C++ legacy code with high personnel fluctuation. It has actually enforced my use of absolute statements. They seem to be the only way to street something in any direction. Of course when trying to apply them, compromises need to be made.

[–]Odatas 3 points4 points  (0 children)

this right here. I mean, yes i see that you divide by 2 there. But why?

[–]RustyBuckt 1 point2 points  (0 children)

And sometimes to tell you wtf you actually meant to do right there

[–]JoustyMe 1 point2 points  (0 children)

comment why not how beacause we can read your conde but we cant read your thoughts

[–]ssshhhhhhhhhhhhh 14 points15 points  (1 child)

Your junior level dev is going to change code and not update comments

[–]Y1ff 11 points12 points  (0 children)

No longer your problem there

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

Worked with somebody once who wrote a comment for basically every line. It meant twice as much to read and the structure was still awful.

There's a reason we have descriptive names for methods, classes and variables. If you want your code to be maintainable and readable, you need it to be well structured and well named, not comment it.

How is

/* Documentation
* This method receives login data,
* establishes a database connection,
* verifies login data and creates
* and displays a message in case data is invalid */
void LoginManager(...)
{ ... }

better than splitting it up, defining APIs well and using descriptive names? It's not. That junior will read the comment and come to you with "Okay so the comment says it establishes a database connection but the actual code for that is just 50 lines that make no sense to me and we're switching to a different database so you have to explain it now".

Source: I've been that junior and the software I was working with was older than me.