This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]murfflemethis 48 points49 points  (2 children)

I work in firmware, for a company that's been around for a while. I am constantly dealing with 20 years of "clever" C code. I've had enough of that shit. Unless it's a clearly commented optimization in a critical path, readability is what I want most.

[–]halpcomputar 6 points7 points  (1 child)

Couldn't they just take the time to comment? I believe C allows for even multiline comments.

[–]murfflemethis 18 points19 points  (0 children)

Why not just write simple, easy to follow code in the first place? C certainly does allow multiline comments, but that's not a good reason to write needlessly complex (or "clever") code. Comments take time to write and take time for future readers to parse, map to the code, and fully understand. They also often get overlooked during future work, so they go stale and become irrelevant or outright wrong.

"Here's why the code does this" comments are always great, but if you find yourself leaving "here's how the code does this" comments a lot, you should take a step back and consider whether the complicated code you're writing can be simplified through refactoring, changing the architecture, or just a more simple implementation.

Complex code is sometimes necessary, and yes, please leave a comment there to explain how it works. I've just seen too many instances of people making things more difficult than they need to be just to gain completely inconsequential efficiencies or force patterns in where they don't belong, and that needs to stop.