Jim McIntyre wrote:

> I got the impression from the AS2 documentation that one *should* set an
> initial value for a variable in the class body, as long as the initial
> value could be defined at compile time.
> 
> However, I've seen many folks leave the value undefined by not assigning
> anything in the class body, like your example below.
> 
> What's the real deal? Is there a reason it's better (or worse) to favor
> one practice over the other?

I'm not  sure what you mean by "class body", but in the example you cited,
the variable is initialized in the constructor. That guarantees that the
variable will be initialized.

As for initializing it in the variable declaration vs. in the constructor,
it's purely a matter of style and circumstance. Sometimes you can't
initialize a variable until the class is constructed--for example, a path.

It's crucial to initialize your variables--uninitialized variables are the
source of more bugs than any other single thing I can think of. It doesn't
matter a lot where you initialize the variables, though.

Cordially,

Kerry Thompson

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to