Tuesday, January 20, 2009

Visual Studio2008: Comments

Comments are parts of a program that are ignored by the Visual Basic 2008 compiler, which means you can write whatever you like in them, be it English, C#, Perl, FORTRAN, Chinese, whatever. What they ’ re supposed to do is help the human developer reading the code understand what each part of the code is supposed to be doing.

All languages support comments, not just Visual Basic 2008. If you ’ re looking at C# code, for example,you ’ ll find that comments start with a double forward slash ( // ).




In Visual Basic 2008, you begin your comments with an apostrophe ('). Anything on the same line following that apostrophe is your comment. You can also add comments onto a line that already has code, like this:

intNumber = intNumber + 1 'Add 1 to the value of intNumber

This works just as well, because only comments (not code) follow the apostrophe. Note that the
comments in the preceding code, more or less, match the algorithm. A good technique for
adding comments is to write a few words explaining the stage of the algorithm that ’ s being expressed as software code.

Comments are primarily used to make the code easier to understand, either to a new developer who ’ s never seen your code before or to you when you haven ’ t reviewed your code for a while. The purpose of a comment is to point out something that might not be immediately obvious or to summarize code to enable the developer to understand what ’ s going on without having to ponder each and every line.

You ’ ll find that programmers have their own guidelines about how to write comments. If you work for a larger software company, or your manager/mentor is hot on coding standards, they will dictate which formats your comments should take and where you should and should not add comments to the code.

"The compiler ignores whitespace and comments, so there are no performance differences between codewith lots of whitespace and comments, and code with none."

No comments:

Post a Comment