[WannaJava]

Java Beginners Tutorial

intro basics applets comments variables expressions loops review
Chpt. 4 Comments

Source code is created by humans, read by humans, and reworked by humans. Yes, eventually the source code is compiled, at which point the compiler reads it, but at that point it converts it into byte code. So we can safely say the source code is for the benefit of humans.

Having established this fact, we are obliged as programmers to make our code as readable and understandable as humanly possible. We have already seen one way in which we try to do this: using the indented structure we discussed in Dissecting HelloWorld. There is another way: peppering our code with comments.

Comments are exactly what they sound like. They are phrases and sentences you can add to you code that comment on what your code is doing. By using the right code format, you tell the compiler that these comments are for human eyes only, and the compiler ignores them. Humans, on the other hand, will pour over them in frustrated hope of deciphering the purpose and flow of your code.

The degree to which you comment your code is up to you (or your boss). If you are writing a tutorial, you may want to comment almost every line, describing in detail every step you take. If you are writing a program simply for yourself, you may just want to place strategic comments that will tweak your memory when you come back to the code in six months. If you are writing code that other programmers will have to use, you will most likely have to follow a set of comment conventions agreed upon by your group.



<< BACK | NEXT >>

WannaJava.com WannaJava.net WannaJava.org

WannaJava™
Copyright © 1999-2010 - All Rights Reserved
Contact Us