Why Scala is so Cool?

Scala was suffer lots of criticism on late 2011, some "failure/Step Back" public appear and let several people worried.   If  you din't read this links before I high recommend you read it, but if you don't have practical experience with Scala becareful some things may mess with you head deeply and create a wrong concept of the language for you. So take it easy :-)  Here are the links

There are practical and useful feedback about tooling, language features -> more related with performance that deftly will be great for the Scala community to improve the language and make things better, smother and stronger. Other things are pure FUD and the worst thing unfortunately often people don't really understand what really things means in practice. I sow people got crazy with binary compatibility issues, and basically saying we don't have this issue in java, sure Java don't let you do what Scala does.  You don't have the same degree of flexibility / excitability, so If you got affected by that without realizing this your are not being fare with the Language.

I can say that Scala guys have balls trying to merge OOP and FP concepts in a sort of mixed paradigm language, I personally will enjoy Scala even more if Scala had more caution with state / mutability, like Clojure, that basically everything is immutable by default and If you want have state that's not default programming metaphor and you need do suck a explicit code like in STM dosync macro. But in other way around Scala has better OOP than java, for example lets look how java is permissive with statics, you basically can have static classes and static fields, in Scala you don't. You basically need to create a object, the cool thing is that you don't need instantiate a object you just use it and by default it's a singleton, in Java to archive this you must follow the singleton design pattern or even use a framework like Spring.

Anonymous Functions / Closure / Lambda

That's an old very well desired feature in Java, first sun promised for Java 7 and them ORACLE but the really is that java 7 was released and no big change was there and closures will be available(according what they say) late 2013 maybe early 2014 this is late too late. Ruby, Python and Scala had this since day one.

Look how beautiful and easy is to create closures in Scala. This code speak for him-self. 

Function Currying

Haskell you currying to pass multiple arguments to a function, so you maybe realize that Scala already can do that without currying so why use currying anyway?

Currying it's another functional programming benefit, I love currying it kicks ass. You use currying basically for 2 simple yet powerful reasons / features:
  • You have the ability to do partial functions and with that do a kinda of lazy programming and also enable you to use wild cards like _ and when involved with high order functions you end up having a better code with less noise.
  •  You gain the ability to "push" functions beyond the parameters, that may sounds crazy but this end up giving you a very nice, syntax on the user perspective, look how we do callbacks in Java <= 7, using inner classes and its ugly and it sucks.

IF you code with ruby this may look familiar to you... As you may notice currying here made the function consumer code really beautiful. Also clean and easy to read and understand.


Code java as a language is boring a plenty or reasons, one is that you need do basically everything manually, so you create a Pojo, you do need create a default constructor, a full constructor, getters, setters, equals and hashcode methods. I granted you that you IDE(probably eclipse) generate this things for you, but you don't get rid of good lines of code a small regular Pojo in java easily can get 100 LOC or more.

Scala it's smarter about this things, when you use the @BeanProperty annotation Scala do all this work for you and you code gets small and nice, check this sample.

What's interesting in this code besides what I mention before is that I'm using default values for each parameter, this give you the flexibility to create a object with all attributes or just the ones that you want change. You express this with perfect harmony with preview future(getters, setters)  it's D.Y.I indeed.

Scala is great for DSL

Using another cool feature called implicits you can create a very powerful code that I bet you a beer your business analysts will understand with any issue. 

2 days ago #wtf? Well it blow my mind first time I sow it. There is a implicit conversion that basically converts Int in DateHelper objects,  '.' and '(' and ')' are optional and using val variables we pass String without using the "" all  time. 

Scala has plenty of great features like Traits, dynamic mixing, Duck Typing, Structured Type Members, Typer Matcher, Case Classes,  Options[T] / Some / None, Either[Right,Left], actors, parallel collections, XML as first class citizen, parametric polymorphism, quantification wild cards and so on and on on other post I will explain and show more of this features If you curious you can check my Scala Playground project that's is more like a code catalog and look this things there https://github.com/diegopacheco/Diego-Pacheco-Sandbox/tree/master/scripts/scala/scala-playground

Where Innovation lies is here you want to be

There was a time when java was exiting and lots of frameworks was emerging, lots of companies using java and people talking about it doing open source projects coding and learning new ideas and new concepts, java lack of action kill the innovation. Now I see innovation that you may read as community or buzz in Scala, I see need ideas, new concepts, better ways of building software, new metaphors, new open source frameworks with new concepts like akka

Hold on a second Functional Programming is old as my grandmother and akka basically implementing ErLang ideas on the JVM, so be fare most of this things ideas originally inspire by Haskell, Python and Ruby are not essentially new. Yes, that's right, still exiting see all this things coming to the JVM where lots of people work now a days and have not only jobs but experience, it's great see FP concepts and FP going mainstream with Scala.

Wrapping up

You don't want be left behind, java as a language already had the days of  glory, the best use for the future will be as a platform I mean the JVM and benefit of all rich ecosystem of frameworks and libraries we have i place. 

Scala still evolving and getting better, the documentation is great, tooling is a issue but won't be in the next years and community will be growing and getting bigger, cumulatively speaking Scala is just growing  and this chart talks for it self.

 I'm already much more productive with Scala than java, and it's happening so naturally for sure there are lots of things to learn Scala is complex compared with Clojure, but this also make things exiting and cool. :-) What's was the last time you learn something new in Java? All the new options that Scala brings to us are some exiting and I love learn new things specifically if this things can make my life easier and make my work more sexy and fun :-) 

Scala #FTW

Diego Pacheco

Popular posts from this blog

Linux Terminal Goods

Running Istio 1.5 on Minikube

Mocking and Testing AWS APIs with TestContainers and LocalStack