Hi there! I have just written my two first classes and my first trait in Scala at work! It may sound a little bit weird, but I thought, hey, why not? So I wanted to celebrate it and share it with us 🙂
This means that Scala isn’t for me a free time thing anymore, of course I will continue with it in my free time, but now I am using it now at the office too and this three pretty pieces of Scala code will go into production.
The thing came while I was refactoring two Eclipse plugin editors. There was a code duplication (thanks SonarQube) where there were two Adapter classes, one ListenerAdapter and one KeyAdapter, both reacting to their corresponding events. The body of the handler method of each Adapter was duplicated and I wanted to get rid of it, I couldn’t extract it to an abstract class because they where already extending one and in Java, as you may already now, there is no multiple inheritance, the other idea could be to add an Utility class, but as you now, I don’t like them pretty much, so I discarded this option. I knew that I could use Scala, write a trait and then mix it within both Adapter classes and I would get a good clean code effective solution and as we plan to work with DSLs in the future, Scala was going to be there sooner or later, so better sooner.
By the way it is amazing how Scala mixes into Java without any effort and how you can call classes from Java in Scala and vice versa. But the best thing is to work with a team that listens to the new things coming into the business and let you place for being creative. Thank you Alex, thank you Jonas, thanks for letting me introduce Scala, for letting me introduce SonarQube… und für die gute Stimmung, die wir im Team haben. Es gibt noch viel zu tun 🙂 Danke Jungs.