The really cool thing about hybris is that the platform incorporates all major technology upgrades soon after they become available. This means you immediately have the chance to work with newest versions of languages and libraries such as Java, Spring etc. Last year, all our projects were upgraded to hybris version 5.6 and as a result we can now take advantage of Java 8.
Now, this opens up a whole host of new possibilities. Java 8 introduces a few fancy features that have been long awaited and well established in other languages. Features we believe you won’t want to live without once you’ve introduced them into your programming style.
A short list of these features can be found here:
Naturally, although this is the new standard, we still need to be cautious about how we use the additional features available in Java 8. They have to fit into our architectural guidelines and retain or improve the quality of our code, its maintainability and testability. After all, we know from past experience that some of these new standards have not made it into the mainstream, despite the support of Sun/Oracle; for example, java logging in JDK 1.4. Other features are of great value but can be radically misused if applied incorrectly.
So, we have started evaluating selected new elements of Java 8 in order to gather some hands-on experience with real commercial projects. The idea is to analyse the new features and have an internal discussion about how effective they are. We then want to come up with a set of guidelines as to what’s great, what’s cool or useful and what’s a no-go.
We’re very excited to be starting this exercise. To begin with, please take a look at the following Java 8 code:
.map(item -> item - item)
.map(item -> item * 3)
.map(item -> item.toString())
Yes, it is Java :). It’s not Ruby, Python or anything else. What this means is that we can now use a few key features of modern programming languages that were previously unavailable in Java.
It all looks very promising and will certainly change the way we write code in the future. That said, there are certain caveats associated with these techniques, some of which we have discovered already and others that will become apparent in the future.
For instance, the above code is in conflict with our coding style which would not normally allow long chained statements. We have always had rules that make sense when it comes to code readability, and some static code analysis tools like PMD enforce those rules by raising alarms. This remains a positive and we will simply have to adapt these rules to the new concepts we are presented with.
However, for the optimal use of streams, these chained statements are essential. Methods should be passing (streaming) data to other methods while processing. Splitting the above into several lines would result in different behaviour in terms of memory usage.
This means, we’ll need to adjust the code style and reconfigure the tools but we think it’s worth it.
So, we’re all now on Java 8, but we’re just beginning our hands-on research. We’ll be producing regular, information-packed updates on our progress and discussing the pros and cons of implementing the new features of Java 8 in real world, commercial projects. Stay tuned for more updates based on our experiences – coming your way shortly.