HACKER Q&A
📣 hamedb

What code do you consider as clean code?


obviously this is something debatable and subjective but there's always some common basis that everyone agrees on. do you have any good examples of code you wrote or saw on Github that you consider as state of the art code? what makes it so great? if you are reading someone else's code how do you want it to be written/structured (preferably JS examples)


  👤 MattGaiser Accepted Answer ✓
> but there's always some common basis that everyone agrees on.

I am really curious what this is because I have been with 4 organizations now and despite all doing things very differently, they insist that they are doing things according to "industry standard."

I have even had a few cases of two senior devs reviewing my PR at the same time and going back and forth to tell me to revert what the other dev had me put in, with both coming from prestigious companies.


👤 gabrielsroka
Steve McConnell covers this in "Code Complete". Iirc, a lot of the book is based on actual research done, not anecdata.

https://en.wikipedia.org/wiki/Code_Complete


👤 joshink1
I've enjoyed reading the Guacamole client code (JS): https://github.com/apache/guacamole-client/blob/master/guaca...

Clean and consistent formatting, detailed comments, sensible modularization -- and it works well


👤 giorgioz
One of the first thing to pick up that it's likely agreed upon by everyone is to give meaningful names to variables:

// GOOD

let fullname = 'John Smith'

// BAD

let f = 'John Smith'