x += 1; // Increases x by one
…Years later
x += config.increment; // Increases x by one
""" config.yaml increment: -2 """
// increase the dynamically allocated memory space of a word sized integer stored at the memory address represented by the symbol "x" by the integer 1 and terminate the instruction
Why the heck does it need to be dynamically allocated? Just put that puppy on the stack.
That’s what it used to do.
But it was a bug, and the code has been fixed.
Wait why is it dynamically allocated and why are you increasing the memory. Something is very wrong here
Yeah, but unironic…
If your code needs comments, it’s either because it’s unnecessarily complex/convoluted, or because there’s more thought in it (e.g. complex mathematic operations, or edge-cases etc.). Comments just often don’t age well IME, and when people are “forced” to read the (hopefully readable) code, they will more likely understand what is really happening, and the relevant design decisions.
Good video I really recommend: https://www.youtube.com/watch?v=Bf7vDBBOBUA
This mindset is good, but unfortunately enforces bad programmers to leave their undocumented code in critical places where someone eventually has to figure out what the hell they were doing or refactor the whole damn thing because they got promoted to middle-management and can’t remember why they even wrote it.
“I’ll just be extremely precise with my variable names. Then everyone will know exactly what everything does!”
Uses variable names like “INTEGER” and “STRING”
Comments don’t describe the code. They describe the decision to use this business logic.
If you stick to good engineering practices, like small methods/functions, decoupling, and having testable code, you don’t often need many comments to show what your code does. I always recommend a method signature, though, because you can save a few seconds by just saying that a block of code does, rather than me needing to read exactly how you turned one dict into another dict…