Commenting code
May. 11th, 2006 01:45 am![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
I think my brain is hardwired to solve problems in the most elegant way. This has good consequences (I got a good degree from Cambridge, am paid £n0k/yr to program, and can beat Tony at noughts and crosses generalisations) and bad consequences (I don't like asking for directions or other help, I find it hard to get on well with people, etc).
When I was young, it used to almost be a point of pride that I didn't comment my code. Now I do so quite well, or so I believe. But I think both stem from the same underlying trait. When I was young, I saw the problem as "Write this program." Now, the problem has evolved into "Write this program so it works, and solves a specific problem, and in the future update it with the least possible effort."
When I was young, it used to almost be a point of pride that I didn't comment my code. Now I do so quite well, or so I believe. But I think both stem from the same underlying trait. When I was young, I saw the problem as "Write this program." Now, the problem has evolved into "Write this program so it works, and solves a specific problem, and in the future update it with the least possible effort."
no subject
Date: 2006-05-11 08:32 am (UTC)Aha! So you're the one who stole Occam's Razor!
no subject
Date: 2006-05-11 08:43 am (UTC)Until my first assignment in my previous job was to learn C and take over maintaining 100,000 lines of home-grown system, whose writer had left, and whose comments were restricted to one-liners saying things like "Bet you can't see why I've done it like this!" and variables were called things like isnull and were true if it wasn't and false if it was.
Now I think the standard should be that *someone else* can update it in the future with the least possible effort, and you shouldn't necessarily assume that they've used the language before...
no subject
Date: 2006-05-11 08:53 am (UTC)"Bet you can't see why I've done it like this!"
ROFL.
Now I think the standard should be that *someone else* can update it in the future with the least possible effort
That's about right. As a matter of fact I tend to think of "myself, with no memory of this code whatsoever" which is often close to the truth.
be that *someone else* can update it in the future
Date: 2006-05-11 08:54 am (UTC)no subject
Date: 2006-05-11 12:19 pm (UTC)Why yes I have been fixing other people's code for the last two days, why do you ask?
no subject
Date: 2006-05-11 09:08 am (UTC)Other times, of course, it's shameful and means losing face. Knowing which is which quickly is important.
no subject
Date: 2006-05-11 09:40 am (UTC)no subject
Date: 2006-05-11 12:23 pm (UTC)no subject
Date: 2006-05-11 11:35 am (UTC)no subject
Date: 2006-05-11 12:24 pm (UTC)no subject
Date: 2006-05-11 03:10 pm (UTC)As a young geeklet, it has to be said that I'm the opposite; I comment my code all the time, but that's because I'm a forgetful pixie. You might say I comment excessively, but I like to explain things well, so it can't be a bad thing. And when I move onto languages that are less fluffy than Java, commenting might be a good thing indeed!
Of course, you could always follow the silly rules of commenting. My personal preference is /* magic happens */ :P
no subject
Date: 2006-05-11 04:24 pm (UTC)/* magic happens */ :P
ROFL. Of course, sometimes that's the right comment -- if the author doesn't understand the code then that is a correct comment and the problem is in the code not the commenting :)
no subject
Date: 2006-05-12 06:31 pm (UTC)What. How. Why. Who. When.
What - the contract a function or object agrees to fulfill (arguments, checking, errors thrown, arguments returned, side effects, memory or resource usage - eg who frees the memory used by stuff passed and returned)
How - how does it implement this contract (Eg "Implements Kruskal's Algorithm")
Why - why does it do what it does? The reasons behind your design and implementation decisions ("Optimised for memory usage not speed because concurrent with process Foo that will always take 10 times as long")
Who & When - revision history & responsibility
Personally I'd like to see What, Who and When comments all handled automatically. I'd like the "How" to be as obvious as possible from the code itself. It is the "Why" that you often can't work out from one bit in isolation - you need to know the whole fragging system.
Douglas
no subject
Date: 2006-05-15 01:24 pm (UTC)If you know what, you might at least be able to work out how, but without what you have to understand the rest of the system. Why is great, but generally out of date.
If you have good what/why, who/when are less vital, but always necessary in working out what/why.