I have gotten quite a few comments from former co-workers who have taken over some of the projects I was lead on about how easy it was to read. That brings me a lot of joy, knowing that I made their lives easier and that the output of the trade I invest so much time and energy into is appreciated by my peers.
That said, I think `self-documenting code` is the bare minimum in 2022.
At my current role, I'm pushing the org to become "documentation first"--but this goes way outside the scope of writing code.
It's about writing all 4 types of documentation[] as a daily practice. This way, when you create something or learn something, that gets documented for the next person. It's not just about what variables and functions are for.
It's about what the business is doing and how that relates to our work, what our poor backend-cum-devops folks are having to do day in and day out, and about helping everyone accomplish their tasks without needing to go around getting help from 3 different people over 5 days because the system is completely opaque.
// function to get the recipes
function getRecipes() { ... }
which are redundant and pollute the codebase.Where have you heard that writing useful comments (e.g. explaining an edge case, explaining a technical workaround, etc) is a bad practice?
For example: http://web.archive.org/web/20100415205750/http://blog.weapon...
But there is also information that you can't just describe into the code. There are the examples I already gave above. Another one could be what I did this afternoon: I had 2 options to solve a problem, I chose the more complicated one but the one that works in every case. I added a 4 lines comment describing the second option and why I didn't use it. There is no other way to add this information that would be useful for me or another developer in the future other than a comment.
At least once I forgot to add a comment in such a case and luckily I got the question of "why not just..." in the code review.
They are pretty clear about "useful comments" - by what they wrote, it sounds like they already understand what you wrote.
No-comment self-documenting code is largely a backlash to this style, which is how introductory coding courses teach (taught?) was the right way to do comments. For a lot of programmers who first started in in one of these courses it tended to stick because they were never taught another way.
// function to get the recipes (!)
function getRecipes()
Or just document what recipes actually mean within the application context.Maybe? Not sure - haven't worked on enough big projects to declare answer
>A new developer is supposed to go through all the codebases and figure out for himself?
Yes to this bit - code should have very clear structure to it with appropriate comments attached, whether that's literate style as JonesForth<https://github.com/phf/forth/blob/master/x86/jonesforth.S> shows, small section header comment or whatever.
It should be very clear what section exploring does - tiny example but cat<http://9p.io/sources/plan9/sys/src/cmd/cat.c> from plan 9 very simple segmented code - deals with file opening in main loop and cat function just reads and prints text
If your code is sufficiently clear there will be nothing left to say in the comments, the comments will have to repeat what the code is already telling you which significantly diminishes the value of comments.
>You don't write README.md
I don't think people are talking about self promoting projects or self documenting projects.
>ARCHITECTURE.md
or self documenting architecture.
>JavaDocs, etc, at all?
or self documenting libraries.
Seriously, what's so hard to understand about looking at code and then understanding it because you read it instead of having to read comments to understand the code that is in front of you? You seem to be under the wrong impression that self documenting code is a negative process where things are taken away rather than added.
And unless your programs are formally verified this process that you have codified most likely will not meet the requirements to satisfy the intended purpose.
A typical non-technical "assignment" that's given before someone is fluent is to describe in excruciating detail/list of steps how to make a peanut butter and jelly sandwich. The point of the exercise is to show students that you need to remove all ambiguity. Or at least as much as possibly. What the exercise doesn't show is.. why are we making a list of steps to tell someone how to make a sandwich.
“If you give me six lines written by the hand of the best debugging programmers, I will find something in them which will hang his operating system.”
Incorrect. The code can never tell you WHY. That's what comments are for.
The big drawback (right now?) is that diffs are computed on a line basis rather than a semantic token basis, so a bug fix for a comparison operator obfuscates the raison d'être of a whole conditional.