views:

117

answers:

7

This may sound like a foolish question or an observation, but i have seen that most of the times when one tries to look at the opensource code, there are no comments or just one or two lines at the start of the function telling what the function is used for e.g. register a user or data in table etc. There is no code which actually explains what exactly the function is doing etc.

Is it done intentionally (removal of comments) when a code is released to open source community to make things difficult to understand by others?

+5  A: 

There is a line of thought that says that comments are unnecessary when the code speaks for itself. I don't believe comments would be removed on purpose, though.

Otávio Décio
Code as big as firefox or mysql, i am sure would need commenting even for experienced programmers unless you have bunch of programmers who have just coded on one particular project since its inception. Though would not like to debate if we need comments or not. It is an observation based on some of the leading open source projects with huge code base.
Kavitesh Singh
@Kavitesh Singh: Not necessarily...the "code speaks for itself" can be scaled to any project and any size, even Firefox. But that does only work as long as code the code is well written. If the project has over 20k lines, and everything is packed in functions which are not longer then 20 lines, what would I need comments _in_ the functions for?
Bobby
@ocdecio: code never speaks for itself. that line of thought is baloney.
Paul Nathan
@Paul Nathan: this is actually the first time I've seen/heard someone say this. For me it was pretty obvious, that well-written code rarely needs much inline commentary, because it, as they say, "speaks for itself". As for badly-structured or downright bad code it doesn't really matter, - even if you put four million volts.. err I mean comments through it, it is still bad code.
shylent
There are *way* too many times where I'll read my code or someone else's code and I'll be asking myself, "what was he on when writing this ----". Comments are a must for a comprehensible code base.
Paul Nathan
@shylent: there are times the "what" of the code is clear, but the "why" is not. Think of a device driver working around defective hardware, using undocumented (or not well known) port banging. The code is clear, but you'll still scratch your wondering what's going on.
themis
@Paul Nathan - I am not arguing in favor or against the point, just saying that baloney or not there are people that really believe that a well written piece of code requires little commenting. That's the whole reason behind refactoring, extracting methods, giving methods a meaningful name, have a method have a single responsibility and etc.
Otávio Décio
+2  A: 

I don't think there is a practice or policy to remove comments when releasing software as Open Source. A sneaky software publisher might think that a good idea (maintaining de facto exclusivity, because nobody can't understand it, while having released an open source product) but this would cripple the Open Source project from the start and most likely render it unusable.

The code you are talking about is probably just very little documented. As ocdecio says, that can be either a good sign (the code speaks for itself and does not need comments) or a bad one (it is badly documented, bad code). Both cases are entirely possible. :)

Pekka
+1  A: 

What are you comparing it to?

I doubt that closed-source code has better comments.

As for what functions do, there is probably API documentation. No need to duplicate those in comments.

Thilo
I was going through mozilla code and then few other projects on sourceforge too. Didnt really find commenting which was detailed to make things easy for an amateur like me.
Kavitesh Singh
A: 

As a rule, functions should be small enough and written in a way that allows working out how it works by just reading them. A comment on top of the function describing what it does helps getting a quick overview of the function itself when reading through the whole source code file (unless the function name speaks for itself).

Many projects are organized in that way, and that is great.

However, what I am often missing when trying find my way around a larger codebase is something describing the big picture, i.e. the general architecture, principles, what goes where and similar things.

ndim
A: 

Open source software has bad comments and bad documentation most of the time. There are various reasons why, some better than others. Usually they relate to laziness or the developers 'being in the moment'. None of the reasons are good reasons.

Paul Nathan
+3  A: 

I've seen both sides, and frankly code in general is insufficiently documented.

I've been congratulated and thanked for leaving copious breadcrumbs but that's because I've had to sift through too much undocumented code to want to subject anyone else to it.

Call it an ethical obligation.

My reason to document code: my short-term memory is junk. I write comments to remind myself of why I did something. Everyone else benefiting from that is gravy.

Broam
A: 

All open source is not made the same. This is what we call a generalization.

If you look at the website Ohloh, which tracks a very large amount of the open source software in existence, it paints a much different picture:

http://www.ohloh.net/languages?query=&sort=code

For instance, in the C language, there are 252+ million lines of comments, approx 1 in every 5 lines of C is a comment. For Java, nearly 1 in 3 lines is a comment. That's not bad.

joemoe