Help

So my recent return to writing code in Java has been interesting. Most of my Java programming experience has been in web apps, where there is a lot of UI/declarative code, and state-holding classes, or in framework development where I need a lot of interception and reflective code, and in those domains I have often found that Java gets in the way. But now I'm writing a compiler (well, a type checker/analyzer to be precise), and I don't have much use for declarative code, interception, or reflection. And there is a lot more code that does stuff rather than represents state or data. Java is honestly a quite different experience in this domain. My overall reaction is that Java is simply very reasonable and non-annoying for this kind of work. It just doesn't get in my way much. And in an IDE like Eclipse, Java's static typing saves me enormous gobs of time.

Nevertheless, there are definitely some moments where I find myself wishing I had Ceylon already. Here are the things I really miss:

  • Typesafe null. One of the things about a compiler is that it needs to be able to accept input that is partly rubbish and partly meaningful and just keep going and do the best it can with what it has. That means that there are a lot of null checks in my code, and, frankly, catching all the places an NPE could occur is very tough work. I wish the compiler would help me here.
  • Algebraic types. There's lots of instanceof in my code. Indeed, the whole thing is a bunch of tree Visitors. Algebraic types, typesafe narrowing, and built-in support for the visitor pattern would help enormously.
  • Mixin inheritance. The metamodel classes which represent Ceylon types would turn out much cleaner if I had concrete methods on interfaces. As it is, I'm stuck with some code duplication.

These are the three things I really miss. Sure, there are other bits of Java that I don't love, but for now they're just not bothering me much.

6 comments:
 
25. Jul 2011, 17:10 CET | Link

If you're using IntelliJ and/or static analyzers, you can annotate your variables, parameters and return types with @NonNull and @Nullable annotations. With IntelliJ you'll get real-time flow analysis that will warn you when you're trying to access nullable references. Not a great solution but a big help.

ReplyQuote
 
26. Jul 2011, 03:03 CET | Link

It would be interesting to look at the code where, as you mentioned, you do a lot of null checks. Sometimes null reference can be replaced with DontDoAnything objects, so I am wondering if this could be the case. As foe finding paces for potential NPEs, FindBugs is very good at it.

Hope this helps.

Regards,

Slava Imeshev

Cacheonix: Reliable Distributed Java Cache

 
26. Jul 2011, 05:32 CET | Link
Sometimes null reference can be replaced with DontDoAnything objects, so I am wondering if this could be the case

I doubt that this would help in this case - my compiler is a bunch of visitors which walk a tree composed of many different node types, almost any of which might be null in the case of garbage input. The nodes themselves don't do anything. The functionality is in the visitors. And they need to account for the possibility of null subnodes.

As foe finding paces for potential NPEs, FindBugs is very good at it.

Ugh, depends on your definition of very good, I suppose...

 
22. Aug 2011, 01:39 CET | Link

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

 
22. Aug 2011, 01:41 CET | Link

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

 
16. Sep 2012, 09:45 CET | Link
Slava Imeshev | simeshev(AT)cacheonix.com

Gavin,

Sorry for the late reply. I wish this commenting system had some sort of a mechanism that would alert about responses. I see where you are coming from and I agree that DontDoAnything instead of nulls might not be that much of help.

Regards,

Slava Imeshev

Post Comment