Questions tagged [language-design]

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

1363 questions
143
votes
9 answers

Why doesn't Ruby support i++ or i--​ (increment/decrement operators)?

The pre/post increment/decrement operator (++ and --) are pretty standard programing language syntax (for procedural and object-oriented languages, at least). Why doesn't Ruby support them? I understand you could accomplish the same thing with +=…
Andy_Vulhop
  • 4,699
  • 3
  • 25
  • 34
137
votes
22 answers

Conventions for exceptions or error codes

Yesterday I was having a heated debate with a coworker on what would be the preferred error reporting method. Mainly we were discussing the usage of exceptions or error codes for reporting errors between application layers or modules. What rules do…
Jorge Ferreira
  • 96,051
  • 25
  • 122
  • 132
136
votes
13 answers

Why does C# disallow readonly local variables?

Having a friendly debate with a co-worker about this. We have some thoughts about this, but wondering what the SO crowd thinks about this?
Brian Genisio
  • 47,787
  • 16
  • 124
  • 167
129
votes
5 answers

Why are C# 3.0 object initializer constructor parentheses optional?

It seems that the C# 3.0 object initializer syntax allows one to exclude the open/close pair of parentheses in the constructor when there is a parameterless constructor existing. Example: var x = new XTypeName { PropA = value, PropB = value }; As…
James Dunne
  • 3,607
  • 3
  • 24
  • 29
124
votes
17 answers

Why is Multiple Inheritance not allowed in Java or C#?

I know that multiple inheritance is not allowed in Java and C#. Many books just say, multiple inheritance is not allowed. But it can be implemented by using interfaces. Nothing is discussed about why it is not allowed. Can anybody tell me precisely…
Abdulsattar Mohammed
  • 10,154
  • 13
  • 52
  • 66
113
votes
6 answers

Why are there no sorted containers in Python's standard libraries?

Is there a Python design decision (PEP) that precludes a sorted container from being added to Python? (OrderedDict is not a sorted container since it is ordered by insertion order.)
Neil G
  • 32,138
  • 39
  • 156
  • 257
110
votes
5 answers

Why are const parameters not allowed in C#?

It looks strange especially for C++ developers. In C++ we used to mark a parameter as const in order to be sure that its state will not be changed in the method. There are also other C++ specific reasons, like passing const ref in order to pass by…
Incognito
  • 16,567
  • 9
  • 52
  • 74
109
votes
6 answers

Calling Java varargs method with single null argument?

If I have a vararg Java method foo(Object ...arg) and I call foo(null, null), I have both arg[0] and arg[1] as nulls. But if I call foo(null), arg itself is null. Why is this happening? How should I call foo such that foo.length == 1 && foo[0] ==…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
109
votes
6 answers

Does R have an assert statement as in python?

a statement that checks if something is true and if not prints a given error message and exits
Dan
  • 6,008
  • 7
  • 40
  • 41
104
votes
16 answers

Why do we need break after case statements?

Why doesn't the compiler automatically put break statements after each code block in the switch? Is it for historical reasons? When would you want multiple code blocks to execute?
unj2
  • 52,135
  • 87
  • 247
  • 375
101
votes
7 answers

PHP global in functions

What is the utility of the global keyword? Are there any reasons to prefer one method to another? Security? Performance? Anything else? Method 1: function exempleConcat($str1, $str2) { return $str1.$str2; } Method 2: function exempleConcat() { …
Pascal Qyy
  • 4,442
  • 4
  • 31
  • 46
100
votes
5 answers

implementing type inference

I see some interesting discussions here about static vs. dynamic typing. I generally prefer static typing, due to compile type checking, better documented code, etc. However, I do agree that they do clutter up the code if done the way Java does it,…
100
votes
9 answers

Why does C++ not allow inherited friendship?

Why is friendship not at least optionally inheritable in C++? I understand transitivity and reflexivity being forbidden for obvious reasons (I say this only to head off simple FAQ quote answers), but the lack of something along the lines of virtual…
Jeff
  • 3,475
  • 4
  • 26
  • 35
100
votes
3 answers

Zero-based month numbering

Some popular programming languages use month numbering which is off by 1 -- JavaScript comes to mind, as does Java, and if memory serves, C is another. I have some questions: If you are going to be ignoring the month numbering used by laypeople,…
Robert L
  • 1,963
  • 2
  • 13
  • 11
98
votes
5 answers

Why can't your switch statement data type be long, Java?

Here's an excerpt from Sun's Java tutorials: A switch works with the byte, short, char, and int primitive data types. It also works with enumerated types (discussed in Classes and Inheritance) and a few special classes that "wrap" certain primitive…
Fostah
  • 11,398
  • 10
  • 46
  • 55
1 2
3
90 91