Tải bản đầy đủ (.pdf) (2 trang)

Eliminating Bugs Before They Hatch

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (18.3 KB, 2 trang )


< Day Day Up >

Eliminating Bugs Before They Hatch
Writing code is not something you want to do while half asleep. As you've probably
experienced, Flash is unforgiving when it interprets the script you add to a project.
Seemingly tiny errors such as a faulty line of script or even a misspelled word can have a
damaging domino effect on the rest of the code in your project. These minor problems are
experienced by scripters of all skill levels. Most problems can usually be solved by a tap
on the Backspace key. But if errors are hidden deep inside your code, you'll find yourself
staring at it for hours, pulling out your hair, and yelling at your dog (maybe even pulling
out your dog's hair if things get really out of control). Sometimes the simplest problem
can be the largest contributor to a stressful development cycle.
One of the best ways to avoid many problems is to be aware of what they are. The
following list shows some of the more common mistakes that all scripters make:

Omitting quotation marks in strings. Strings of text should always be identified
with quotes.

Misnaming variables, functions, and objects. As your project grows, you'll need to
keep track of more named items. It's a good idea to adopt a common naming
convention, based on your preferences. Some scripters use all lowercase letters
and underscores to name variables, such as my_variable and my_other_variable,
and in-fix notation (where the first letter of the first word is lowercase, while the
first letter in subsequent words is uppercase) for function names such as
myFunction() and myOtherFunction(). Other scripters avoid using plural names
completely; they don't have to remember whether an element's name has an s at
the end. Whatever naming conventions you adopt, consistency is the key.
Remember that ActionScript is case-sensitive, so userName and username are not
the same.


Omitting quotation marks when comparing string values. When writing a condi
tional statement, the concept of using quotes to identify strings sometimes gets lost
in our brains as we type. If a conditional statement is not doing what it should,
suspect missing quotation marks.

Forgetting case when comparing string values. This is an easy mistake to commit.
Remember, "this string" is not equal to "This String". Case must be considered
when comparing string values.

Confusing = and ==. A single equals sign assigns a value (this = that). A double
equals sign compares values (does this == that?).

Missing or mismatched curly braces around blocks of code. Make sure that the end
of a code block has as many closing curly braces (}) as the beginning of the block
has opening braces ({).

Omitting the return statement in a function. If a function is meant to return a value,
it will be worthless (broken) without a return statement.

< Day Day Up >

×