Bunny

Programming Primer
Licensing And Preface

Standardized Coding Practices

Errors And Exceptions

Variables

String DataType

Number DataTypes

Conditionals

Commonly Used Flash Commands

More Topics:

3D

Music

Processing

Flash



Part 2: Standardized Coding Practices

Standardized Coding Practices

Standardized coding practices are there to establish a consistency between different software languages. If you do not use them your software may or may not throw an exception, but you can be certain that there are many people that will! Use these practices and avoid creating your own, they have been tried and tested for many years.

Comments

Comments are lines of information inserted between code that informs a person reading the code what the purpose of the next line or next few lines of code is. Comments are completely ignored by the software executing the code. They should be written in plain and simple English or, what ever your chosen language, however consider that the comments you write might not always be for your personal understanding but for another person reading your code.

Comments are particularly useful for code that you have not used in several months. Regardless of whether you wrote the code or not, trying to understand what revisited code is supposed to do after long periods of time becomes a cumbersome process when it is not commented properly.

By the way it is estimated that 80% of a programmers time is spent maintaining code that already exists, this is largely why commenting code is a standardized coding practice.

White Space

Flash unlike some other software languages totally ignores white space. White space is the space between the characters that make up the lines of code for example a space, tab or enter/break. Just because Flash ignores white space doesn't mean you should. Using a consistent spacing and formatting of your code will make it more human readable. For example,

var firstNumber:Number=1;var nextNumber:Number=2;trace(firstNumber nextNumber);

is a lot more difficult to read than this,


var firstNumber:Number=1;

var nextNumber:Number=2;

trace(firstNumber nextNumber);


White space can be a particularly useful visual clue to separate code into task specific blocks. These blocks are referred to as code blocks.

if (1 == true){
trace("yep, 1 does indeed still mean true");
trace("so true must also equal 1, right?");
|
|This is a code block
}else{
trace("somethings not right, here!"); |This is another code block
};

Code blocks depicted with standardized coding practices will always have the same indentation per line of task specific code in Flash. One line will always follow the next, until the task of the code block is completed, at which point the indentation may change.

Next: Errors And Exceptions