Const and its effects

I started using const lot more in my AS3 code. My reasoning is that if the value does not change, then why make it var .

I heard through twitter that const values ​​are optimized differently than vars . Because Twitter was short and sweet, details stayed here.

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

Let me start with the con statement: in Flash Builder values, const values ​​are not displayed in the debugger. Values ​​that do not change do not seem to deserve attention in the debugger.

+4
source share
3 answers

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

There is a pretty big semantic difference that you point to. The constant, since it cannot be changed, will cause the compiler to catch any problems in which the value changes with an error.

+3
source

The only thing I know for constants: you cannot change the value. This. ;-) Constants are constant, and variables are variables. If the value is constant, it should be declared constant and vice versa. This is a BIG hint for the compiler and developer.

Flash Builder displays the value of constants if you move the mouse over a constant or you can add a constant as an expression in the Expressions view. Of course, they are not listed in the Variables view.

Read the AS3 Docs: Constants for more information.

+1
source

As for your con, if you use Flash Builder, the constants are visible in the Variables view, if you go to the menu in the view, select the Flex submenu and choose Show Constants.

0
source

Source: https://habr.com/ru/post/1332338/


All Articles