Questions tagged [language-design]

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

1363 questions
85
votes
5 answers

Why can't you have multiple interfaces in a bounded wildcard generic?

I know there's all sorts of counter-intuitive properties of Java's generic types. Here's one in particular that I don't understand, and which I'm hoping someone can explain to me. When specifying a type parameter for a class or interface, you can…
Adrian Petrescu
  • 16,629
  • 6
  • 56
  • 82
85
votes
6 answers

Why can't we define a variable inside an if statement?

Maybe this question has been answered before, but the word if occurs so often it's hard to find it. The example doesn't make sense (the expression is always true), but it illustrates my question. Why is this code valid: StringBuilder sb; if ((sb =…
comecme
  • 6,086
  • 10
  • 39
  • 67
83
votes
19 answers

Why can't I inherit from int in C++?

I'd love to be able to do this: class myInt : public int { }; Why can't I? Why would I want to? Stronger typing. For example, I could define two classes intA and intB, which let me do intA + intA or intB + intB, but not intA + intB. "Ints aren't…
Rocketmagnet
  • 5,656
  • 8
  • 36
  • 47
83
votes
3 answers

What does a PHP function return by default?

If I return nothing explicitly, what does a php function exactly return? function foo() {} What type is it? What value is it? How do I test for it exactly with === ? Did this change from php4 to php5? Is there a difference between function foo()…
user89021
  • 14,784
  • 16
  • 53
  • 65
82
votes
18 answers

What are C macros useful for?

I have written a little bit of C, and I can read it well enough to get a general idea of what it is doing, but every time I have encountered a macro it has thrown me completely. I end up having to remember what the macro is and substitute it in my…
Jack Ryan
  • 8,396
  • 4
  • 37
  • 76
81
votes
9 answers

Why does Ruby have TrueClass and FalseClass instead of a single Boolean class?

I was working on serializing values when found out about this one. Ruby has a TrueClass class, and a FalseClass class, but it has no Boolean class. I'd like to know why is this. I see some advantages in using a Boolean; for example, string parsing…
kikito
  • 51,734
  • 32
  • 149
  • 189
80
votes
3 answers

Why is there no sub-class visibility modifier in Java?

On more than one occasion I have found myself desiring a variable visibility that is not possible in Java. I wanted certain members to be visible within their own class and within any sub-classes, but not to the rest of the package or to the rest…
Michael McGowan
  • 6,528
  • 8
  • 42
  • 70
80
votes
5 answers

Why doesn't Rust support trait object upcasting?

Given this code: trait Base { fn a(&self); fn b(&self); fn c(&self); fn d(&self); } trait Derived : Base { fn e(&self); fn f(&self); fn g(&self); } struct S; impl Derived for S { fn e(&self) {} fn f(&self) {} …
kFYatek
  • 5,503
  • 4
  • 21
  • 14
78
votes
3 answers

Using variable keys to access values in JavaScript objects

The code: function updateDashboardData() { $.getJSON("includes/system/ajaxDataInterface.php", {recordcount:1}, function(data) { $('.stationContainer').each(function(data) { var bsID = $(this).attr("id"); var…
mikegreenberg
  • 1,411
  • 1
  • 12
  • 19
77
votes
3 answers

Why are there no ||= or &&= operators in C#?

We have equivalent assignment operators for all Logical operators, Shift operators, Additive operators and all Multiplicative operators. Why did the logical operators get left out? Is there a good technical reason why it is hard?
75
votes
7 answers

Why isn't Array a generic type?

Array is declared: public abstract class Array : ICloneable, IList, ICollection, IEnumerable { I'm wondering why isn't it: public partial class Array : ICloneable, IList, ICollection, IEnumerable { What would be the issue if…
Ken Kin
  • 4,503
  • 3
  • 38
  • 76
74
votes
7 answers

Why not call nullptr NULL?

In C++11 the nullptr keyword was added as a more type safe null pointer constant, since the previous common definition of NULL as 0 has some problems. Why did the standards committee choose not to call the new null pointer constant NULL, or declare…
user253751
  • 57,427
  • 7
  • 48
  • 90
72
votes
5 answers

Why does Python assignment not return a value?

Why is Python assignment a statement rather than an expression? If it was an expression which returns the value of the right hand side in the assignment, it would have allowed for much less verbose code in some cases. Are there any issues I can't…
max
  • 49,282
  • 56
  • 208
  • 355
71
votes
8 answers

Is there a better PHP way for getting default value by key from array (dictionary)?

In Python one can do: foo = {} assert foo.get('bar', 'baz') == 'baz' In PHP one can go for a trinary operator as in: $foo = array(); assert( (isset($foo['bar'])) ? $foo['bar'] : 'baz' == 'baz' ); I am looking for a golf version. Can I do it…
Yauhen Yakimovich
  • 13,635
  • 8
  • 60
  • 67
71
votes
3 answers

Purpose of Scala's Symbol?

Possible Duplicate: What are some example use cases for symbol literals in Scala? What's the purpose of Symbol and why does it deserve some special literal syntax e. g. 'FooSymbol?
soc
  • 27,983
  • 20
  • 111
  • 215