Friday, January 22. 2010Self documenting code is a lieTrackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
Wow, that's way overboard! I must confess that I usually don't comment my code. I know that I should, but I'd never comment as crazily as you did in that blurry screenshot. Is that normal for you? No, that's pretty abnormal. Normally it's either nothing (for small/straight forward functions), a line or two to visually separate the logical parts of a bigger function, and of course the occasional three or four line block where something needs some explanation. Here's the initializer of an ActionScript class: http://img.skitch.com/20100122-tf7e5qpnkyge19r5m11b5ejbkb.png When this came up in RSS I thought of something else I wanted to say! I may have uttered something in the past that made you think I said that all code should be self-documenting. I may again in the future. If so, what I really mean is that self-documenting code is an ideal. And when you hit it, there's little point in documenting it. At the extreme case, getters and (simple) setters do not need a comment. Many things, usually the things at the heart of the program, need documentation. It's unavoidable. Still get as CLOSE as possible to self-documenting, then document where it wasn't possible. Yes, you're right - clear code (ie, "self documenting") is much, much better than commented ugly code. But I have heard more than a few people say things along the lines of "I don't need comments because I write self-documenting code"… But, as you've said, there are situations where comments are critical to explain why the line "there are situations where comments are critical to explain why the line x += 1; x -= 1 is vitally important." In many of those cases, changing the name of x eliminates the need to add a comment. E.g. numberOfLinesReadSoFar += 1 or numberOfNewMessages -= 1. |
QuicksearchArchivesLinksCategories |