PDA

View Full Version : public static var/const: Name conventions


Flash Gordon
07-14-2007, 10:37 PM
Hi,

What is the convention for naming public static vars? I know public static conts look like this:

public static const HELLO_WORLD:String = "hello world";


But is the all capital letters because is it static or because it is a constant? So what would be the convention for this:

public static var WIDTH:Number = 300;

where "WIDTH" would actually change? Would it be all upper case or lower case?

LOLFlash
07-15-2007, 03:54 AM
Good question, as much as a know, you can't declare constant in Flash and they advise to name variables UPPERCASE as reminder: it is variable that you shouldn't change in future.

Flash Gordon
07-15-2007, 04:20 AM
AS 3.0 allows contsants just like the first code I posted.

question still out there.......

Assertnfailure
07-15-2007, 07:23 AM
All caps is a convention for constant, not static. Static variables should still follow the same conventions as instance variables.

Flash Gordon
07-15-2007, 08:49 AM
ok....so I take it AS 2.0 use just trying to fake constants.

Thanks
:)

Assertnfailure
07-15-2007, 05:52 PM
Well, in AS 2.0 you'd just caps to differentiate between which values shouldn't be changed.

However I always liked to write my constants in AS 2.0 like this:

public static function get MAX_HEIGHT():Number{ return 500; }

Flash Gordon
07-15-2007, 08:32 PM
yea that makes sense. That's a nice approach for AS 2.0.

Thanks
:)

Assertnfailure
07-16-2007, 12:54 AM
np d0000d