Posts

Implicits @ brief

Implicit conversions Used in extending the behaviour of closed classes, for e.g. String class Implicit class myStrBehavior(s:String){ def incrment = s.map(c=> (c+1).toChar) Flow: When we call "HAL".increment, compiler sees for increment method on String object When it didn't find that method, it looks around for implicit conversion methods that are in scope and accepts the string argument Then it finds increment method in myStrBehavior class. Typical example of using implicits is: "Hello".map(), this is done by the implicit conversions. As String doesn't have map method in it, it is defined in StringOps class. args object is implicitly available when we have an Object <<name>> extends App class, which is one way of launching the Scala applicaton. args object is an instance of Array[String] Implicit imports are: s...

Why Scala?

Concurrency model is no more a nightmare(This concept is taken from Erlang - general purpose, concurrent, FP and garbage collected runtime system.) Same can be achieved in java with lot more code and pain. Actor concept is taken from Erlang Deadlock is handled in much better way Synchronization and shared variables are abstracted Mixins - No diamond problem Both FP + OOP - It's blend of both programming paradigms Scalable language - Goes with ideas of massive parallelism and Reactive programming( reactive programming is a declarative programming paradigm concerned with data streams and the propagation of change) Implicits Implicit conversions - Used for extending the closed class behaviour e.g. String class extension. Implicit parameters implicit variables Pattern matching and case classes Cost of development to delivering will go down when compared to java Combined features from dif...

Immutability in FP(Functional Programming)/Scala

Immutability is a key concept in FP . Scala follows this as the default approach for variables in their programs. Benefits/Advantages of immutable's are: They don't have complex state spaces, that change over time; easier to construct, test and use Can pass the objects around quite freely No data corruption because of thread safe ; that means no synchronization issues; automatically thread safe, Makes safe hash table keys - for e.g.   If mutable object is placed into the HashSet, then modified, the object may not be found when you look into the HashSet. In other words, immutable objects are good Map keys and Set elements, since they don't change once created Makes easier to parallelize the program , as there are no conflicts among objects. The internal state of the program is consistent, even if you have exceptions. References to immutable objects can be cached as they are not going to be change...