Monday, January 6, 2014

Abusive Language

Sorry to disappoint, but this is actually about Java8.

A long time ago, I was an academic, & we used to teach object-oriented programming in C++. How naive! This was when Java was a mere pup, so it wasn't really an option. The important thing was teaching object-oriented-ness (in theory) & then showing the students how to use it in practice.

Years later, I went from being a C++ developer to being a Java developer - during the war. No, I don't mean a military conflict, but the point when those two languages had some commercial altercations. Propaganda leaflets were dropped from skyscrapers with strident calls for "Multiple inheritance!", etc. There was a lot of discussion over maintainability, libraries, the friendliness of the language (readability), the viciousness (the ability to write bad code), etc. In the end, Java "won out" because it was more web-oriented, & then a lot of the C++ world turned to C#.

A few years ago, I was introduced to Scala. Without delving into it commercially, I could see that it had become an academic favourite because it was a way to do functional programming - which represents theoretical ideals - & it also runs on the JVM, which makes it Java friendly & more useful than Haskell. At the time, I thought "nice theory". I couldn't see how functional was going to take the commercial programming world by storm, or how a new language would fit in. Who wants it?

Now I've got my dev copy of Java 8. Each of the previous major upgrades has been an improvement - some in efficiency of the JVM, some in better coding style. Up until now, though, the introduction of generics, which was effectively C++ templates a long time overdue - was the biggest change to the way Java is used. Some would say that annotations were as big a change, but this depends on whether you take advantage of frameworks (Spring, Junit, ...).
Java 8 has Lambdas.

Although you might think that anonymous classes & defining callback interfaces had already covered this area, it was messy, so you avoided it. Now, there is encouragement to be functional. It will be easier to write functional code within object-oriented Java. You will discover that you'd been doing it quite a bit before (in event handlers) & can do it better & more often.

Here's the kicker, along with the new way of writing lambdas (which is VERY concise) come other short-cuts influenced by Scala & Ruby that do seem to take away some of the elegance of Java - where verbosity was often a blessing. I can recall, during the war, how we were told to avoid inline-conditionals, on the basis that they made code unreadable. Now we have inline functions.

Is there a driver for making things easier or quicker to type? I thought that's why we used IDEs with short-cuts. Good code design & development can be partially auto-generated from UML (theoretically), then the features defined in TDD before the implementation is begun. XP's mantra of pair programming is distinctly on the side of "think before you type".

There has to be some balance between introducing new language features that work elsewhere (lambdas, generics, annotations) & staying true to how that language is used professionally (readability, testability, design).

In the world of written & spoken languages, some countries have committees that ensure the "purity" of the culture represented by the language. In Java, we have Oracle & OpenJDK. At some point, you have to ask whether new concepts need to be incorporated into the culture, or whether they would just be an abuse of the language.

No comments:

Post a Comment