Why Scala ?

Posted on Updated on


SCALA

  • Scala – means Scalable Language ( pronounced as scah-lah)
  • Scala extends  the Java language, in-fact internally uses many of Java language libraries.
  • Scala is recommended for algorithm development , big data processing & multi-threaded applications in a multi-core environment.
  • The Scala compiler, “scalac” generates java byte code, which can run in JVM
  • Scala is a statically typed language, suites large projects.
  • Scala improves the productivity of the developers after the initial learning curve.

Language Features

1. JVM Language

Scala is an JVM language.  Scala generates Java byte code, which can run on JVM.  Scala supports use of existing Java libraries in scala code.  Java libraries & Scala libraries are inter-operable.

2. Functional Programming Language along with Object Oriented Programming

Scala supports both Functional Style along with OOPs, unlike Java which is strictly OOPs or other functional programming languages which are strictly functional (Haskell, Clojure).

  • Immutable Objects by default : Scala creates immutable objects only.  If the programmer wants mutable objects, they must be created consciously  from a different library.
  • Higher Order Functions :  In Scala function is an object.  It supports anonymous functions, tail-recursion, closure etc.

3. Concurrency Support in Multi-Core Environment

  • Actor – Similar to Java Threads, which has advanced thread management, synchronous/asynchronous communication mechanism across threads.  This communication mechanism avoids the need for thread synchronization.
  • NO support for STATIC class/variables.  If similar behavior is needed programmer has to create a companion object for the class.  This feature avoid the need to protect the critical region which act on the global/static memory.
  • Threads (Actors) can be created and run for-ever and execute based on the messages.
  • Private[this] – feature to make a private member, perfectly private.  A private member of an object, can be accessed by other object of the same class.  This can restricted by Private[this] feature.

4. Removes boiler plate coding:

  • Object creation – simplified
  • Collection library – minimal set of methods to handle most scenarios

5. More Features & Less typing

  • Scala creates default code for commonly used behaviors
    • Automatically creates constructors for class
    • Class can have arguments, which can act as argument for default constructor
    • Automatically Getter & Setter Functions for class members
  • Simple File Handling & IO
    • No need to worry about [File/Input/Output/Buffer] [Stream / Reader / Writer] (Eg. Input Stream Reader => Buffer Reader => ReadInt )
    • Simple functions for input and output statements ( Because Scala supports functions)
  • More language features
    • Easy to create Singleton – Object without a Class definition
    • No primitive data type – All data types of objects : Byte, Char, Int, Long, Double, Float and String.
  • Less typing – Each key stroke is valuable
    • No semicolon
    • No return statement for functions (Every Scala Statement is an Expression which returns a value)

Summary

After the initial learning curve, scala improves the productivity of the engineers.  Since scala introduces some new syntax, new symbols into the programming the initial learning curve is slightly bigger than learning other modern languages.  At the same time, if the engineer is experienced Java programmer, they will greatly appreciate the features of the scala language.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s