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
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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.

0
votes
2answers
59 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
300 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
90 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
154 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
257 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 ...
2
votes
2answers
135 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
186 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
51 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
212 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
248 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
490 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
268 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
34 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: ...
8
votes
3answers
1k 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
1k 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 ...
43
votes
15answers
17k 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 ...
2
votes
2answers
1k 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
422 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
227 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
460 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 ...
0
votes
2answers
447 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
624 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
156 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 ...
90
votes
14answers
15k 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
395 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
593 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
189 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
165 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
414 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
380 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
705 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
181 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
118 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
441 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 ...
5
votes
2answers
1k 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
98 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
466 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
221 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
108 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
566 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 ...
1
vote
1answer
1k 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
113 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 ...
2
votes
1answer
68 views

How to compute whether it is guaranteed the variable is set?

Assuming declarations are expressions consider such code: if ((var x = foo()) and (var y = x)) or (var z = bar()) then println(z); end The reference to x is OK, because at this point x has to be ...
47
votes
4answers
9k views

Why do so few languages with a variable-type 'operator' exist?

I mean it in this way: <?php $number1 = 5; // (Type 'Int') $operator1 = +; // (Type non-existent 'Operator') $number2 = 5; // (Type 'Int') $operator2 = *; // (Type non-existent ...
-2
votes
2answers
191 views

How to find all occurrences of a variable within a source code?

The title is pretty self-explanatory. I have a minified JavaScript code (100k+ lines) and would like to find all occurrences of a particular variable so I could rename it to better understand code. Is ...
8
votes
5answers
2k views

Why does Kotlin require type after variable, rather than before? [duplicate]

C, C++, C#, Java, as well as many other statically typed languages have the type before variable like (int a =5, auto c = 4, etc.). Non-statically typed languages (such as Javascript, basic) use var (...
1
vote
1answer
575 views

Best practices for scientific variable naming?

What are some of the conventions you use when naming variables in mathematical/scientific code? I'm looking to establish a set of conventions for an upcoming project. So here's an example formula to ...
0
votes
1answer
337 views

Is there ever a reason to use variable variables in PHP rather than an array? [closed]

Is there any situation where an array is not suitable but a variable variable is? I cannot think of one or find one on any Stack Programmer Q&A. <?php $foo = array(); for($i = 0;$i < 3; $i+...