Questions involving the design and structure of programming languages.
Questions tagged [language-design]
484 questions
178
votes
22 answers
Are null references really a bad thing?
I've heard it said that the inclusion of null references in programming languages is the "billion dollar mistake". But why? Sure, they can cause NullReferenceExceptions, but so what? Any element of the language can be a source of errors if used…

Tim Goodman
- 2,644
- 2
- 28
- 25
133
votes
14 answers
Why do most programming languages only support returning a single value from a function?
Is there a reason why functions in most(?) programming languages are designed to support any number of input parameters but only one return value?
In most languages, it is possible to "work around" that limitation, e.g. by using out-parameters,…

M4N
- 1,447
- 3
- 12
- 10
124
votes
15 answers
Why is 0 false?
This question may sound dumb, but why does 0 evaluates to false and any other [integer] value to true is most of programming languages?
String comparison
Since the question seems a little bit too simple, I will explain myself a little bit more:…

Morwenn
- 1,736
- 2
- 13
- 22
111
votes
12 answers
I've been told that Exceptions should only be used in exceptional cases. How do I know if my case is exceptional?
My specific case here is that the user can pass in a string into the application, the application parses it and assigns it to structured objects. Sometimes the user may type in something invalid. For example, their input may describe a person but…

Daniel Kaplan
- 6,776
- 5
- 32
- 46
109
votes
6 answers
Why is XML called a "language" exactly?
I've been wondering why XML has an L in its name.
By itself, XML doesn't "do" anything. It's just a data storage format, not a language! Languages "do" things.
The way you get XML to "do" stuff, to turn it into a language proper, is to add xmlns…

Mr Lister
- 1,599
- 3
- 12
- 18
102
votes
9 answers
Why did BASIC use line numbers?
Why did old BASICs (and maybe other languages) use line numbers as part of the source code?
I mean, what problems did it (try to) solve?

DerMike
- 1,053
- 2
- 7
- 9
102
votes
12 answers
Should I use a parser generator or should I roll my own custom lexer and parser code?
What specific advantages and disadvantages of each way to working on a programming language grammar?
Why/When should I roll my own? Why/When should I use a generator?

Maniero
- 10,826
- 14
- 80
- 133
91
votes
11 answers
Why F#, Rust and others use Option type instead of nullable types like C# 8 or TypeScript?
AFAIK, Option type will have runtime overhead, while nullable types won't, because Option time is an enum (consuming memory).
Why not just mark optional references as optional, then the compiler can follow code execution and find whenever it can't…

Chayim Friedman
- 1,138
- 1
- 6
- 14
91
votes
10 answers
If null is bad, why do modern languages implement it?
I'm sure designers of languages like Java or C# knew issues related to existence of null references (see Are null references really a bad thing?). Also implementing an option type isn't really much more complex than null references.
Why did they…

zduny
- 2,623
- 2
- 19
- 24
88
votes
63 answers
What features would you like to have in PHP?
Since it's the holiday season now and everybody's making wishes, I wonder - which language features you would wish PHP would have added? I am interested in some practical suggestions/wishes for the language. By practical I mean:
Something that can…

StasM
- 3,377
- 2
- 23
- 28
88
votes
11 answers
Did the developers of Java consciously abandon RAII?
As a long-time C# programmer, I have recently come to learn more about the advantages of Resource Acquisition Is Initialization (RAII). In particular, I have discovered that the C# idiom:
using (var dbConn = new DbConnection(connStr)) {
// do…

JoelFan
- 7,025
- 4
- 38
- 53
85
votes
11 answers
Why is String immutable in Java?
I couldn't understand the reason of it. I always use String class like other developers, but when I modify the value of it, new instance of String created.
What might be the reason of immutability for String class in Java?
I know there are some…

yfklon
- 1,752
- 4
- 19
- 30
83
votes
6 answers
Why does the type go after the variable name in modern programming languages?
Why is it that in nearly all modern programming languages (Go, Rust, Kotlin, Swift, Scala, Nim, even Python last version) types always come after the variable name in the variable declaration, and not before?
Why x: int = 42 and not int x = 42?
Is…

Andre Polykanine
- 957
- 1
- 6
- 6
77
votes
14 answers
Why is Arithmetic Overflow ignored?
Ever tried to sum up all numbers from 1 to 2,000,000 in your favorite programming language? The result is easy to calculate manually: 2,000,001,000,000, which some 900 times larger than the maximum value of an unsigned 32bit integer.
C# prints out…

Bernhard Hiller
- 1,953
- 1
- 12
- 17
76
votes
9 answers
Why use partial classes?
In my understanding, the partial keyword does nothing but allow a class to be split between several source files. Is there any reason to do this other than for code organization? I've seen it used for that in generated UI classes.
It seems a poor…

Michael K
- 15,539
- 9
- 61
- 93