602
No comment
(lemmy.nz)
Related Communities !programmerhumor@lemmy.ml !programmer_humor@programming.dev !programmerhumor@kbin.social !programming_horror@programming.dev
Other Programming Communities !programming@beehaw.org !programming@programming.dev !programming@lemmy.ml !programming@kbin.social !learn_programming@programming.dev !functional_programming@programming.dev !embedded_prog@lemmy.ml
Most code isn't unreadable, because it's optimized for performance, but rather because it is needlessly complicated and should be refactored. And then reducing this complexity is likely to improve performance as well.
For example, you might draft out an algorithm with a nested loop, and then you look at it once more and realize that it can be done with a single loop. That's very likely easier to grasp and massively better for performance, too.
If you do need to make code unreadable for performance reasons, then absolutely do make use of comments. Although I would still recommend making it understandable without resorting to comments, if possible.
Function, variable and test names can help to explain a lot. Error and log messages can be used to write out really clearly what is happening. And they have the huge advantage compared to code comments, that they show up in at least two places, which makes them more likely to be read and updated.
As someone else already wrote, the why should still be explained with a code comment. It rarely makes sense to explain implementation details in log statements...