Constant is that which is known (which is manifest or registered) or which has constancy (certainty, perseverance). Something constant is durable, repeated, or persistent. For example: “The constant effort of the North American led him to a new victory in the tournament”, “My grandfather always tells me that to be successful in business it is essential to be constant and never give up in the face of adversity”, “Estudiantes de La Plata is the most consistent Argentine team in recent years ”.
For mathematics, a constant is a quantity that has a fixed value in a certain calculation, process, or equation. This means that the constant is a permanent value that cannot be modified within a certain context. The usual thing is that it is related to a variable (whose values can be modified).
Physical constant
A physical constant is the invariable value of a physical quantity over time. An example of this, mentioned very often even in non-scientific fields, is the speed of light in vacuum (299,792,458 m / s).
When there is, in theory at least, a constant speed, travel times can be estimated. If a car is traveling at a constant speed of 100 kilometers per hour, it takes four hours to travel a 400-kilometer trip. As constant speed does not exist in practice, it is common for this type of estimations to be made with the average speed or average speed.
The concept in programming
In the field of computer programming, a constant is that value that cannot be modified during the execution of a program. It corresponds, therefore, to a fixed length in a reserved area in the memory of the computer.
Its applications, as well as its implementation methods, are diverse; They are generally used to determine values such as minimum and maximum speeds, error margins, fixed dimensions of elements that must be drawn many times during execution, and numbers of states of the various machines that usually compose a program. This last point is essential, since the state machine represents a very efficient organization model.
Example of applying a constant
Let’s take as an example a very simple application, which presents the user with a form with the fields “name” and “password” to verify the data once entered and that will only be closed once the result is positive. Basically, it can be said that said program will go through the following states from its start to its end:
0: it will load the resources necessary for its graphic representation, such as images for the buttons and fonts for the text;
1: it will create the form, setting the values of all its components (text input boxes, labels, buttons, pop-up messages) and display it on the screen;
2: it will wait for the user to enter their information and confirm said action;
3: it will proceed to verify the data and give one of two possible results: “correct”, in which case it will be closed; “Wrong”, which will lead to a state where it will display a message asking the user to repeat the procedure;
4: While the notification of incorrect data, the program will wait for an action by the user to return to state 1, probably changing the creation of the form (since it already exists) by a simple cleaning of its input fields.
Although the real structure of an application is more complex, the example given serves to demonstrate the efficiency and degree of control that allows the arrangement of states in a machine. In the code, which may be different for each programmer, each state is represented by a constant, which is named (such as IS_LOAD, IS_WAITING) and is generally associated with a numeric value.