A comment on commenting

The first language I dabbled in was Java and that was for a class in high school. Commenting in Java is pretty much the same as commenting in C, C++, C#, and Obj-C. Example:

//Single comment

/*  Block Comment */

After receiving the first assignment for the class, I glanced through it and everything seem well. Although there was no specification for comments, I had to add some anyways since ever since I started coding the idea of commenting and documenting your program was pounded into my head. So of course, by reflex I commented all my programs using the double slash even though I knew Python used a different syntax and of course I got errors. So I simply had to Google up real quick how the commenting syntax for bash and Python which luckily used the same syntax for commenting using the number sign.

Of course this isn’t a big deal or anything, but it’s just irritating sometimes when you’re working with multiple languages on a project and you’re switching between languages. Sometimes you just code and your brain can flip flop the commenting syntax, like what I’ve done so many times before and you get annoying and easily avoidable errors. The most annoying of this is developing a website. HTML’s comment tag is <!– Comment –>, which is sort of annoying when you just want to add comments real quick. Javascript and PHP uses the two slash to comment and it’s sometimes annoying when I switch around and use two slashes in some HTML snippets (even though I’m pretty sure it usually wouldn’t cause errors and just ignore the line, it still could).

Bottom line is I wish all languages just use the same syntax for commenting, even though I’m sure that there are different functionality of the characters in other languages. Here is a list showing the some of the different ways to comment in different languages:

Java, Javascript, PHP,  C, C++, C#, Obj-C: // Comment

Python and Bash: # Comment

Lua (A scripting language): — Comment

Ruby: Ruby is weird since you use the number sign for single comments but block commenting requires this:

=begin comment block =end

4 thoughts on “A comment on commenting

  1. I clicked on your post because of the catchy title, but I have to agree with the content. While doing the mult assignment I had to look up the different ways to comment in bash and python, and was frustrated that I had to do it. I too wish that there was a single commenting character. I think that there are far too many languages for this to ever be the case, but a programmer can dream..

  2. ah yes, it’s one of those things that we just have to get used to and learn to live with. One thing that can be handy is that most programming aware text editors such as vim or emacs will have an editor command to comment out a highlighted block of code, and since the editor generally automatically knows what language you are writing in, you then just need to learn one keyboard command to comment ALL THE THINGS. See http://www.emacswiki.org/emacs/CommentingCode for details of the emacs method. I will leave the vim solution as an exercise for the reader.

    Also, side comment. On the comments feed on the mother blog, the title of this comment was “comment on A comment on commenting”. How could I not click?

  3. I completely agree that it is annoying trying to get used to different ways of commenting. Besides the commenting, the syntax is completely different which makes it really confusing after learning just one language. I guess it gets better after learning 2 or more, but besides the commenting, how python does not use semi-colons completely bugs me.

Leave a Reply