Questions tagged [variables]

For questions about variables, named storage locations that hold a value, which can be changed during the execution of a program.

Filter by
Sorted by
Tagged with
20 votes
6 answers

Why do some languages have both immutable "variables" and constants?

Some programming languages (Rust is one I can think of off the top of my head) provides mechanisms to have immutable variables but they also have constants. Isn't an immutable variable just a constant?...
QAH's user avatar
  • 311
8 votes
4 answers

Why are mixed declarations more challenging to implement than forcing all declarations to be at the top of a scope?

C89 had a requirement that all declarations must appear at the top of the scope before any statements: ...
user16217248's user avatar
  • 7,285
1 vote
1 answer

How does languages distinguish passing a parameter by value and reference, especially with non-parameter direct initializations in consideration?

Background What I want is to make the behaviors of the following two pieces of code identical: specifier x = getX(); doSomething(x); ...
user23013's user avatar
  • 2,010
6 votes
1 answer

What is the difference between having an auto type and having dynamic typing?

In C++, you can define variables with auto instead of giving it a default type such as int. Like this (where ...
Redz's user avatar
  • 900
11 votes
6 answers

Early binding, mutual recursion, closures. Can I have all three?

Take this Python snippet of two functions that are mutually recursive and form closures: ...
BoppreH's user avatar
  • 1,401
5 votes
3 answers

Types and variables in a different namespace

What would it take to design a language that permitted construct such as below? int int = 10; Such a language would need to be able to infer contextually whether a ...
user16217248's user avatar
  • 7,285
7 votes
9 answers

What syntax options exist for avoiding variable names colliding with keywords and built-ins?

Preamble As you probably know, keywords are special reserved words in a programming language that have specific meanings and purposes and can’t be used for anything but those specific purposes. An ...
necklace's user avatar
6 votes
2 answers

Why do newer languages allow implicit variable declarations?

For me, one of the best things to happen to FORTRAN was the introduction of the LOGICAL*1 type. I quickly discovered that putting ...
Ray Butterworth's user avatar
0 votes
2 answers

How to store variables in an interpreted language? [closed]

Say I'm making an interpreted language. What's the best way for me to store variable name/value pairs (or type/name/value triplets in the case of languages with typing)?
lyxal's user avatar
  • 1,747