What makes Scala scalable?

Scalability of a language is effected by some factors ranging from syntax details to component abstraction construct. The main aspect of scala that makes it scalable is that it is a combination of both object-oriented and functional programming. It has good support for both the programming constructs like high-order functions, tail-call optimization, immutable values, pattern matching, polymorphism, abstraction, inheritance etc. Scala also includes its own interpreter which can be used to execute instruction directly, without previous compiling. Another key feature is parallel collections library designed to help developers address parallel programming patterns.
Some Another features are as follow :

  • Scala is concise. it provides a better support for backend operations. Scala programs tend to be short upto a factor of 10 compared to Java. It avoids code that shows up again and again in order to get some result that burdens Java program.
    Example: In Java, a class with constructor looks like:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    class Geek 
        // data members of the class. 
        String name; 
        int id; 
        
        // contructor would initialized data members 
        // with the values of passed arguments while 
        // object of that class created. 
        Geek(String name, int id) 
        
            this.name = name; 
            this.id = id; 
        

    chevron_right

    
    

    In Scala it’ll be written as:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    class Geek(name: String, id: Int) {}

    chevron_right

    
    

  • Scala helps you manage complexity by letting we raise the level of abstraction in the interfaces we design. Java treats stings as low-level entities that are stepped through character by character in a loop. The Scala code treats same string as higher-level sequences of character that can be queried. Scala provides the facility to develop the frameworks and libraries.
    Example: In Java,to find the first uppercase letter.

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // Function to find string which has 
       // first character of each word. 
       static char first(String str) 
       
           for (int i = 0; i < str.length(); i++) 
               if (Character.isUpperCase(str.charAt(i))) 
                   return str.charAt(i); 
           return 0
       

    chevron_right

    
    

    In scala it will be written as:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    val first = str.exists(_.isUpperCase) 

    chevron_right

    
    

    In Java code, string is low level entities whereas in Scala same string is treated as high level entities. In Scala _.isUpperCase is a function literals.

  • It supports static typing in which computations are formed as statements that change program state at compile time. It is an approach that can provide improved runtime efficiencies. By the values they hold and compute a static type system classifies variables and expressions. A system of nested class types much like Java’s, it allows us to parameterize types with generics, to hide details using abstract types, and by using intersections it combine types .
  • It is implemented on Java Virtual Machine(JVM) so it can access all Java methods and fields, inherit from Java classes and implement Java interface. It does not require any special syntax, explicit interface descriptions, or glue code. It uses Java’s types and dresses them up to look nicer. The Scala compiler compiles the program into .class file, containing the Bytecode that can be executed by JVM. All the classes of Java SDK can be used by Scala. With the help of Scala user can customize the Java classes.


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.