DEV Community

Discussion on: Why Good Code Needs Comments

Collapse
 
sebbdk profile image
Sebastian Vargr • Edited

This is interesting, could you give some examples in rough code?

Like fx. where would you suggest adding comments, maybe some specific instances where you remember a comment saved the day etc.

I'm a huge fan of verbose code, but i've been debugging for almost 14 years now. So i hardly spend much time figuring out how things work unless i am dealing with something entirely new.

So to be frank, i have a huge bias/blindspot.
So examples would help me a lot. :)

Collapse
 
mxldevs profile image
MxL Devs

I haven't thought of a good example yet. The one in draft right now involves a method that generates a hash token by taking some data and manipulating it a specific way based on how the app does it, and then at some point the dev changed it which causes all my requests to fail.

Without comments, I couldn't remember why it was doing all if those things or how I even figured it out, so I had to go back and understand the app all over again. If I had simply wrote down where to find the algorithm, it would've saved me a lot of time.

But I don't know how relatable this example is.

Collapse
 
sebbdk profile image
Sebastian Vargr

A bit, I’ve had to add unit tests to enforce not changing certain Functions return values before.

Not all environments are unit test viable, I could see my self adding warning comments if that was the case. :)

That being said, changing the return type of something Is generally very bad, so my hope is that it would be caught in code review first.

Thread Thread
 
mxldevs profile image
MxL Devs

Most of the tools I have rely on third party services/data formats, some of which are not designed with the end-user in mind (eg: proprietary formats, internal API's, etc) so I think the issues I'm running into are mostly because I'm doing things people shouldn't be doing lol