Saturday, December 29, 2012 -> Scala or Groovy?

The future is already here—it’s just not evenly distributed. —William Gibson

The is going to be Java followed by Groovy and Scala. The dominance of java language is likely to continue but there are more and more use cases that compels us to use other JVM languages (with their functional programming capabilities) for developing newer platforms. Java7's new features like "Improved Type Inference","Multi-catch","try-with-resources statement","Strings in switch","New Garbage First Collector" can still fight with newer languages. Java8 is likely to close the gap further with the support of closures. Hence would be multiple languages led by java, a technique also popularly known as polygot programming.

Project team will have heterogeneous level of competence (best/good/average bad developers), technical superiority is not always the best choice, cost of maintenance always exceeds the cost of construction. Java has proved to be the best choice although it may not be technically superior, there is no reason to believe that it will change dramatically in coming days.
I am personally sold on the productivity benefits of JVM languages (Scala/Groovy/JRuby) and their functional programming abilities. Having developed several internal projects during day work and few personal projects during free time given a chance, I always prefer to code with JVM languages rather than in java.

The assumption that Java is getting old its time look for new ideas is getting stronger day by day. Irony of the history that .NET started as truly multi-language with single platform as compared to java claiming one language running in multi-platforms, the current trend looks like there are lots of JVM languages gaining lots of mind-share but .NET still heavily tilted towards C#.
The question of what is itself seems to be strange because all who came to replace java as language compile to byte code and runs on rock solid JVM. I have been following JVM languages for a quite some time. I picked these Groovy,Scala languages (Only because I can code in these languages and following seems to be higher for these 2 compared to any other JVM languages) as contenders.
I also picked up the parameters that suits java developers thinking.
1. Can I get my things faster and hence spend less time in office. (Here "my things" are general programming requirements as I perceive)
2. How easily I can pick them and can convince both technically literate and il-literate stake holders.
3. How easily I can get jobs and is it going to offer better salary compared to java

Thought Leaders opinion about the the languages 
Generally the understanding is that scala has the ability to disrupt the status quo rather than incrementally improving it like Groovy. Scala has done and doing good job of reducing the cost of abstraction transliterate Java into Scala and end up with bytecode that is almost exactly the same. Scala has some original good ideas and well thought out type system.
It does look like java programming Intellectuals move towards scala.
Here are the examples.
- Spring creator (Rod Johnson) endorses Typesafe and his dislike for groovy is quite evident as I heard from a podcost
- Java creator (James Gosling) prefers scala over ther JVM languages
- Groovy original creator (James Strachan) says scala as better option in the long run to replace java and so the JRuby creator (Charles Oliver Nutter )
But I think there will be some vested interest by some of these folks taking extreme stand and hence we need to take them with pinch of salt.

Winner : Scala

Job Trends
"Where the rubber meets the road" - The moment of truth.
Making more money with enjoyable effort (I don't say least effort) is a general end goal with technologies. Job opportunuties are the best borometer. They are the real reason for anyone to invest in a technology & probably single most important parameter to believe the hype in technology.
As web technology development is dominant one Grails popularity and active SpringSource support is driving the results.

Winner: Groovy

Learning curve
Compared to Groovy, Scala has been harder to learn for me (still learning of course). The ability to write scary programs in scala is big NO for enterprise development. We are always going to have mixture of good/averege/bad and great developers.
Although Martin (author of scala) tried hard to prove other way round brilliantly  From my experience I say it just more hard for java developers.In groovy I can just close my eyes and type java code if I get struck with some groovy concepts while learning that can't happen with scala.

Winner : Groovy

Multi-core programming
For the past 30 years, computer performance has been driven by Moore's Law;(the number of transistors on integrated circuits doubles approximately every two years). We don’t get the same increase in clock frequency as we used to, instead, we get more cores. CPUs aren't get faster anymore, it’s physically difficult to do so. Programming languages that can handle this better is likely to succeed more in coming days.
Scala supports  multi-core friendly language constructs and libraries than others. (Im-mutability and functional programming is baked into the language). Although there is nothing inherently great about scala (which runs on JVM anyway) compared java. GPars from groovy is also fair. Scala folks says if we stick our head in the sand we will be left behind. This is most preferred argument from scala evangelists to promote. I do think there is huge merit in this argument by seeing what libraries like akka are able to achieve although famous TestNG creator thinks otherwise.

Winner: Scala

Web Applications
Grails and play framework are the show pieces of Groovy and Scala respectively. They beat other java web frameworks in the page oriented MVC architecture hands down. The productive gains are pretty huge to overlook. The approach is not only new and intelligent.
More and more work is getting done at the web browser, mainly through java script. This trend likely to continue the future as well. With lots of great library pushing the limits of ability of java script (JQuery, AngularJS, Backbone ...).
Both the frameworks are way ahead of other frameworks in supporting new java scrpit libraries, web soeckets etc... JSON/XML rendering from controllers of play and grails looks so innate behaviour of the framework unlike others. Both supports MVC and stateless architecture much better than their counterparts.
I think there is scope to write component oriented single web applications is pretty huge. GWT is still the best option for java programmers. Relying on some code generators is always not good. Coffee script(better way to write java script) also looks nice.

Coming to performance, performance of most web applications is I/O bound, so the practical performance impact of Groovy may be largely offset by the (developer) productivity gains it offers. Play framework folks thought otherwise and moved from groovy based templates to scala one. But I still feel for most of the applications the first assertion stands,  and groovy offers awesome productivity benefits.
The plugin framework eco system of grails is miles ahead compared to play,  definitely a big plus.

Winner : Groovy

Mobile platform
Its difficult to imagine any new application that runs only on web. Although web apps will work with mobile as well with new frameworks fluently with mobile centric CSS/Script supoort, I believe HTML5's inherent advantages with distribution, monetization, platform power and network effects aren't enough to match with rich user experience with native in mobile apps.
I firmly believe that both of them will have their own space in the days to come and we have to live with building 2 kinds of applications. Java android SDK is the viable option for java programmers. (although there are some options to run other way)

Winner : Java

Writing DSLs
"Say What You Mean, Mean What You Say" - bridging the gap between what the user and a programming language. Ability to defining Domain Specific Language is very important feature. There are lots of use cases where it can be used to simplify most of the tasks. (new rules, Data entry, API usage, Testing, build systems, deployment etc...). Writing fluent API and XML are definitely verbose of way of defining new DSL. Resorting into using ANTLR, JavaCC is also overkill in most of the cases with huge learning curve/maintenance overhead that they bring in.
Ability to modify the existing class at runtime (meta programming) and language ability for operator overloading flexible syntax plays very important role.All functions can be used infix (obj.method(arg) or obj method arg) makes the writing of DSL a joy. I created fluent interface library myself and a great fan of functional libraries like Guava,  and functional java. But we are bending too much to use functional programming with java and isn't natural.

Winner : Groovy

Both Scala/Groovy wins hands down over java.

Database operations
Most of the development involve large chunk of code dealing with bringing data from various data sources (mainly relational) and updating the same. JPA (Its originator Hibernate) tried solve impedance mismatch between the object oriented code and relational data. After evaluating some of the scala framework I have come conclusion, JPA fixed the issue and not solved it. Functional programming is the best way to deal with row oriented data and success is not hiding the SQL details from developer but making as easy and transparent to developer without losing type safety.
Its thumbs up for slick and other several scala frameworks making JDBC operations simpler from scala world.

Winner : Scala

Big Data
In general appetite for insight into the details is increasing.Data inflow is increasing with larger velocity, its becoming difficult to assimilate the insight information. When we deal with larger data we need software that monitors and heals the software. Pretty big challenges.
We need software that exploits the hardware and new multi-core cpus better. The functional programming paradigm and immutable friendly programming language plays very important role.

Winner : Scala

Here are some interesting threads on this topic I found interesting against Scala. You can also see spirited fight from scala enthusiasts as response.
Switching back to Java:
Scala feels like EJB-2
Yammer moves back to java from scala

No comments:

Bookmark and Share