Help

Cedric recently brought up the topic of type erasure, concluding:

All in all, I am pretty happy with erasure and I’m hoping that the future versions of Java will choose to prioritize different features that are more urgently needed

Well, I suppose erasure isn't the thing I hate most about Java, but it's certainly up there. Java's system of partially reified types actually adds a surprising amount of complexity and unintuitive behavior to the type system.

From a pure language-design point of view, I think a partially reified type system is one of the worst decisions you could possibly make. Either reify all types, like C#, or reify none of them, like ML. And look, there's certain language features that simply don't play nicely with type erasure. A case in point: overloading. You can have type erasure, or you can have overloading (or, like Ceylon, you can have neither). You can't have both type erasure and overloading. No, Java is not a counter-example to this! In terms of language design, Java's approach to reification is almost impossible to justify except as a totally half-baked and misconceived workaround for simply not having time to Do It Right.

But Cedric's coming from a purely practical point of view, saying the problems don't actually bite him much when he's doing real work. Well, OK, I can see that. So here's the practical reasons why I think reified generics are needed, and why they should be added to Java if that could be done without messing up Java's type system even further.

Frameworks

Many frameworks depend upon having reified types. Type argument erasure cripples frameworks that work with generic types, and results in horrid workarounds like this one in CDI.

Typesafe narrowing

Instead of a Java-style instanceof operator, and C-style typecasts, Ceylon provides a construct for narrowing the type of a reference in a totally statically typesafe way. You just can't get ClassCastExceptions in Ceylon.

But this functionality depends upon having reified generics. Until we implement reified type arguments, we can't provide any mechanism to narrow to a parameterized type. Right now, you simply can't narrow an Object to a List<String>.

You might think that this is a problem with Ceylon, but really, the situation isn't much better in Java. The instanceof operator doesn't support types with type arguments, and casting to a type with type arguments is a totally unsafe operation! I just don't think that's acceptable behavior in a language with static typing.

Inter-language interoperability

Interoperability between statically-typed JVM languages is going to get really messy when some of the languages support reified generics and some don't. Especially since it's easy to imagine that those languages which do support reified generics won't support them in an interoperable way. This could turn out to be a real problem for the vision of a multi-language JVM.

19 comments:
 
02. Aug 2011, 09:15 CET | Link
Geoffrey De Smet

Starting from scratch, I 'd definitely prefer having reified types over erasure types (and I don't think anyone can decently argue differently).

The problem is, we're not starting from scratch, ever: we're always reusing existing libraries, such as hibernate and seam. And those are based on the java Collections API.

So, the elephant in the generics room is the java Collections API: Will Ceylon's reified generics be compatible with the java Collections API and therefore with all those existing libraries, such as hibernate, seam, ...? If not (which might be ok), does this mean we'll have to wait until those frameworks are rewritten on Ceylon before we can use Ceylon?

ReplyQuote
 
02. Aug 2011, 09:47 CET | Link
Geoffrey De Smet wrote on Aug 02, 2011 03:15:
So, the elephant in the generics room is the java Collections API: Will Ceylon's reified generics be compatible with the java Collections API and therefore with all those existing libraries, such as hibernate, seam, ...? If not (which might be ok), does this mean we'll have to wait until those frameworks are rewritten on Ceylon before we can use Ceylon?

Ceylon will have its own collections module. The language is meant to be interoperable with Java. It's not supposed to be seamlessly compatible with existing Java frameworks. I mean, it simply wouldn't really make sense to use Java frameworks with Ceylon, because Ceylon is designed to enable much nicer frameworks than what are possible in Java.

 
02. Aug 2011, 12:20 CET | Link

So, are you saying Oracle should break every single Java library out there, so that it's easier for my shiny new yet-another-JVM-language to work?

 
02. Aug 2011, 13:14 CET | Link
Sergej Koščejev
So, are you saying 'Oracle should break every single Java library out there, so that it's easier for my shiny new yet-another-JVM-language to work'?

Eh, where exactly is he saying that? Ceylon will work without Oracle doing anything.

 
02. Aug 2011, 14:59 CET | Link

The first part of the statement is the relevant one. I don't think Sun chose erasure just for laziness, but because any other way would break the whole Java ecosystem.

Gavin just don't give a crap, because his language will have a whole new base class library, incompatible with the current Java library. And he does say that interoperate with different languages will be difficult without reified generics.

 
02. Aug 2011, 18:10 CET | Link
Tetsuo wrote on Aug 02, 2011 08:59:
The first part of the statement is the relevant one. I don't think Sun chose erasure just for laziness, but because any other way would break the whole Java ecosystem.

Really? I I understand you correctly, you're claiming that there would have been absolutely no other imaginable approach to achieving the backward compatibility goals that Sun had with Java 5? That's a pretty big claim. Exactly how long have you spent thinking about the problem to be able to make such a claim? Because I can imagine just off the top of my head two approaches that could potentially have met the requirements as I understand them to have been at the time, and that would not have required a partially reified typesystem. Certainly, the solution they went with is easier to implement than the solutions I'm imagining, but that doesn't mean it was the only viable solution.

Gavin just don't give a crap, because his language will have a whole new base class library, incompatible with the current Java library. And he does say that interoperate with different languages will be difficult without reified generics.

I assure you that I absolutely do give a crap about these issues. Indeed they're issues I spend a lot of time thinking about. I imagine I devote much more of my time to worrying about this stuff than you do. And please, lose the hostility if you wish to keep posting here, thanks.

 
02. Aug 2011, 21:07 CET | Link

Ok, I'm sorry. I'll go back to my corner now.

Oh, could you please remove my email from my first comment? Since every other site in the Internet never publishes commenters' email addresses, I've written mine, but didn't think it would appear publicly.

 
03. Aug 2011, 00:06 CET | Link
Stephane Epardaud
Because I can imagine just off the top of my head two approaches that could potentially have met the requirements as I understand them to have been at the time, and that would not have required a partially reified typesystem.

OK now I'm curious, since I didn't spend any time thinking about how it could be done and just assumed it couldn't without giving it any thought. Now I'm dying to hear about those approaches :)

 
03. Aug 2011, 00:17 CET | Link
Stephane Epardaud
Tetsuo wrote on Aug 02, 2011 15:07:
Ok, I'm sorry. I'll go back to my corner now.

It's not about being punished for your comments' tone, I'm sure you understood that open discussions always work better when there is a friendlier tone. After all the fact that you are commenting here shows you express interest and you want a constructive discussion (as opposed to a Monty Python argument), so in general using the same rules online as for real life discussions work best :)

 
03. Aug 2011, 05:56 CET | Link

Frankly I think they should have done what C# did, introduce new Collection types. Even with erasure they are still broken from a type saftey perspective (e.g. get taking Object as a param instead of ? extends K)

 
03. Aug 2011, 13:31 CET | Link
Geoffrey De Smet
Gavin King wrote on Aug 02, 2011 03:47:
Ceylon will have its own collections module. ... It's not supposed to be seamlessly compatible with existing Java frameworks. ...

Thanks for the clear answer. Ceylon is very ambitious (language, modules, collections, ...), which is both good and risky. Such a better language with a reified collection framework (and those other aspects in harmony) is welcome, but the quality of the (temporary) Ceylon Collection Bridges to Java Collections will be critical for it's success.

 
22. Aug 2011, 01:40 CET | Link

Please vote for Kotlin and Ceylon merging in Kotlin bug tracker. Vote

 
01. Sep 2014, 09:18 CET | Link
jack

It has fully emerged to crown Singapore's southern shores and undoubtedly placed her on the global map of residential landmarks. I still scored the more points than I ever have in a season for GS. I think dental implants north lauderdale you would be hard pressed to find somebody with the same consistency I have had over the years so I am happy with that

 
25. Oct 2014, 15:14 CET | Link

The electric motor is two to five times more efficient than a diesel engine. Higher efficiency means less energy consumption. Less energy consumption means lower costs and less pollution. testofuel

 
27. Oct 2014, 08:51 CET | Link

We are existing because we are not dead; though our daily way of life is packed with the emotional jumble of concepts, feelings, and applications, at another stage we have a low-level careful system that is always looking out for existential threats. www.solidremote.com

 
28. Oct 2014, 11:06 CET | Link

I've tried rechargeable batteries, but they're not long-lasting enough for me). well i had a bit doubt but after i using these cartridges, i have my confidence in this product and will not hesitate to used it again. cosmetic dentist Cardiff

 
11. Nov 2014, 09:37 CET | Link
article

Moreover, they will have a live example to demonstrate during their job discussions to show how they have applied their SEO abilities to their own sites or weblogs. This is a sure-shot way of obtaining a job in SEO. article

 
26. Nov 2014, 12:25 CET | Link

Something else to consider is that eczema can also be linked to drinks that contain gluten, such as root beer and whole wheat alcoholic beer. For those that have issues with gluten based foods, there is the usual digestive problems but this can also lead to ulcers as well as eczema. apartemen kebayoran icon

Post Comment