DEV Community

Discussion on: What's the worst advice you've ever received?

Collapse
 
mxldevs profile image
MxL Devs

"Good code doesn't need comments"

Collapse
 
malaud profile image
Malaury

Could you explain a bit more your thought?

Collapse
 
oguzhanaknc profile image
Oğuzhan Akıncı

Writing code is like making a joke. It's bad if you need to explain.

Collapse
 
almenon profile image
Almenon

If a joke was used as the basis for entire industries, I'd sure as heck want a explanation.

Collapse
 
codemouse92 profile image
Jason C. McDonald

Tell me about it.

Good code shouldn't need a code to describe what it's doing, but it certainly benefits from intent-comments ("why").

Collapse
 
garretharp profile image
Garret

That is good advice. I should be able to look at the function names and variables and get a good idea of what is happening without comments.

Collapse
 
sebbdk profile image
Sebastian Vargr

Wait, what? why is that bad advice? :)

The idea is to make verbose code, it’s the main difference I observe in programmers relative to their experience level.

Novices tend to make messy complex code riddled with or needing comments & experienced programmers make simple/short code that uses sane naming and formatting so comments become pointless.

Correct if I’m wrong please, I feel like I would need that lesson. :D

Collapse
 
mxldevs profile image
MxL Devs • Edited

Good names help make it easier to understand what the code is doing compared to using variables like a and b and method names like my_func1 but it doesn't explain things like "why you wrote the code", "how it's intended to be used", etc.

Some devs might end up with this idea that as long as they write clean beautiful verbose code, comments won't be needed.

I've written a post about comments to clarify my position on comments.

Thread Thread
 
sebbdk profile image
Sebastian Vargr • Edited

I would have to disagree, intent and why' can be conveyed.
It requires extra thought tho, which is what the quote is trying to encourage.
It's not meant to be taken literally.

Take fx.


// I'm gonna assume this is the unix cat command maybe?
// I have no idea what data is.. this could be anything.
function cat(data) {...} 

// Gonna assume this returns a Cat embedded in the input
function getCat(from) {...}

// Gonna assume this generate's a new cat from the input
function generateCat(from) {...}

// My comments make sense here btw. :)
// Since i am actually commenting' on my' thoughts.
// Not what is going on in the code.

The intent is conveyed using verbs and subjects.
This communicates the message or intent shorter, usually meaning better.
The subjects i should know what is based on context and documentation.

The quote "If I had more time, I would have written a shorter letter." - Someone
Fully encompasses the idea.

I'l flip through you article now, thank you for taking the time to write it. :)

// Edit, ps, worth noting, with types, the verbosity and intent here could be much improved.

Collapse
 
iamarya profile image
Arya

Woah! One of the worse advices I have seen on this thread a nightmare even for junior devs/admins haha!