A tag for questions related to the design of any aspect of programming languages.
Questions tagged [language-design]
1363 questions
32
votes
7 answers
Advantages of Java's enum over the old "Typesafe Enum" pattern?
In Java prior to JDK1.5, the "Typesafe Enum" pattern was the usual way to implement a type that can only take a finite number of values:
public class Suit {
private final String name;
public static final Suit CLUBS =new Suit("clubs");
…

sleske
- 81,358
- 34
- 189
- 227
32
votes
6 answers
Why are regular expressions greedy by default?
It seems that this is a huge source of confusion for beginners writing regular expressions, can cause hidden performance problems, and it would seem that a typical use case would be non-greedy.
Is this just for legacy reasons (it was how it was…

Yishai
- 90,445
- 31
- 189
- 263
32
votes
3 answers
Why do the older C language specs require function-local variables to be declared up-front?
In the C programming language, all of the language revisions I have worked with enforced up-front variable declarations before any non-declarative/assignative expressions would be evaluated. C++ seems to have waived this requirement from all…

Daniel Green
- 634
- 5
- 14
31
votes
2 answers
Scala's .type and Java's .class literal
I wonder from a language design perspective why Scala has removed Java's class literal (e. g. String.class) and replaced it with classOf[String], but has then added a "type literal" with its Singletons like Singleton.type instead of something like…

soc
- 27,983
- 20
- 111
- 215
31
votes
5 answers
What is the rationale for not having static constructor in C++?
What is the rationale for not having static constructor in C++?
If it were allowed, we would be initializing all the static members in it, at one place in a very organized way, as:
//illegal C++
class sample
{
public:
static int some_integer;
…

Nawaz
- 353,942
- 115
- 666
- 851
31
votes
2 answers
How to implement Swift-like enums with associated values in JavaScript?
The Swift language has a fantastic enum support. Not only can one define a standard enum with cases, but cases can have optional values "associated to them."
For example, taken from the Swift docs:
enum Barcode {
case UPCA(Int, Int, Int, Int)
…

Janum Trivedi
- 1,660
- 2
- 16
- 24
31
votes
13 answers
Suggestions on syntax to express mathematical formula concisely
I am developing functional domain specific embedded language within C++ to translate formulas into working code as concisely and accurately as possible.
I posted a prototype in the comments, it is about two hundred lines long.
Right now my language…

Anycorn
- 50,217
- 42
- 167
- 261
31
votes
6 answers
Java generic methods in generics classes
If you create a generic class in Java (the class has generic type parameters), can you use generic methods (the method takes generic type parameters)?
Consider the following example:
public class MyClass {
public K doSomething(K k){
return…

amaidment
- 6,942
- 5
- 52
- 88
31
votes
8 answers
What makes PHP slower than Java or C#?
This is something I've always wondered: Why is PHP slower than Java or C#, if all 3 of these languages get compiled down to bytecode and then executed from there? I know that normally PHP recompiles each file with each request, but even when you…

ryeguy
- 65,519
- 58
- 198
- 260
30
votes
24 answers
Why do most programming languages only have binary equality comparison operators?
In natural languages, we would say "some color is a primary color if the color is red, blue, or yellow."
In every programming language I've seen, that translates into something like:
isPrimaryColor = someColor == "Red" or someColor == "Blue" or…

Davy8
- 30,868
- 25
- 115
- 173
30
votes
5 answers
Where are the readonly/const in .NET?
In C++ you'll see void func(const T& t) everywhere. However, i havent seen anything similar in .NET. Why?
I have notice a nice amount of parameters using struct. But i see no functions with readonly/const. In fact now that i tried it i couldnt use…
user34537
30
votes
3 answers
What is a formal parameter?
When compiling in C++ I often end up with error messages dealing with "formal parameters", such as
error C2719: 'b': formal parameter with __declspec(align('16')) won't be aligned
I do understand the error, and the fact that b is a parameter of a…

CygnusX1
- 20,968
- 5
- 65
- 109
29
votes
5 answers
Why does C# not allow generic properties?
I was wondering why I can not have generic property in non-generic class the way I can have generic methods. I.e.:
public interface TestClass
{
IEnumerable GetAllBy(); //this works
IEnumerable All { get; } //this does not…

Sunny Milenov
- 21,990
- 6
- 80
- 106
29
votes
2 answers
How is Dart "sound null-safety" different from Kotlin null safety?
This Dart official video states that Dart's so-called "sound null safety" is better than Kotlin's null safety design, because it can optimise the code based on whether a variable is declared nullable, and other languages (I assume this refers to…

Yihao Gao
- 535
- 7
- 11
29
votes
6 answers
Is "monkey patching" really that bad?
Some languages like Ruby and JavaScript have open classes which allow you to modify interfaces of even core classes like numbers, strings, arrays, etc. Obviously doing so could confuse others who are familiar with the API but is there a good reason…

maerics
- 151,642
- 46
- 269
- 291