3 ms·
HN Challenge: name a scenario in which defining a constant as 86400 is better then defining it as (60 * 60 * 24). Or, are there languages where you can't decla
by strommen 12y ago
HN Challenge: name a scenario in which defining a constant as 86400 is better then defining it as (60 * 60 * 24).
Or, are there languages where you can't declare a constant with a multiplication expression?
- sliverstorm 12y agoTo me it's a coding style thing. The argument for 86400 would be, too many operators makes things damn confusing. When your define expands in the preprocessor to a function sixteen operators long, you have made a mess.
- zemo 12y ago> are there languages where you can't declare a constant with a multiplication expression? obviously PHP. php > const X = 1; php > echo X; 1 php > const Y = 1 * 2; Parse error: parse error, expecting `','' or `';'' in php shell code on line 1 php > echo Y; Y
- mappu 12y agoFixed in the (upcoming) PHP 5.6. https://wiki.php.net/rfc/const_scalar_exprs https://wiki.php.net/rfc/const_scalar_exprs
- quaffapint 12y agoI find myself with pre-optimization issues on my new code and define constants multiplied out rather than add that .000000001% extra overhead of doing the multiplication - it's a sickness.
- wlievens 12y agoActually in all likeliness your compiler will do tgat for you anyway.