News for hackers. Stuff that matters.
Re:JSON as configuration files: please don’t (2016) by breck on Saturday April 13, 2019 @02:54PM (#19655004)
> Comments are mostly useless in a machine-generated and machine-consumed file. They are indispensable for humans, because they are a link to what machines are not doing.

But comments are often code smell—a crutch for poor identifier naming and design. If your names and design are well thought out you rarely need comments and the consumer of your code should be able to understand it using the statically checked source alone—-versus manually having to parse your unchecked human language documentation.

Re:JSON as configuration files: please don’t (2016) by nine_k on Saturday April 13, 2019 @03:51PM (#19655346)
Comments are a code smell when they describe things that should be described in code.

Comments are important when they express things that code cannot.

Examples:

// See ticket XYZ-123 for discussion and rationale.

// We are sidestepping a bug in Docker 3.x here.

// TODO: Allow queue size per service version. Currently we're using max size for all.

Re:JSON as configuration files: please don’t (2016) by breck on Saturday April 13, 2019 @07:52PM (#19656560)
Great examples. I wonder though if all those could be better expressed using something like decorators in order to enforce some static time checks. For example, instead of a free form comment to do have a structured todo notation that then makes the todo parsible and checkable. Often I see a //todo comment that is still there by accident after the thing is done. Or a todo that has since been abandoned.
Re:JSON as configuration files: please don’t (2016) by breck on Saturday April 13, 2019 @03:07PM (#19655086)
Edit: adding a link to the Clean Code bit about comments, which I think is great advice : https://gist.github.com/wojteklu/73c6914cc446146b8b533c0988c...
Re:JSON as configuration files: please don’t (2016) by TeMPOraL on Saturday April 13, 2019 @04:08PM (#19655447)
From the link, about comments:

  Use as explanation of intent.
  Use as clarification of code.
  Use as warning of consequences.
Here's a link to a well-known recent book, half of which is pretty much about why those points are a real and frequent thing, and why code should be much more thoroughly commented than it's recommended by the usual philosophies.

https://www.amazon.com/Philosophy-Software-Design-John-Ouste...

Re:JSON as configuration files: please don’t (2016) by afiori on Saturday April 13, 2019 @06:10PM (#19656072)
In a JSON config comments can be very useful to "hide" disabled options

["DoStuff", "EvenMore"/, "ops go back :("/]

Re:JSON as configuration files: please don’t (2016) by j88439h84 on Saturday April 13, 2019 @02:57PM (#19655018)
> If your names and design are well thought out

Sure, but how often does that happen?

Re:JSON as configuration files: please don’t (2016) by breck on Saturday April 13, 2019 @03:05PM (#19655077)
It usually happens in good code if the language supports it. But I agree, not enough and comments are great as a stopgap until the thing you need to explain can be explained in the programming language. But sometimes that can’t be and so you do need to resort to comments. It’s like types in doc comments being used as a stopgap until a language added types. I hypothesize (I plan at some point to crunch some data here) the more comments the worse the language, and so you’d see a pattern like Python 3 code having fewer comments on average than Python 2 code.
Re:JSON as configuration files: please don’t (2016) by int_19h on Saturday April 13, 2019 @09:33PM (#19656974)
JSON is data, not code.