Why don't other programming languages have ranges?

Sean Kelly sean at invisibleduck.org
Sun Jul 25 21:32:17 PDT 2010


bearophile Wrote:

> Andrei Alexandrescu:
> > In my humble opinion, the design of Java, C#, and Go is proof 
> > that their authors didn't get the STL. Otherwise, those languages would 
> > be very different.
> 
> I don't believe you. Among the designers of Java, C# and Go there are people that are both experts and smart. C# designers have shown to be sometimes smarter than D designers. So I think some of them 'get the STL' and understand its advantages, but despite this in the universe they have found some other reasons to refuse it. I think they were unwilling to pay the large price in language complexity, bug-prone-ness, code bloat and compilation speed that C++ and D are willing to pay.

The reason behind the Java design is much more mundane: they chose binary backwards compatibility as a requirement for future language changes.  So you can do ridiculous things like:

class A {
    void put(List x) {}
}

class B {
    void pass(List<Integer> x) {
        (new A).put(x);
    }
}
 
> Here you can find why C# designers have refused C++-style templates & STL and chosen the generics instead:
> http://msdn.microsoft.com/it-it/magazine/cc163683%28en-us%29.aspx

C# generics are a heck of a lot nicer than Java generics, but there also I think there were other practical reasons for the decision that they didn't fully address.  C# is effectively the native language for .NET, and so its libraries should be as useful as possible to other languages compiled to CLR bytecode.  If C# used C++ style templates, C++ would integrate well with it, but no other languages really would.  Try telling some Visual Basic programmer that they have to define a different container interface for each stored type and see if they use your library.  The "Binary Compatibility" section mentions this, but only briefly.

> Maybe there is a way to build something like STL without C++/D-style templates :-)

If you figure out how, I'd love to know it :-)


More information about the Digitalmars-d mailing list