Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

-3
votes
0answers
72 views

Encoding information in object names

I work with a system that has some lists of objects that can have arbitrary, user defined names, and each object has some properties that can be configured. In the IDE for the system the objects are ...
0
votes
0answers
14 views

Heroku (12 factor) large configuration in environment variables?

In here we're deploying applications on Heroku. I'm talking here about a database-connected and CRM-connected application. This application has a pipeline, with a "staging" stage and a "production" ...
0
votes
0answers
73 views

are dynamic variable names for readability a good practice

So recently I've been developing some simple stuff in C# to process data in an excel spreadsheet. I've had to create a nested map construct to represent the sheet of the excel document I want to work ...
-1
votes
1answer
51 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 ...
41
votes
5answers
9k 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?
2
votes
3answers
234 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 ...
0
votes
2answers
76 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[...
6
votes
3answers
305 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
98 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
158 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 ...
2
votes
1answer
325 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
139 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 ...
2
votes
3answers
218 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 ...
0
votes
0answers
60 views

Variable/config/secrets management options

I'm currently transitioning my app from Heroku to a more custom environment (to scale beyond what Heroku can offer) and I'm looking for a solution for configuration and environment variables. Here is ...
3
votes
1answer
216 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 ...
3
votes
1answer
253 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 ...
35
votes
7answers
6k 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
509 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
276 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 ...
0
votes
0answers
35 views

Best practice on naming an array (i.e. an array of image file names) [duplicate]

I have an array of image file names. e.g: [ 'a/b/foo.jpg' 'c/d/bar.jpg', 'example.png' ] However, I am confused as to what the best practice of naming this array. Would it be: ...
9
votes
3answers
2k 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
2k 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 ...
47
votes
15answers
19k 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 ...
7
votes
2answers
2k 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 ...
3
votes
2answers
575 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
238 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 ...
-3
votes
1answer
512 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 ...
1
vote
2answers
663 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 ...
1
vote
3answers
837 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
157 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 ...
91
votes
14answers
16k 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(...
0
votes
2answers
542 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
975 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
193 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
184 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
448 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
487 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
926 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 ...
1
vote
2answers
216 views

How to name variables that clash with functions?

As an example, in Python I have a lowest_prime_factor function which does it exactly what it says it does. Then, in another function, I need to call this function and store it. In another language ...
0
votes
2answers
120 views

Variable can't hold str() method information with “pure” word in brackets… why?

I've recently bumped into string methods and mainly str() method caught my interest because, it makes string out of every type of data? integers, booleans and so on. And if you want, they can be ...
-2
votes
2answers
561 views

C++ Which of the following is a better singleton pattern approach?

I'm now stuck in the server I am programming, simply because I do not seem to find a good and realiable way to handle my "single object" classes, I've attempted the Singleton pattern but it is just ...
7
votes
2answers
2k views

Is there a convention for returning multiple items?

In Python specifically (I don't know if this generalizes) is there a "best" way to return multiple items from a function? def func1(): return a,b #equivalent to (a,b) def func2(): return[a,...
0
votes
1answer
104 views

In scala is it acceptable to have id variables written as `_id` instead of the regular camel case notation?

In Scala is it acceptable to have id variables written as _id instead of the regular camel case notation? In the code most variables respect the camel case notation. However for variables referring ...
2
votes
3answers
607 views

Including the type name in a variable name

Abstract: Is it acceptable to include the type name in the variable name? My scenario: I am working with C# MVVM, and I have a lot of ICommand properties in my ViewModel, named various things like ...
0
votes
6answers
313 views

Dealing with a variable that is a number, but has greater meaning? [closed]

I've been working on some embedded code that handles a Bluetooth Low Energy (BLE) radio. BLE has 40 channels, numbered 0 through 39. One function for the radio driver takes in the channel and sets ...
-1
votes
2answers
226 views

One Word for Functions, Variables, and Objects

Is there a single word that can describe JavaScript functions, variables, and objects? I was thinking "entities", but that word is usually used to describe the mapping between objects and a database. ...
0
votes
1answer
184 views

Why adding positive values in Java or C# sometimes result in a negative value?

I was playing around with variables in Java. public class Hello { public static void main(String[] args) { byte byteV = 127; short shortV = Short.MAX_VALUE; int intV = ...
0
votes
3answers
675 views

A few questions about initializing variables

I'm in an introductory programming class and we're only in lesson two, so try to keep terminology simple, ha. I'm a bit confused about when you need to and when you don't need to initialize a ...
2
votes
1answer
2k views

Why Variables in Python Are Different from Other Programming Languages? [closed]

According to my understanding, a variable in Python is: A name that refers to a value stored in the computer memory, and it's like a label on a box. but in other programming languages it is: A ...
5
votes
1answer
114 views

What is the impact of re-defining a dynamic type variable (such as in PHP)?

PHP variables are dynamic in type so I can do: $x = 'hello world!'; $x = strlen($x); Sometimes this is trivial and I could save many lines of code, but it reduces clarity. I'm using a text ...