Slashdot Mirror


Hejlsberg Talk About Generics in C# and Java

An anonymous reader writes "artima.com has a very interesting interview with Anders Hejlsberg - the Borland guy now at Microsoft who can best be defined as MR C# - doing all the stuff that Borland wouldn't let him do. He discusses generics in C#, Java (1.5) and C++. Naturally there is the chance of bias but he does raise some interesting points againt Java's generics. Specifically that Java's genericised collections will have to box all primitive types as full objects, whereas C# does not. This is a big performance plus for C#. Java created the primitive types in the first place to address performance concerns but appears to be stepping sideways here. I can't help wondering if Sun has taken this approach to get the syntatic sugar in the language without requiring a bytecode change, but perhaps in a future VM version will allow primitive generics (obvioulsy forcing a bytecode regeneration)?"

6 of 128 comments (clear)

  1. Boxing in Java by Ianoo · · Score: 2, Interesting

    Primitive types are boxed in C#, just automatically wrapped and unwrapped as required. But what he seems to fail to realise is that Java 1.5 is introducing this too, so that I will be able to define method(Object obj) and type method(12) and will receive a boxed Integer type. This should work fairly for generics too (I hope).

    1. Re:Boxing in Java by drkich · · Score: 2, Interesting

      Yes, C# does auto-boxing for the user. However, his point was that the Generics will not auto-box the primitive inside of an object.

      So for instance if you have a List, you can not place an Integer with out unboxing it. Vice-versa, if you have a List you can not place an int into with out boxing it.

      However if you have a List you can place an int into it directly without boxing it.

    2. Re:Boxing in Java by jovlinger · · Score: 3, Interesting

      Automatic boxing and unboxing will be identical to manual boxing from a performance standpoint.

      I got the impression that C# could actually use generics to instantiate the array at type int, rather than type Integer with autoboxing.

  2. Why Generics? by HaiLHaiL · · Score: 2, Interesting

    I'm a Java developer of 4 years and I'm unimpressed by generics. Why have all those 's dirtying up my code, only to enforce strong typing on my collections? If strong typing is really important, I can create my own strongly-typed collection. Otherwise, there's something called GOOD CODING, along with runtime exceptions, which enforce it. I don't see the need for all that extra ugly syntax just to enforce it at compile time.

    --


    reech bee-yond ur clip-0n
  3. Oh, the irony! by joelparker · · Score: 2, Interesting
    ...we do fairly aggressive code sharing
    where it makes sense, but we are also very
    conscious about not sharing where you want
    the performance.

    Welcome to the Microsoft business model. :)

  4. Re:It does seem any "performance" argument is bogu by dustman · · Score: 2, Interesting

    The types of performance problems you're talking about are orders of magnitude away from the performance problems that users percieve when using Java applications though.

    I disagree here.

    Think of Moore's law, processor speeds, etc... Java is a fast enough language for doing just about anything a user needs to do. Even if java were only 25% as fast as native code, that would be 2 cycles of Moore's law, 36 months, 3 years ago. (And, java is much faster than 25% of C, check here)

    3 years ago, users were all doing the same things they are doing today.

    A couple of exceptions apply, of course: scientific computing, games, etc, tax the hardware pretty heavily.

    But, the primary reason that Java is perceived as slow by users is the terrible speed of the GUI.

    All the widgets are implemented in Java directly. This is almost like the same exception as game software, since all this rendering code involves moving around lots of memory, etc...

    The GUI matters more than anything to user perception of slowness.

    An old 14mhz 68000 amiga often "felt" faster than a 50mhz 386, because the amiga's os/gui were very responsive, while the 386 was running win3.1

    Look at the recent developments with the linux kernel. Compare X responsiveness with a preemptible low-latency kernel, and how the whole machine "feels" better.

    By going with preemption and low-latency, the overall throughput of the machine is actually slightly slower. But it feels loads better.

    C# and the .NET framework use native code libraries for the GUI. It will never have the same perception of "slowness" that java has.