开发者

Const and its effects

I've started using cons开发者_如何学Ct a lot more in my AS3 code. My reasoning being that if a value does not change then why make it a var.

I heard through the twitter vine that const values are optimized differently than vars. Due to twitter being short and sweet, this is where the details stopped.

Does anyone have more info on the pro/cons of using var and const.

Let me start off by stating a con: in Flash Builder const values are not visible in the debugger. It seems values that do not change are not worth viewing in a debugger.


According to Jackson Dunstan, there's no real difference performance wise when using const instead of var.

There's a pretty big semantical distinction however, which you point out yourself. A const, since it can't be changed, will make the compiler catch any issues where the value is changed in error.


The only con I know for constants is: you can't change the value. That's it. ;-) Constants are constant and variables are variable. If a value is constant then it should be declared as constant and vice versa. That's a BIG hint for the compiler and the developer.

Flash Builder shows the value for constants if you move the mouse pointer over the constant or you can add a constant as expression to the "Expressions" view. Of course they are not listed in the "Variables" view.

Fore more informations read the AS3 Docs: Constants


Regarding your con, if you're using Flash Builder, constants are visible in the Variables view if you go to the menu on the view, select the Flex submenu, and chose Show Constants.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜