Comments


Documenting programs is a very important practice all software developers should do, no matter what programming language they use. Unfortunately, documentation is often the first thing to suffer when a project is crunched for time.

If you are the only developer for a program, you might think that because you wrote the program, you should have no problem remembering how the program works. From experience, leaving a piece of code and coming back to it a year or more later is nearly equivalent to reading someone else's code, unless of course it is documented.

Managed C++, like traditional C++, provides two comment styles: the single-line comment and the multiline comment.

The single-line comment begins with a double slash (//). Anything after the double slash is a comment. Depending on where you place the double slash, you can use a single-line comment to comment an entire line or just part of a line. By the way, you probably noticed the comments in the previous example code, but here are a couple more examples:

 // This entire line is a comment. Int32 x = 0;   // This comment uses part of the line. 

The multiline comment starts with /* and ends with */. You can place multiline comments anywhere in the code, even on different lines. You must use care with this kind of comment, as embedding a multiline comment within a multiline comment will cause errors. Here are some multiline comments:

 /*****************************************************  * Common comment box. You will see these frequently *  * within programs.                                  *  *****************************************************/ Int32 x = 0;  /*  This is a comment on a single line */ Int32 y = 0;  /*  This is a comment that stretched for                   More than one line */ /* Embedded comments like this /* do not work    as you might expect */ this portion would    not be commented and will in this case cause errors */ 

Because of the embedded comment problem, many programmers, myself included, prefer to use the double slash comment.




Managed C++ and. NET Development
Managed C++ and .NET Development: Visual Studio .NET 2003 Edition
ISBN: 1590590333
EAN: 2147483647
Year: 2005
Pages: 169

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net