Questions tagged [language-design]

A tag for questions related to the design of any aspect of programming languages.

1363 questions
52
votes
1 answer

Why are await and async valid variable names?

I was experimenting with how / is interpreted when around different keywords and operators, and found that the following syntax is perfectly legal: // awaiting something that isn't a Promise is fine, it's just strange to do: const foo = await…
52
votes
13 answers

What are practical guidelines for evaluating a language's "Turing Completeness"?

I've read "what-is-turing-complete" and the wikipedia page, but I'm less interested in a formal proof than in the practical implications of requirements for being Turing Complete. What I'm actually trying to decide is if the toy language I've just…
AShelly
  • 34,686
  • 15
  • 91
  • 152
51
votes
7 answers

C# static member "inheritance" - why does this exist at all?

In C#, a superclass's static members are "inherited" into the subclasses scope. For instance: class A { public static int M() { return 1; } } class B : A {} class C : A { public new static int M() { return 2; } } [...] A.M(); //returns 1 B.M();…
Eamon Nerbonne
  • 47,023
  • 20
  • 101
  • 166
51
votes
9 answers

Why don't languages raise errors on integer overflow by default?

In several modern programming languages (including C++, Java, and C#), the language allows integer overflow to occur at runtime without raising any kind of error condition. For example, consider this (contrived) C# method, which does not account for…
Jon Schneider
  • 25,758
  • 23
  • 142
  • 170
50
votes
13 answers

C++ iterators considered harmful?

At the Boost library conference today, Andrei Alexandrescu, author of the book Modern C++ Design and the Loki C++ library, gave a talk titled "Iterators Must Go" (video, slides) about why iterators are bad, and he had a better solution. I tried to…
Unknown
  • 45,913
  • 27
  • 138
  • 182
49
votes
32 answers

Why are many languages case sensitive?

Why are many languages case sensitive? Is it simply a matter of inheritance? C++ is case-sensitive because C is, Java is case-sensitive because C++ is, etc.? Or is there a more pragmatic reason behind it?
Yuvi
  • 4,447
  • 8
  • 35
  • 42
49
votes
4 answers

Why aren't there compiler-generated swap() methods in C++0x?

C++ compilers automatically generate copy constructors and copy-assignment operators. Why not swap too? These days the preferred method for implementing the copy-assignment operator is the copy-and-swap idiom: T& operator=(const T& other) { T…
jamesdlin
  • 81,374
  • 13
  • 159
  • 204
47
votes
5 answers

Where are expressions and constants stored if not in memory?

From C Programming Language by Brian W. Kernighan & operator only applies to objects in memory: variables and array elements. It cannot be applied to expressions, constants or register variables. Where are expressions and constants stored if…
Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411
47
votes
11 answers

Why didn't C have a boolean data type prior to C99?

I realise you can just #define some integers, but why didn't C have a dedicated boolean data type before C99? It's such a common occurence in programming and logic, I don't understand the absense of an explicit type and notation.
xyz
  • 27,223
  • 29
  • 105
  • 125
46
votes
4 answers

Why are there two assignment operators, `<-` and `->` in R?

I know how to use <- and ->, and there are several writeups on the difference between equals assignment & arrow assignment, but I don't know when to prefer -> over <-. It seems the community has coalesced around using <- for assignment. Neither the…
Haleemur Ali
  • 26,718
  • 5
  • 61
  • 85
44
votes
1 answer

Why isn't __new__ in Python new-style classes a class method?

The Changelog for Python 2.2 (where new-style classes were introduced) says the following about the __new__ function: __new__ is a static method, not a class method. I initially thought it would have to be a class method, and that's why I added the…
Dolda2000
  • 25,216
  • 4
  • 51
  • 92
44
votes
3 answers

Why was IEnumerable made covariant in C# 4?

In earlier versions of C# IEnumerable was defined like this: public interface IEnumerable : IEnumerable Since C# 4 the definition is: public interface IEnumerable : IEnumerable Is it just to make the annoying casts in LINQ expressions…
soc
  • 27,983
  • 20
  • 111
  • 215
44
votes
1 answer

Why do C++ templates use the angle bracket syntax?

The titular question refers to the design decisions in the C++ standard that introduced templates around 1990. Why did the designers use <> (angle brackets) instead of, say, () (round brackets)? Doing so would have saved lots of programmers from…
shuhalo
  • 5,732
  • 12
  • 43
  • 60
44
votes
6 answers

I don't understand why we need the 'new' keyword

I am new to C#, from a C++ background. In C++ you can do this: class MyClass{ .... }; int main() { MyClass object; // this will create object in memory MyClass* object = new MyClass(); // this does same thing } Whereas, in C#: class…
user6528398
  • 491
  • 1
  • 4
  • 4
44
votes
2 answers

Why did Matz choose to make Strings mutable by default in Ruby?

It's the reverse of this question: Why can't strings be mutable in Java and .NET? Was this choice made in Ruby only because operations (appends and such) are efficient on mutable strings, or was there some other reason? (If it's only efficiency,…
Seth Tisue
  • 29,985
  • 11
  • 82
  • 149