A tag for questions related to the design of any aspect of programming languages.
Questions tagged [language-design]
1363 questions
195
votes
5 answers
Why is an array not assignable to Iterable?
with Java5 we can write:
Foo[] foos = ...
for (Foo foo : foos)
or just using an Iterable in the for loop. This is very handy.
However you can't write a generic method for iterable like this:
public void bar(Iterable foos) { .. }
and calling…

dfa
- 114,442
- 31
- 189
- 228
192
votes
21 answers
Why is there no multiple inheritance in Java, but implementing multiple interfaces is allowed?
Java doesn't allow multiple inheritance, but it allows implementing multiple interfaces. Why?

abson
- 9,148
- 17
- 50
- 69
185
votes
13 answers
When someone writes a new programming language, what do they write it IN?
I am dabbling in PHP and getting my feet wet browsing SO, and feel compelled to ask a question that I've been wondering about for years:
When you write an entirely new programming language, what do you write it in?
It's to me a perplexing chicken &…

Drew
- 6,208
- 10
- 45
- 68
182
votes
6 answers
Why doesn't Java allow generic subclasses of Throwable?
According to the Java Language Sepecification, 3rd edition:
It is a compile-time error if a generic class is a direct or indirect subclass of Throwable.
I wish to understand why this decision has been made. What's wrong with generic…

Hosam Aly
- 41,555
- 36
- 141
- 182
180
votes
15 answers
What does void mean in C, C++, and C#?
Looking to get the fundamentals on where the term "void" comes from, and why it is called void. The intention of the question is to assist someone who has no C experience, and is suddenly looking at a C-based codebase.

Nick Katsivelos
- 5,060
- 4
- 20
- 11
170
votes
3 answers
Why was the statement (j++); forbidden?
The following code is wrong (see it on ideone):
public class Test
{
public static void Main()
{
int j = 5;
(j++); // if we remove the "(" and ")" then this compiles fine.
}
}
error CS0201: Only assignment, call,…

user10607
- 3,011
- 4
- 24
- 31
167
votes
4 answers
Why is there "data" and "newtype" in Haskell?
It seems that a newtype definition is just a data definition that obeys some restrictions (e.g., only one constructor), and that due to these restrictions the runtime system can handle newtypes more efficiently. And the handling of pattern matching…

martingw
- 4,153
- 3
- 21
- 26
165
votes
28 answers
Why aren't variables declared in "try" in scope in "catch" or "finally"?
In C# and in Java (and possibly other languages as well), variables declared in a "try" block are not in scope in the corresponding "catch" or "finally" blocks. For example, the following code does not compile:
try {
String s = "test";
// (more…

Jon Schneider
- 25,758
- 23
- 142
- 170
163
votes
24 answers
Why can't variable names start with numbers?
I was working with a new C++ developer a while back when he asked the question: "Why can't variable names start with numbers?"
I couldn't come up with an answer except that some numbers can have text in them (123456L, 123456U) and that wouldn't be…

Jeremiah
- 5,386
- 9
- 38
- 45
161
votes
8 answers
Why are C++ inline functions in the header?
NB This is not a question about how to use inline functions or how they work, more why they are done the way they are.
The declaration of a class member function does not need to define a function as inline, it is only the actual implementation of…

thecoshman
- 8,394
- 8
- 55
- 77
157
votes
10 answers
Why are private fields private to the type, not the instance?
In C# (and many other languages) it's perfectly legitimate to access private fields of other instances of the same type. For example:
public class Foo
{
private bool aBool;
public void DoBar(Foo anotherFoo)
{
if…

RichK
- 11,318
- 6
- 35
- 49
156
votes
9 answers
Why was the switch statement designed to need a break?
Given a simple switch statement
switch (int)
{
case 1 :
{
printf("1\n");
break;
}
case 2 :
{
printf("2\n");
}
case 3 :
{
printf("3\n");
}
}
The absence of a break statement in…

EvilTeach
- 28,120
- 21
- 85
- 141
149
votes
8 answers
Why does Ruby have both private and protected methods?
Before I read this article, I thought access control in Ruby worked like this:
public - can be accessed by any object (e.g. Obj.new.public_method)
protected - can only be accessed from within the object itself, as well as any subclasses
private -…

Kyle Slattery
- 33,318
- 9
- 32
- 36
149
votes
9 answers
Why doesn't String switch statement support a null case?
I am just wondering why the Java 7 switch statement does not support a null case and instead throws NullPointerException? See the commented line below (example taken from the Java Tutorials article on switch):
{
String month = null;
switch…

Prashant Bhate
- 10,907
- 7
- 47
- 82
144
votes
4 answers
Why do local variables require initialization, but fields do not?
If I create a bool within my class, just something like bool check, it defaults to false.
When I create the same bool within my method, bool check(instead of within the class), i get an error "use of unassigned local variable check". Why?

nachime
- 1,826
- 4
- 16
- 25