Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [variables]

Variable or scalar is a storage location paired with an associated symbolic name (an identifier), which contains some known or unknown quantity or information referred to as a value.

Filter by
Sorted by
Tagged with
0 votes
3 answers
122 views

Use of environment variable or appsettings as a counter, good or bad practice [closed]

I'm wondering if it's bad practice to have a variable in a webserver which counts the amount of incoming requests and put it in an environment variable. In C# for example you have System.Configuration....
Vincent's user avatar
  • 383
0 votes
1 answer
140 views

How can I minimize the number of captured variables in lambda expressions? [closed]

If a lambda is frequently used, it is considered to reuse the same instance instead of creating new instances repeatedly. How can I minimize the number of captured variables in lambda expressions?
Arunabh's user avatar
  • 143
1 vote
2 answers
219 views

Variable assignment in ECMAScript specification in detail

I am trying to wrap my head around what the ECMAScript specification suggests about variable assignment. Introduction: Coming from Java, this is pretty straight forward. Variables get stored at a ...
tweekz's user avatar
  • 237
0 votes
2 answers
292 views

ECMAScript Primitives: Immutability vs Value Type

Coming from languages like C++, Java or PHP I've learned that there are Value Types and Reference Types. Value Types store values directly in the variable (in a box / memory location). Whereas ...
tweekz's user avatar
  • 237
0 votes
2 answers
532 views

Can a UUID be called a constant?

From my understanding, a constant is a value which is assigned only once and cannot change at runtime, whereas variables have mutable values which are unpredictable by nature. My question is, to what ...
Clara's user avatar
  • 53
0 votes
2 answers
239 views

Symbolic constants versus variables

coders. I'm learning C programming language and found out such thing as #define directive that allows us to use symbolic constants (following Brain Kernigan). I know that this directives "insert&...
CoderDesu's user avatar
  • 1,015
10 votes
7 answers
2k views

Is global state really always bad?

I have a question regarding my general understanding of global state in software engineering. When I write an app I like to decompose it into little, manageable components and functions, that are ...
Angelica's user avatar
  • 109
1 vote
3 answers
234 views

Does it always take the same amount of time to retrieve the same thing from collection?

for example: const arr = [1,2,3,4]; const coordinate = [arr[0] + 2, arr[0] + 1]; here arr[0] is written out twice, when the code is executed would it literally go and find same value twice or would ...
link2name's user avatar
32 votes
6 answers
8k views

Do inline expressions obstruct readability of code?

Currently, I'm reading "Code Complete" by Steve McConnell, 24.3 chapter "Specific Refactorings". I've become kind of confused with 4th paragraph, that looks like: Move an ...
CoderDesu's user avatar
  • 1,015
16 votes
5 answers
8k views

Why are variables declared without a value in C?

The way I see used most frequently int main() { int i; for (i=0; i<10; i++) { printf("hello\n"); } return 0; } The way I’m used to int main() { ...
Nickotine's user avatar
  • 290
4 votes
2 answers
3k views

What does "set" mean in programming languages like C#?

I've been reading a book about C#. What does the word 'set' mean in the following excerpt? Pattern matching with the switch statement: Like the if statement, the switch statement supports pattern ...
Hossein's user avatar
  • 75
2 votes
2 answers
2k views

What’s the standard used to deploy .env files?

I used docker to containerize the node.js express app and used GitHub action to add the .env file in the container. I googled this method when I was doing the DEV project. But I think that if someone ...
nermineslimane's user avatar
0 votes
1 answer
315 views

Is there a reason why you shouldn't use 'integration variables'?

I tend to create a variable whenever I need an uncircumstantially same value as to that of an earlier value more than once (the values are not happening to be the same by chance rather they actually ...
Nae's user avatar
  • 197
1 vote
1 answer
108 views

Variable binding time (Steve McConnell)

Currently reading Steve McConnell "Code complete". "General issues in using variables" chapter, "Binding time" section. He says about variable's binding time in such ...
CoderDesu's user avatar
  • 1,015
-2 votes
3 answers
3k views

Is there the difference between "symbols" and "characters" in programming?

I want to select between "symbol(s)" and "character(s)" for my variables' names in cases when these terms are synonyms. Please teach me some information which allows to make this ...
Takesi Tokugawa YD's user avatar
3 votes
3 answers
2k views

When doing multiple operations on a variable, is it considered bad practice to reuse the same variable name?

A commonly repeated best practice is to not reuse local variables. However, when doing multiple small operations on the same variable, I struggle both with coming up with good names for all the ...
Godsmith's user avatar
  • 141
2 votes
5 answers
5k views

Do all threads share the same instance of a heap variable, or have different instances of a heap variable? [closed]

Computer Systems: a Programmer's Perspective says: 12.4.2 Mapping Variables to Memory Variables in threaded C programs are mapped to virtual memory according to their storage classes: Global ...
Tim's user avatar
  • 5,485
-2 votes
1 answer
135 views

System Hungarian Notation for Android UI components?

Is using System Hungarian Notation for Android UI components (Views) valid? I mean using it ONLY for Views - no strSomething, boolStuff or similar names. For example, tvDescription (TextView), ...
Anxxy1's user avatar
  • 17
-3 votes
1 answer
209 views

Long variable naming with chained filters on API best practices?

I am writing an application where a single variable may be affected by different filters applied to the data that's read from the DB. Each different variation has to be stored (as each one serves ...
HumbertoWoody's user avatar
-2 votes
2 answers
101 views

Nassi Shneiderman diagram: Which player has its turn?

I am trying to program a little game and for that I need to determine which's players turn. I am solving it firstly with a Nassi-Schneiderman diagram with a variable turn whic can be 1 or 2, but my ...
kripss's user avatar
  • 23
-1 votes
1 answer
331 views

Is there a naming convention for variables that hold one of several possible ids?

Sorry if this is a silly question, but I am not a native english speaker and a lot of times it is difficult for me to come up with meaningful variable names. I have a table of users in our app. All ...
Karolis's user avatar
  • 115
2 votes
3 answers
135 views

Is there a way to specify a two-way relationship between variables?

Let's say we have two variables, eta and phi related by eta = cos(phi). Is there a way to link these variables in any programming language such that there's no need for two different functions, ...
BeeperTeeper's user avatar
2 votes
3 answers
4k views

Declaring Multiple Variables of the Same Type within a Function's Parameters

We've started looking at functions, and our homework requires us to include some simple ones in our programming. As we've left it a little late in the semester to explore functions, we're well-used to ...
user316193's user avatar
-1 votes
2 answers
670 views

How to decide if a global variable is used inside or outside a function in Python?

In Python variables that are created outside of a function are known as global variables. However to create a global variable inside a function (a local variable), you can use the global keyword. My ...
Qubit's user avatar
  • 197
37 votes
10 answers
15k views

What's the difference between a variable and a memory location? [closed]

Recently I've been trying to explain pointers in a visual way, as flashcards. Question 001: This is the drawing of a location in computer memory. Is it true that its address is 0x23452? Why? ...
progner's user avatar
  • 523
1 vote
2 answers
2k views

How to prevent 'global variables' in a big project?

With 'global variables', I mean Variables on namespace level Static data members in classes Static variables in functions In a big C++ project I would like to have a mechanism (like a compiler ...
Borph's user avatar
  • 121
-5 votes
2 answers
217 views

What is the proper way to unspecify an integer's value in C++? [closed]

// Default initialization int i; // i has an unspecified value return i; // Probably 0, but Unreliable i = 5; // i has a specified value i = int();// This will give it a specified value, 0 i = ...
Anon's user avatar
  • 3,613
-1 votes
1 answer
761 views

What is a common name for a module being tested?

When writing unit tests, I want to reduce the cognitive load of the reader as much as possible. One thing I've noticed that bothers me is that the variable names of the thing that is being tested are ...
pascalwhoop's user avatar
5 votes
7 answers
1k views

Is there a programming term that means property or field?

I think this question can span multiple languages, but in C# specifically there is a clear distinction between a field (ex: private int a;) and a property (ex: private int b { get; set; }). While ...
Kyle Delaney's user avatar
0 votes
1 answer
100 views

Variable naming for collaboration between software engineering and data science

There exist lots of discussions on variable naming. However, I would like to address a specific aspect. I am a data scientist and deal with dozens of features/variables/columns — however you may call ...
Xiphias's user avatar
  • 111
45 votes
5 answers
18k views

How do variables in C++ store their type?

If I define a variable of a certain type (which, as far as I know, just allocates data for the content of the variable), how does it keep track of which type of variable it is?
Finn McClusky's user avatar
5 votes
3 answers
12k views

What is the best practice for initializing variables: outside or inside of the constructor?

I try to use the best coding standards/practices, however in all of my googling and classes I have never learned which is proper form for declaring/defining variables like the examples below. I have ...
Paul Gildehaus's user avatar
2 votes
2 answers
424 views

Scala: what has been the desired design consideration for the null instantiation in the example

Or simply asked WHY ? It simply does not seems logical ... if ( null.asInstanceOf[String] == null ) println ("null.asIstanceOf[String] is null") println ("BUT !!!") if ( null.asInstanceOf[...
Yordan Georgiev's user avatar
8 votes
3 answers
699 views

Equal length variable names: tricks or alternatives? [closed]

This might be a super nerdy, OCD-like, silly question, but... I love it when related variables have names of equal length, such that when written below one another, it lines up nicely. Eg: min/max: ...
Martijn Courteaux's user avatar
-1 votes
4 answers
868 views

Sending camelCase code to under_score code

I'm working with JavaScript and PHP right now. My JavaScript uses camelCase while my PHP uses under_score for variable/object/array naming. I often have JavaScript send data to PHP. In fact it's ...
Trevor's user avatar
  • 101
3 votes
3 answers
170 views

Standard Variable nomenclature

I have a written a function and intend to provide an input variable so that when it is true, user-information is printed to the console. If the variable is false the function is 'silent'. Console ...
gatorback's user avatar
  • 227
4 votes
2 answers
1k views

How to name a Boolean variable that represents either of two options?

I'm developing an application with Python. I want to have a Boolean variable that represent whether something is buy or sell but I'm not sure how I should name it. Here are my current ideas: isBuy ...
tgwtdt's user avatar
  • 159
3 votes
2 answers
1k views

Avoiding variables/functions only referenced once

I've heard some developers say that if a variable is only referenced one place, to just replace the reference to it with the value assigned to it. I've also heard developers say if a function is only ...
jinglesthula's user avatar
6 votes
3 answers
6k views

How do you denote a variable in a comment?

Let's say I have the following function in Python: def foo(one, two): return one + two And I want to document it with "adds one to two". However, this is confusing, because I could just mean ...
Pro Q's user avatar
  • 677
3 votes
1 answer
374 views

Should I rename variables that are already constants in my own library?

I'm writing a high level wrapper around the Python socket.socket object. Specifically, I want to do this for IPv4 TCP sockets (though it would be useful to be able to expand the library later with ...
Daniel's user avatar
  • 149
4 votes
1 answer
561 views

Are externs (global variables) ever justifiable?

Under which circumstances would you deem it justifiable to use externs (i.e. global variables)? For example, in a system with 1 given state at a time, would it be appropriate to store this state in ...
Edward's user avatar
  • 51
43 votes
7 answers
9k views

Does it make sense to create blocks just to reduce a variable's scope?

I'm writing a program in Java where at one point I need to load a password for my keystore. Just for fun, I tried to keep my password in Java as short as possible by doing this: //Some code .... ...
Lord Farquaad's user avatar
2 votes
4 answers
2k views

Naming similar variables [closed]

I need few related variables (for example I have the lengths of 3 lines given. I have to say whether they form a triangle). Which variable naming convention is preferable in Java? len0, len1, len2 ...
Md. Abu Nafee Ibna Zahid's user avatar
0 votes
4 answers
405 views

Regarding a variable in C, is an assignment always equivalent to a definition of that variable? [closed]

Is there a difference between defining a variable in C and assigning a value to a variable in C? I know that declaring a variable simply means telling the name and its type like int a. On the other ...
yoyo_fun's user avatar
  • 2,297
13 votes
3 answers
8k views

How are variables stored in a language compiler or interpreter?

Say we set a variable in Python. five = 5 Boom. What I'm wondering is, how is this stored? Does the compiler or interpreter just put it in a variable like so? varname = ["five"] varval = [5] If ...
baranskistad's user avatar
0 votes
2 answers
10k views

Check whether a field has been modified in Java

I've an entity class that the user will construct the object using the setters. This object when passed to another layer, that layer will call the constructChangeDataMap() method to identify the ...
Magesh Kumaar's user avatar
53 votes
15 answers
36k views

Clean Code: Functions with few parameters [closed]

I read the first chapters of Clean Code by Robert C. Martin, and it seems to me it's pretty good, but I have a doubt, in one part it is mentioned that it is good (cognitively) that the functions ...
OiciTrap's user avatar
  • 729
29 votes
3 answers
13k views

Why should I use namedtuple over SimpleNamespace when not using dict, they seem very similar

At one point or another you might come over functions with a lot of arguments. Sometimes it makes sense to combine some of the arguments into super-arguments. I've often done this with dicts, but now ...
André Christoffer Andersen's user avatar
5 votes
2 answers
3k views

What can I infer from someones code when they use direct initialization with Curly Braces as opposed to Parenthese?

Up until now, I have been initializing most of my variables as such: const QString foo("bar"); Which from my newfound understanding, is known as direct initialization. (http://en.cppreference.com/w/...
Anon's user avatar
  • 3,613
1 vote
2 answers
543 views

How do I best store a value with multiple keys?

I need to store two 32-bit numbers in a way that is quickly accessible and as storage space efficient as possible. My keys are a combination of the following two values: port: 0 - 29 vlan: 1 - 4095 ...
stdcerr's user avatar
  • 139

1
2 3 4 5