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
1 vote
3 answers
205 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 ...
user avatar
31 votes
6 answers
7k 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 ...
user avatar
  • 965
16 votes
5 answers
6k 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() { ...
user avatar
  • 190
4 votes
2 answers
2k 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 ...
user avatar
  • 75
0 votes
1 answer
459 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 ...
user avatar
0 votes
1 answer
283 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 ...
user avatar
  • 197
1 vote
1 answer
97 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 ...
user avatar
  • 965
-4 votes
3 answers
248 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 ...
user avatar
3 votes
3 answers
449 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 ...
user avatar
  • 141
2 votes
5 answers
3k 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 ...
user avatar
  • 5,301
-2 votes
1 answer
73 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), ...
user avatar
  • 17
-3 votes
1 answer
96 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 ...
user avatar
-2 votes
2 answers
77 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 ...
user avatar
  • 23
-1 votes
1 answer
121 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 ...
user avatar
  • 115
2 votes
3 answers
129 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, ...
user avatar
1 vote
3 answers
2k 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 ...
user avatar
-1 votes
2 answers
176 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 ...
user avatar
38 votes
10 answers
13k 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? ...
user avatar
  • 533
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 ...
user avatar
  • 121
-5 votes
2 answers
187 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 = ...
user avatar
  • 3,379
-1 votes
1 answer
294 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 ...
user avatar
4 votes
6 answers
839 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 ...
user avatar
0 votes
1 answer
78 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 ...
user avatar
  • 111
45 votes
5 answers
16k 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?
user avatar
5 votes
3 answers
8k 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 ...
user avatar
2 votes
2 answers
334 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[...
user avatar
8 votes
3 answers
425 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: ...
user avatar
-1 votes
4 answers
697 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 ...
user avatar
3 votes
3 answers
164 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 ...
user avatar
  • 207
3 votes
2 answers
856 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 ...
user avatar
  • 141
3 votes
2 answers
473 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 ...
user avatar
4 votes
3 answers
3k 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 ...
user avatar
  • 657
3 votes
1 answer
276 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 ...
user avatar
  • 149
4 votes
1 answer
388 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 ...
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 .... ...
user avatar
2 votes
4 answers
1k 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 ...
user avatar
0 votes
4 answers
330 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 ...
user avatar
  • 2,227
13 votes
3 answers
6k 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 ...
user avatar
0 votes
2 answers
8k 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 ...
user avatar
53 votes
15 answers
34k 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 ...
user avatar
  • 729
20 votes
3 answers
10k views

In Python 3.4+, 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 ...
user avatar
5 votes
2 answers
2k 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/...
user avatar
  • 3,379
1 vote
2 answers
405 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 ...
user avatar
  • 139
-2 votes
1 answer
2k views

How complex a program can be without variables? [closed]

Theoretically, is it possible to write programs without using variables? What will the most complex program look like? Does the answer vary depending on the language? Would you be able to use ...
user avatar
  • 185
15 votes
2 answers
5k views

Complex variable name with plural nouns [closed]

It's a language agnostic question. Seems like a common problem, but I can't find answer anywhere. I need to pick a name for a variable to hold the values of one attribute of a list of objects, and I ...
user avatar
2 votes
3 answers
2k views

How to DRY refactor several similar functions?

I was assigned a refactoring. We have several modules having similar functions with some differences. My task is to extract common portions of code for DRY principle. I am a little lost how to do it....
user avatar
  • 722
0 votes
2 answers
199 views

Is this a constant or a variable?

I was wondering if a value that is defined by the user at the start of a program, and not modified by the program, is considered a constant or a variable. I know that a constant is a word/letter that ...
user avatar
  • 111
103 votes
13 answers
23k views

Should we eliminate local variables if we can?

For example, to keep a CPU on in Android, I can use code like this: PowerManager powerManager = (PowerManager)getSystemService(POWER_SERVICE); WakeLock wakeLock = powerManager.newWakeLock(...
user avatar
  • 5,705
1 vote
2 answers
1k views

Using "intermediate variables" to abbreviate long dict entries

Sometimes I come across the situation that I have some data in a nested dict with rather long key-names (sometimes unavoidable for one reason or another). some_dict = {'not_too_short_key_one': {'...
user avatar
-1 votes
2 answers
3k views

When do we say that a variable is undefined? [closed]

In C, When do we say that a variable is undefined ? When it is not present in the complete code or in a function scope ?
user avatar
  • 109