Programming evolution

The Java programming language continues to evolve, and at times it can be hard to keep up. I can code in dozens of languages, but the constant switching between differing syntax and paradigms often leads to confusion. I frequently find myself attempting quirky hybrids of languages, such as this morning when I attempted to initialize an ArrayList<Object> structure with a ({a,b,c}) constructor pattern. It took an embarrasing few seconds before I understood my mistake. In the end I refactored to use an “Object…” argument, since this better matched what I was doing, but how long will it be before I attempt using “…” in some other language?

Meanwhile, since more than half of my recent coding is in Java, some of its more interesting features are starting to feel natural. (Dangerous, as this is what prompts me to create hybrids!) Here are a few that come to mind:

  • Generics. Reminds me a lot of the old C++ templating, and often useful. For a lot of bespoke work the structures tend not to be of the reusable kind, so generics don’t have as much benefit. On the other hand, using generics (from libraries) is incredibly useful, and helps to avoid a lot of code fluff like array cursors, sentinels etc.
  • Autoboxing. I used to be very strict about using objects when objects were expected, and explicitly wrapping primitives. Now I just let the compiler box them. This could make me lazy in other languages where explicit boxing is still the norm.
  • Variable length argument lists. Varargs, if you wish. As mentioned above, the “…” syntax has its uses. It’s basically an old friend from my C days (and even before that, when doing stack coding in various assembly languages!).
  • Enums. How did Java survive for so long without enums?
  • Annotations. Brilliant. Embedded metadata to clarify at compile-time how various classes, methods and data are expected to be used. No more compiler guesswork. The metadata can be inspected at runtime too, which enables all kinds of possibilties (loose binding, improved diagnostics, design tooling and more).

These are a few features that are already present in Java, I use them a lot and they feel natural. Some features are still missing, and I wait for Project Coin and the OpenJDK work to deliver them. Two that come to mind are string-based switches, and (*fanfare*) lamda expressions! The latter will finally sort out the clumsy callback mechanism and herald a new era of functional programming. Lisp fans will nod in appreciation, but I think perhaps the biggest impact will be on Java coders who are also JavaScript coders. These guys have recently woken up to the fact that JS is inherently a functional language, thanks in no small part to the example set by jQuery. I think those awful JS primers that polute the Web should all be dumped or rewritten!

Back to coding, I think…

Categorised as: Coding

Comment Free Zone

Comments are closed.