+ 1
Why use constants?
Is there a benifit for using a constant over using the other variable types?
8 Antworten
+ 5
They also can be used for set up. For example, I have the default speed of a foe (in a spaceship game, it will not change when the project will be finished). I use this value a lot in my code. If I want to change the value (to try with quicker foes), I'll just have to change the constant instead of changing every where I used it.
So, why not using a variable ? For the same reasons that was already told by @aklex : optimisation.
+ 6
It also lets the compiler know that the object/variable will not change, which can open up more optimizations made by the compiler
+ 4
Constants are for making sure that if you intend to create a value that cannot be changed, then you can know that a constant will never change and therefore is safer to use. This is how you can avoid debugging headaches down the line.
0
constant are used to make value same throughout the project
0
it's mainly use full deceleration of database or configuration of database
0
in my opinion we use the if we have something and it doesn't change
0
π es un ejemplo clarísimo