During the course of your time spent programming video games, there will often be times where you need to go back over your code days, weeks, even months after you've originally wrote the code to update it. (for example in games that have new versions released on a regular basis, like Madden) You'll find that without proper documentation, you can easily forget what your code does and why it's there. This is often referred to as "code rot." The solution? Comments.
Comments are used in code to tell you or someone else(you might be working on a big project in a group) what the code does. Comments are not parsed by Flash; and for that matter, the concept of commenting codes is pretty universal throughout all programming and scripting languages. Comments only exist to aid in the organization and readability of your code. If you think this isn’t important, think again. Just because you understand what you’re typing up now doesn’t mean that 6 months from now you’ll remember what parts of your code did what.
So that your code is manageable and others can read and understand it (so that perhaps they can help you make your game), it’s important to have comments that describe what does what, and why it does it.
There are two different styles of comments in programming: I call them C-style comments and C++ comments. Or you might wish to call them multi-line and single-line comments, respectively.
C-style comments begin with ‘/*’ and do not end until you terminate them with the ‘*/’ symbols. If you do not close these comments, ALL code after your opening comment symbol will not be parsed as code, but rather ignored. Sometimes this is actually done intentionally to test what a game would be like without certain lines of code, without having to actually DELETE them. This is called “commenting out” code.
Example:
*/ This will go on and on…
…And on… until I terminate the comment with */
You’re also able to use C++ (or single-line) comments. These are much easier to type: they’re simply two forward slashes ‘//’. Everything beyond those slashes is “commented out” until it reaches the end of the line. So these comments don’t need to be terminated. They automatically terminate at the end of any line of code.
Example:
if (x==5) //If x equals 5,
DoSomething(); //Do something.
Tuesday, April 3, 2007
Subscribe to:
Post Comments (Atom)
1 comments:
Interesting to know.
Post a Comment