DEV Community

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

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.