So this could be labeled “failure to keep politics and legal stuff out of the code”. On the other hand, if someone gives away his source code at all, it is often accompanied with a license.txt or something similar. Note that some kind of copyright comment can be company policy that you can’t easily get rid of. One comment that could have been left in is the “end namespace” comment, if the namespaces are deeply nested and you don’t want to indent the class definition accordingly. Consider the header without the comments: #ifndef Bazinga_H Look at this exemplary header: #ifndef Bazinga_H In a code base I currently work on there are a ton of redundant comments. You probably think that nowadays nobody will write redundant comments, right? This is a textbook example of a bad comment and you probably have seen it before. This comment is utter noise and only costs the reader time. I say less maintainable, because the comment that does not add any useful information will be read by everyone who reads the code. The comment does not help, it only adds noise, making the code less maintainable. The comment is not needed for us to see that. Really? Is that an addition? Of course it is. Consider this piece of code: int i = a + b //adds a and b In contrast to some very old style guides, it is not good to comment each and every line of code. Failure to add information Comment redundancy There are times where a comment simply does not accomplish its purpose, and sometimes there are better ways than using a comment. There are different ways in which comments can express failure, most of them being programmer failures. Ways in which comments can express failure They are meant to clarify, where clarification is needed.Ĭlarification in this case means either providing additional information that can not be found in the source code or making information more prominent that would otherwise be difficult to extract from the code for whatever reason. The purpose of commentsĬomments are there to express something that is not immediately apparent from the code. I don’t like comments, because having to comment a piece of code means the code itself does not express everything there is to know.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |