Why don't developer comment their code?
This is a question I will try to answer by summarizing my life experience.
I've been coding most in PHP but I coded also in a few other languages but the majority of code I have written is PHP so I am a PHP programmer and that has shown me a lot of ugly thoughts why people just wont comment their code.
So here are some of the reasons why most of my colleagues and team mates didn't wont to comment their code and often find more appropriate to delete mines too so they see more REAL CODE than bullshits like comments and lines that separate CODE from DESIGN and so on.
"I'm lazy!"
Well I am lazy too. Laziness is the reason why people are so advanced these days ;). That is why I personally comment my code. I don't want to figure it all out again later cause I forgot what it was and how it works. Think about it. If it is commented you will never have to figure it out again because you have written down an explanation of all the weird parts. It ease everyones work if you haven't got to figure out the problem again every time it comes up.
"Good code is self-documenting!"
The programmer that thinks that way thinks his code is so good that any moron could understand it without comments. After all good code is self-documenting is it? Totally wrong! There are many pieces of code which just could be understand by looking at it. For example because they are one line of code. But in the big picture most of the hard to code algorithms aren't obvious at first look to all the programmers even to you if you look at it after a while. So hard, complex algorithms and code blocks should be documented.
"Upper management doesn't care about comments!"
The BOSS looks at the metrics supplied to him. These usually are like lines of code, hours spent at work, tasks completed or simply does this work. But just cause time spent commenting is not reported or your boss isn't interested in it doesn't mean it isn't important at least to you. The better your comment skill is, the more productive you will code when you rewrite or upgrade your code later. This will decrease some of your hours in the long term so putting some extra time in the beginning might be a good idea.
"I'll never work on this after I'm done!"
This is the normal newbie mistake. So when you have finished your first project and all went well with it you are ready to move on the next one and you do. You might get a couple of more projects done but then they start coming back to you. It is not because they were bad written but because the users wants new features. The idea is that if you have written something once you will most of the time (99% of the time) need at least a piece of it again.
Well I think I gave you enough reasons to think about this for a moment and at least give it a try. After all how bad could it be to put an extra sentence at the end or at the top of your code block ?
Well have fun with your comments...
and your well written never reused code too ;)
I will really appreciate comments on this topic.
And if you have in mind another reason why programmers just wont comment their code feel free to share it with us ;)
Прочети цялата статия...