10

forget comments! write self documenting code that's obvious to anyone reading the system.

Comments
  • 0
    the kicker is that it can take a long time for it to be obvious ;).
  • 2
    I love the idea, but it's fantasy land. "Obvious" is completely subjective and commercial pressures nigh on always guarantee hacks and rushed commits coming up to deadlines. It's just the way it is.

    To me it seems like a false economy to save time writing comments but instead introducing technical debt striving for some "ideal world" scenario.
  • 1
    I use to write the name of functions and variable like this post_a_comment_on_devrant all done
  • 1
    the only comments worth making is to explain the finer logical details that you can't glean a first glance
  • 1
    @samk the point of not commenting is not to earn time. Comments are dead, and code lives. Sometimes people forget to update comments when they change something in a function, and there the comment will make the code even harder to understand! This kind of things won't happen if you write really litteral code, cause if you change the code, well the previous one isn't there anymore to mislead you :)
  • 2
    @ryuu That's a fair point. But I guess I'd argue that's a function of code review (make sure comments reflect code).

    You also can't guarantee a level of knowledge and ability across your team. Comments can be educational in this context. Not everyone may be capable of structuring code precisely or may not know every element of syntax in a given language.

    I know I'm a dinosaur on this subject and the contemporary, agile way is to minimise the need, but I still advocate commenting of code.
  • 1
    @samk your arguments have their weight too :) I guess it depends a lot on your team and personal tastes too. Both views have pros and cons. I have a co-worker who has the same viewpoint as you and he's often ranting about how I split my code in too many functions (which I do to express in words what my code does) instead of just putting a simple comment.
  • 1
    @ryuu I hope I don't come across as ranting about this! 😝 I also would not, in any way, discourage anyone from splitting code into multiple, small functions - and absolutely no way would I use good comments as a justification for writing unnecessarily complex code.
Add Comment