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
1answer
246 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 ...
1
vote
1answer
85 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 ...
-4
votes
3answers
85 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 ...
3
votes
3answers
240 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 ...
2
votes
5answers
2k 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 ...
-2
votes
1answer
58 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), ...
-3
votes
1answer
62 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 ...
-2
votes
2answers
70 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 ...
-1
votes
1answer
95 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 ...
2
votes
3answers
125 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, ...
1
vote
3answers
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 ...
-1
votes
2answers
135 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 ...
38
votes
10answers
12k 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? ...
0
votes
2answers
1k 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 ...
-5
votes
2answers
179 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 = ...
-1
votes
1answer
212 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 ...
4
votes
6answers
778 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 ...
0
votes
1answer
74 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 ...
45
votes
5answers
15k 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?
5
votes
3answers
7k 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 ...
1
vote
2answers
289 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[...
8
votes
3answers
397 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: ...
-1
votes
4answers
636 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 ...
3
votes
3answers
163 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 ...
3
votes
2answers
707 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 ...
3
votes
2answers
378 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 ...
4
votes
3answers
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 ...
3
votes
1answer
250 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 ...
4
votes
1answer
315 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 ...
43
votes
7answers
8k 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 .... ...
2
votes
4answers
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 ...
0
votes
4answers
325 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 ...
10
votes
3answers
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 ...
0
votes
2answers
7k 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 ...
52
votes
15answers
33k 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 ...
17
votes
3answers
9k 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 ...
5
votes
2answers
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/...
1
vote
2answers
387 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 ...
-2
votes
1answer
1k 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 ...
14
votes
2answers
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 ...
2
votes
3answers
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....
0
votes
2answers
185 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 ...
101
votes
13answers
22k 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(...
1
vote
2answers
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': {'...
-1
votes
2answers
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 ?
1
vote
1answer
223 views

Is using uncommon words as descriptive variable names acceptable?

I am implementing a finite state machine in Python 2.7, and I am considering using an English word that I don't commonly see in code: "stimulus". I have a transition function that accepts some kind of ...
-2
votes
1answer
322 views

How does accessing class level variables in java work?

I'm doing my third online course in learning java because I couldn't get over how to even start a project from scratch. There was a lesson in this new course that made me ask this question of the code ...
5
votes
1answer
480 views

How is it possible to program using only immutable / "read-only" variables?

I believe there are languages where all names with associated values cannot have their associated values changed. An example would be a language where all names behave like a does in the following C ...
0
votes
1answer
1k views

Is declaring 'const' variable a good programming practice? [duplicate]

Is it a good practice to declare all the variables in my program as a const variable? eg:- private int myAge = 20; private const int Age = 20; Now, from the above example, which one is a ...
-2
votes
1answer
2k views

Global variable or parameter?

Is it correct that homeitem should be declared inside the OnLoad method and overgiven to all the render methods instead of just declaring it as a global variable and accessing it by all the render ...