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.

learn more… | top users | synonyms

-1
votes
2answers
153 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
70 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
135 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
221 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: ...
5
votes
1answer
105 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 ...
1
vote
1answer
39 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-...
-4
votes
2answers
147 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 ...
1
vote
5answers
406 views

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

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
128 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
122 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+...
2
votes
2answers
219 views

Avoid This Pointer

PROBLEM: this points to different instances at different stages of execution (as it should). But it is not always obvious which instance is that. On the other hand we could minimize the use of this, ...
1
vote
2answers
117 views

What is the use case for shadowing variables?

One of the things the coffeescript programming language is criticized for is its treatment of variable declarations and scope (example). The answers to this question (and the blog I linked to above) ...
-3
votes
3answers
105 views

Best way to handle variables used in a for loop? [duplicate]

From previous experience, I had always thought that, if you are going to use variables inside of a for loop, it was much better to declare them outside of the loop vs. inside the loop itself. I ...
-4
votes
2answers
76 views

Rationale for modern languages implement changeable global variables [closed]

Common sense seems to be that usage of global variables is bad, in particular if they are used as real variables (i.e. changing state; e.g. Why is Global State so Evil?). How does it come then, that ...
2
votes
1answer
283 views

What is internal state and is there a difference between state and internal state

Ok, this question has been asked before, but it's still not clear to me. What exactly is internal state? So far state is clear to me: Functions contain behavior, variables have state, values don't. ...
37
votes
9answers
3k views

Using compound statements (“{” … “}” blocks) to enforce variable locality [duplicate]

Introduction Many "C-like" programming languages use compound statements (code blocks specified with "{" and "}") to define a variables scope. Here is a simple example. for (int i = 0; i < 100; +...
1
vote
2answers
362 views

Should I declare variables at the top of the function for reasons other than the scope rules?

In JavaScript, one should declare all variables at the beginning of the function to mitigate the risk of mistakes related to the fact that the scope of variables is a function. The following code ...
-3
votes
1answer
187 views

grouping variables into a system in C? [closed]

Within C, say I have a number of variables, floats, integers etc, is there a way that I can group them all into one object, lets call it a system, and then create N copies of such an object. Further, ...
2
votes
1answer
221 views

Patterns for sharing context variables between functions

I am looking for ways of passing around a set of contextual variables that are required by functions. As a Python programmer, right now I can see three ways of solving the problem: passing them ...
4
votes
5answers
381 views

What was the reason for the creation of boolean variables?

I found out that some languages like C don't have support for boolean variables and programmers use integers with values of 0 and 1 instead. Is there any specific reason why some languages moved away ...
0
votes
2answers
132 views

The correct way of declaring & instantiating variables ( Javascript ) [duplicate]

I have seen other peoples code and each person has a different way of declaring variables. And I have been told by quite a few people that declaring variables in the Global Scope is wrong. My ...
0
votes
1answer
56 views

Dealing with data containing integer overflow, rollover

I am writing a small matlab function to analyze data from a laser probe. The data to be analyzed is basically: x-data: Position. y-data: Laser (light) intensity. ...
1
vote
1answer
100 views

Best practices for tracking multiple pieces of data in a program

I have a project in C (don't ask why but it needs to be in C), where I need to track multiple pieces of data and commands for different modules. Some actions that the program will take depend on the ...
2
votes
4answers
364 views

Should I check parameter before using it in methods? [duplicate]

I'm going to build some public PHP packages, Following standards is a priority for me. PHP lets users call methods even if they don't pass required parameters to it. My question. Should I check ...
7
votes
4answers
1k views

Is the use of one-letter variables encouraged? [closed]

Is the use of one-letter variables encouraged in Java? In code snippets or tutorials, you often see them. I cannot imagine using them is encouraged because it makes the code relatively harder to read ...
-2
votes
1answer
129 views

How to name variables without plural in a for-each loop? [closed]

How do you name loop variables when the list item is named after something without a plural? For instance (in python): [x for x in sheep]. x is not a great name, but sheep have/has no plural that ...
2
votes
3answers
915 views

In C++, should I ever declare a local variable in the corresponding header?

So for example, I create a class with two functions: foo.h class foo { public: foo(); void bar(); void ey(); bool m_memberBool; bool localBool; // ??? Should I put this here? }; ...
2
votes
1answer
191 views

Python beginner question with Assigning Variables

Coming from C# and now getting my hands dirty with Python. From what I understand, Python is strongly typed: http://stackoverflow.com/questions/11328920/is-python-strongly-typed As stated in the ...
-1
votes
1answer
106 views

How to make variables inherent to an object or system [duplicate]

How can one make variables inherent to an object or system? For example, when creating a web browser, each option that is created for the user to have control over (i.e. how a window opens, if ...
2
votes
0answers
669 views

Var assignment in sequence diagram

I am trying to represent the function below (PHP function/Symfony2) as a sequence diagram using UML 2.0 and Visual Paradigm: private function getVeevaHcpSync($request, $action, $case) { ...
1
vote
5answers
740 views

Are there too many parameters in this constructor? [duplicate]

Check this out: public function __construct( \Magento\Framework\Model\Context $context, \Magento\Framework\View\DesignInterface $design, \Magento\Framework\Registry $registry, ...
0
votes
5answers
539 views

Is it bad form to use the same variable name in different scopes?

Say you have some basic code where similar operations will take place in nearby lexical scopes. Take for example some simple pseudo code: variable = "foo" # Do something with variable if (True) { ...
2
votes
3answers
4k views

What is the difference between a variable and a parameter? [closed]

Its a conceptual question. But I would like to use the right term at the right place. That is why I would like to read some other views on this.
0
votes
1answer
2k views

Python: Faster to use global variable or pass as arguments to a function? [duplicate]

Hey so i was wondering which is the more efficient way, or better practice to do in this situation. 1, def function(): global number number += 2 Or 2, def function(number): return ...
7
votes
2answers
632 views

What is best practice to handle whitespaces when letting the user edit the configuration, the name=value pairs?

For instance, you let the user define the notorious path variable. How do you interpret apppath = C:\Program Files\App? This looks like a programming language adopted practice to ignore the white ...
3
votes
1answer
106 views

Creating variables in methods/functions

In how far do we create variables in our methods or functions? Do we only create one when we're using the result of the variable more then one time like this? function someFunction(SomeClass $...
13
votes
5answers
4k views

Why is *declaration* of data and functions necessary in C language, when the definition is written at the end of the source code?

Consider the following "C" code: #include<stdio.h> main() { printf("func:%d",Func_i()); } Func_i() { int i=3; return i; } Func_i() is defined at the end of the source code and ...
19
votes
4answers
3k views

Why do we have to mention the data type of the variable in C

Usually in C, we have to tell the computer the type of data in variable declaration. E.g. in the following program, I want to print the sum of two floating point numbers X and Y. #include<stdio.h&...
1
vote
3answers
250 views

Member variables vs. State Varaibels? Are they the same? [closed]

I am learning that member variables are to hold the state of an object? Is it their recommended usage? Are all member variables state variables too? or state variables have specific definition and ...
2
votes
4answers
412 views

Overwriting and returning the value of the argument used as conditional of an if statement, inside the same if statement

A simplified example: function logTheColor (color){ if(color == "red"){ color = "The color is red " } else if (color == "yellow") { color = "The color is yellow " } else { ...
0
votes
2answers
382 views

Prime symbol in Python variable name

So I'm a terrible person and I want to name a variable in my mathy-python3 code s′ (that's a prime symbol). I was under the impression Unicode literals work as identifiers in Python 3, which is why ...
0
votes
1answer
380 views

Is there a way to prevent variables from changing their type in Python?

It is useful to have the interpreter derive the type of a variable automatically. This on its own is similar to the auto keyword in C++11. However, in Python variables can change their type after ...
0
votes
1answer
75 views

Should instance variables be bound to the instance right in the beginning of the method they are created in?

A common problem for me - and it's not really a problem, but somehow I again and again ask myself, what is the normal way to handle this - is that there is a method and within this method a couple of ...
0
votes
1answer
97 views

Why does this function work even though the vars are different

$inumber1 = 10; $inumber2 = 20; function add($number1, $number2) { echo $number1 + $number2; } add($inumber1, $inumber2); I'm learning PHP coding for the first time and I'm ...
-2
votes
2answers
160 views

php make dollar optional [closed]

Is there any reason the PHP language could not be updated in a future version to make the $ prefix on variable names optional? Reasons that would break existing code? I'm thinking it would still be ...
4
votes
6answers
2k views

Should I store x,y coordinates as an array, a class object, or two variables?

I have a MyObject which has an x and y coordinate. as far as I can see, I can store it in three ways: class MyObject: def __init__(self, x, y): self.x = x self.y = y class ...
1
vote
2answers
179 views

Should I sacrifice code succintness to ensure the narrowest variable scope? [duplicate]

In many languages (e.g. both Perl and Java - which are the two languages I work most with) it is possible to narrow the scope of local variables by declaring them within a block. Although it adds ...
0
votes
5answers
750 views

Representation of a question mark in variable names [closed]

I once in my childhood read a SF story in which it was assumed that the capital letter 'P' would be a good representation for a question mark, if you cannot use that character directly, eg. in ...
5
votes
2answers
2k views

Why to declare a String (as final) and then use it?

In a typical spring mvc validator class, while inserting an errorCode value in the Errors object, what difference does it make between using a String (props.somefield.req) like so errors.rejectValue("...