Questions tagged [language-design]

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

1363 questions
3352
votes
34 answers

"Least Astonishment" and the Mutable Default Argument

Anyone tinkering with Python long enough has been bitten (or torn to pieces) by the following issue: def foo(a=[]): a.append(5) return a Python novices would expect this function called with no parameter to always return a list with only…
Stefano Borini
  • 138,652
  • 96
  • 297
  • 431
403
votes
17 answers

Why doesn't Java support unsigned ints?

Why doesn't Java include support for unsigned integers? It seems to me to be an odd omission, given that they allow one to write code that is less likely to produce overflows on unexpectedly large input. Furthermore, using unsigned integers can…
dsimcha
  • 67,514
  • 53
  • 213
  • 334
374
votes
5 answers

Why is "final" not allowed in Java 8 interface methods?

One of the most useful features of Java 8 are the new default methods on interfaces. There are essentially two reasons (there may be others) why they have been introduced: Providing actual default implementations. Example:…
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
359
votes
13 answers

Why must we define both == and != in C#?

The C# compiler requires that whenever a custom type defines operator ==, it must also define != (see here). Why? I'm curious to know why the designers thought it necessary and why can't the compiler default to a reasonable implementation for either…
Stefan Dragnev
  • 14,143
  • 6
  • 48
  • 52
350
votes
12 answers

Why doesn't Python have a sign function?

I can't understand why Python doesn't have a sign function. It has an abs builtin (which I consider sign's sister), but no sign. In python 2.6 there is even a copysign function (in math), but no sign. Why bother to write a copysign(x,y) when you…
Davide
  • 17,098
  • 11
  • 52
  • 68
308
votes
10 answers

What does DIM stand for in Visual Basic and BASIC?

What does Dim stand for in Visual Basic?
Nick Katsivelos
  • 5,060
  • 4
  • 20
  • 11
296
votes
5 answers

Benefits of prototypal inheritance over classical?

So I finally stopped dragging my feet all these years and decided to learn JavaScript “properly”. One of the most head-scratching elements of the languages design is its implementation of inheritance. Having experience in Ruby, I was really happy…
268
votes
14 answers

Function overloading by return type?

Why don't more mainstream statically typed languages support function/method overloading by return type? I can't think of any that do. It seems no less useful or reasonable than supporting overload by parameter type. How come it's so much less…
dsimcha
  • 67,514
  • 53
  • 213
  • 334
260
votes
11 answers

What blocks Ruby, Python to get Javascript V8 speed?

Are there any Ruby / Python features that are blocking implementation of optimizations (e.g. inline caching) V8 engine has? Python is co-developed by Google guys so it shouldn't be blocked by software patents. Or this is rather matter of resources…
Greg Dan
  • 6,198
  • 3
  • 33
  • 53
255
votes
7 answers

How does "this" keyword work within a function?

I just came across an interesting situation in JavaScript. I have a class with a method that defines several objects using object-literal notation. Inside those objects, the this pointer is being used. From the behavior of the program, I have…
rmeador
  • 25,504
  • 18
  • 62
  • 103
214
votes
13 answers

Why does C++ need a separate header file?

I've never really understood why C++ needs a separate header file with the same functions as in the .cpp file. It makes creating classes and refactoring them very difficult, and it adds unnecessary files to the project. And then there is the problem…
Marius
  • 57,995
  • 32
  • 132
  • 151
211
votes
10 answers

Why can't I have abstract static methods in C#?

I've been working with providers a fair bit lately, and I came across an interesting situation where I wanted to have an abstract class that had an abstract static method. I read a few posts on the topic, and it sort of made sense, but is there a…
lomaxx
  • 113,627
  • 57
  • 144
  • 179
202
votes
8 answers

Why are arrays covariant but generics are invariant?

From Effective Java by Joshua Bloch, Arrays differ from generic type in two important ways. First arrays are covariant. Generics are invariant. Covariant simply means if X is subtype of Y then X[] will also be sub type of Y[]. Arrays are covariant…
eagertoLearn
  • 9,772
  • 23
  • 80
  • 122
198
votes
11 answers

Why doesn't a python dict.update() return the object?

I have this code: award_dict = { "url": "http://facebook.com", "imageurl": "http://farm4.static.flickr.com/3431/3939267074_feb9eb19b1_o.png", "count": 1, } def award(name, count, points, desc_string, my_size, parent): if my_size >…
Paul Tarjan
  • 48,968
  • 59
  • 172
  • 213
196
votes
11 answers

Why does Lua have no "continue" statement?

I have been dealing a lot with Lua in the past few months, and I really like most of the features but I'm still missing something among those: Why is there no continue? What workarounds are there for it?
Dant
  • 1,961
  • 2
  • 12
  • 3
1
2 3
90 91