Most voted "constant" questions
In programming, constants are definitions whose value is fixed throughout the execution of a program. Literals, in most languages, are constants. In referentially transparent programming styles, all settings are constant.
Learn more…43 questions
Sort by count of
-
25
votes3
answers6810
viewsDifference between PATH_SEPARATOR and DIRECTORY_SEPARATOR
The documentation on this is rather vague, the little that exists does not clearly clarify the difference between the use and purpose of the following two PHP constants: PATH_SEPARATOR and…
-
25
votes1
answer2636
viewsWhat is the difference between const and readonly?
Read-only constants and fields cannot be modified, as can be seen in the documentation: const Constant fields and locations are not variable and cannot be modified. readonly When a field declaration…
-
15
votes4
answers1443
viewsShould an enumeration be constant in the lifetime of the solution?
Modern languages often have a type of enumeration that is usually a range of related constants. Its members are usually constant. In most languages this is even guaranteed by the compiler. But…
software-engineering encoding-style enums constant lifespanasked 10 years, 6 months ago Maniero 444,682 -
15
votes3
answers356
viewsWhy is it possible to change an array or object value from within a constant?
const array = ["a", "b", "c", "d"]; array[1] = 2; console.log(array); //- ['a',2,'c','d'] In this example I gave, I changed the value of the constant dynamically, too, it is possible to do the same…
-
12
votes2
answers2447
viewsWhat is the difference between define() and const?
What is the difference between declaring constants with define() or with const. Would it be the same thing or have some detail I should know? define('TESTE', 'constante 1'); const TESTE2 =…
-
12
votes4
answers11601
viewsSet constant in Python
How can I declare a constant in Python the same way I do in C with #Define PI 3.1415 or in java public final double PI = 3.1415…
-
11
votes2
answers791
viewsWhat are the advantages and disadvantages of declaring constants as an array?
I found way too this new Feature of PHP 5.6. It is now possible to define a array for the value of a constant. Look how cool: const BR_DATES = [ 1 => 'Janeiro', 2 => 'Fevereiro', 3 =>…
-
11
votes3
answers887
viewsHow to print a constant in the middle of a string, without concatenating?
Is there any way to print a constant in the middle of a string, without using concatenation, as with PHP variables? Example: $nome = 'wallace'; echo "Meu nome é {$nome}"; In the case of constants, I…
-
11
votes1
answer173
viewsConstant is really useful?
Why would I use a constant instead of a variable? In addition to readability, there is another gain in using a constant? I can’t make a difference that makes me use a constant instead of a variable.…
-
10
votes1
answer1271
viewsBecause the practice of "constant parameter" exists only in C
In C, there is the practice of applying the "const" modifier to function parameters when the function does not aim to change the parameter. As in this code: char process_string(const char *str);…
-
10
votes3
answers603
viewsWhy is it allowed to delete elements from an array defined as const?
Assuming I have set an array to const: const array = [1,2,3] Why is it possible for one of these elements to be removed? This would not be a way to reassign the array? It’s possible I’ll make one:…
-
9
votes3
answers11758
viewsWhen to use const and when to use #define
Since the two do the same function there is some difference between one and the other? I’ll take the code from this site as an example C - Constants & Literals The #define Preprocessor #include…
-
7
votes1
answer339
viewsHow to declare constants in R
when I went to reproduce the example of the question "How to turn a string into Date format in R?" the command tab<-readHTMLTable(u,header=T,skip.rows=1) failed. The error happened because in my…
-
7
votes3
answers845
viewsHow to declare a constant in Ruby?
How to declare a constant in Ruby? In other languages I do something like: const CONSTANTE = 1024 And CONSTANTE cannot be changed at runtime. But I can’t find anything like this in Ruby.…
-
6
votes1
answer113
viewsWhy do constants in the File class not follow the constant convention?
The convention for Java constants says that a constant should be declared with uppercase letters only and words should be separated by underscore (_). The declaration of a constant is made by the…
-
6
votes1
answer85
viewsShould I avoid operations between constants in a loop?
In C++ there is some sort of optimization or cache that prevents the same mathematical operation between constants to be repeated, mainly in loops, thus decreasing application performance? For…
-
6
votes1
answer111
viewsDifference between overall, const and define()
So I was studying about POO and MVC structures with PHP and saw that we often need to use global variables (accessible throughout the application) and what’s the difference of using: global $nome =…
-
4
votes2
answers405
viewsHow to make a constant object in Javascript
How do I declare a constant object in Javascript? For example: /* meu código */ object_teste = {valor:5} /* console navegador */ object_teste.valor=10; console.log(object_teste.valor) // aqui ele me…
-
4
votes2
answers395
viewsHow to verify if a constant exists in the class or in a namespace?
In PHP, to check if a constant exists we use the function defined. As below, for the two cases of constant declaration: const MY_TEST_1 = 'my test 1'; define('MY_TEST_2', 'my test 2');…
-
4
votes1
answer3427
viewsStatement const at the end of function in C++ and const before argument in method
I came across this piece of code in a material: class Foo { public: int Bar(int arg1) const //<-- qual função do const aqui? { // código a ser implementado aqui } }; [1] Like the const affects…
-
4
votes2
answers137
viewsConstants of non-priminal types
In Java, constants are declared with sequences of Keywords static and final. When we have public static final int UM = 1; "makes sense to "call it constant, since its value cannot be changed. Now,…
-
4
votes3
answers124
viewsHow can I use or name constants for response type fields?
There are situations in which we have fields that represent a type of response, whether boolean responses sim and não, S and N or with multiple responses like the status of something. For example…
-
3
votes1
answer161
viewsBecause in PHP, some predefined constants are case-insensitive?
Because, in the PHP, some predefined constants are case-insensitive (do not differentiate capital letters from minuscules) and others are not? Example 1: echo __FILE__; // index.php echo __file__;…
-
3
votes4
answers1114
viewsCreate string array in C#
There is a way to create an array of string constant? Something like: class Teste { public const string[] Array = new string[] {"a","b"}; } But this one doesn’t compile. In this case nay would…
-
3
votes2
answers144
viewsWhat are the differences between constants declared with const and immutable variables declared with Let in Rust?
The declaration of immutable variables In Rust if you want to declare a variable, we use the keyword let. Example: fn main() { let site_name = "Stack Overflow em Português";…
-
2
votes3
answers1471
viewsHow do I use a constant within a class method?
I defined a constant in a file and would like to call it within a method in a class. Example: Filing cabinet: Configuracao.php <?php define('FOO','Hello World'); require_once('Classe.php'); ?>…
-
2
votes3
answers90
viewsConstant containing Array (matrix)
When I try to define a constant as an Array gives error. define('COLORS', ['red', 'blue', 'green']); Is there any way to define an Array in the value of a constant?…
-
2
votes1
answer101
viewsWhy define a constant for the same document and check if it exists in the document itself?
I see in many codes out there programmers that setam a constant and in the document itself check whether this constant exists (was defined) in itself. I would like to know why this happens. When we…
-
2
votes1
answer340
viewsHow to create Java constants?
A java constant cannot be changed, but can be assigned an initial value via another variable ? For example, if we have in our program a method that hypothetically calculates the import rate of a…
-
2
votes1
answer56
viewsHow to take only one value of a Random variable and turn it into a constant?
How do I get only one value from a variable you use Random and store in another variable? It is possible? Wanted to store what will appear to the user int cartaUnoPersonagem = new…
-
1
votes1
answer49
viewsCan overuse of constants affect system performance?
I use quite a lot constantes in php to store information to configure the system Example: define('_CONFIG_SERVER','PC\SQLEXPRESS'); define('_CONFIG_DATA','Database');…
-
1
votes0
answers78
viewsMethods that return constant values in C and C++ even if they come from variables, is it possible?
In a series of optimizations in a code written in C++ adopted a class to store application parameterization data and some pseuconstants let’s say so. What actually happens is that when the…
-
1
votes1
answer133
viewsWhat is the difference of declaring a variable as constexpr const and constexpr?
What is the difference of declaring a constant as constexpr const for only one constexpr? constexpr const float max_height = 3.0f; constexpr float max_height = 3.0f;…
-
1
votes0
answers51
viewsError when setting a constant
I’m getting the following error in my code, and I’m not getting the reason why. Got error 'PHP message: PHP Warning: Constants may only evaluate to scalar values in config.php on line 85 On the…
-
1
votes2
answers77
viewsWhen to use constexpr in C++?
See you around the keyword constexpr (mainly in ifs and constants) many times, I have read the Microsoft documentation and searched on the internet and still did not understand much the function of…
-
0
votes1
answer50
viewsSet the variable value as an equation
I wanted an equation to appear as a function of x and not the value of the equation, is it possible? I found nothing, and I’m starting now programming in javascript and do not know much
-
0
votes1
answer29
viewschange global Contant value
Good afternoon, I would like to know if it is possible to change the value received by a global constant and set another value. For example, I take the value of the color that is set in the edge…
-
0
votes0
answers63
viewsHow to interpolate constants?
Why don’t these interpolations work and how to make them: class Foo { const BAR = "baz"; } define("TAZ", "qux"); echo "Foo::BAR={Foo::BAR} TAZ={TAZ}"; //Foo::BAR={Foo::BAR} TAZ={TAZ} echo…
-
0
votes1
answer45
viewsError declaring Java constants
I have just started my studies in Java and I have a problem declaring a constant: class Ex007 { public static void main(String[] args) { float comprimento, raio = 9f; public static final float PI =…
-
-1
votes1
answer170
viewsWhat is a constant?
A while ago I did a question about constants that didn’t work out so well and I saw that it was really possible to get a good content out of it, so I’m reshaping it. Even being something basic, I…
-
-2
votes1
answer107
viewsCounties in codeigniter with DB data
Good afternoon I need to get some settings for my site that comes from a table in the database, currently I use variable more then every time have to go there at the bank to get, I think this can…
-
-6
votes1
answer150
viewsIs it possible to delay the initialization of a constant?
With delay initialization, I say initialize a constant after your declaration. For example (pseudocode): const exemplo; exemplo = 2;
-
-6
votes3
answers177
viewsHow to initialize a constant with the value of time. Now() in Golang?
I’m used to doing projects in Python where, when initializing the same I keep a variable saying when it started (to measure the execution time of the project) like this: import time started_at =…