scala overview infx 1616

6

Click here to load reader

Upload: patrick-walter

Post on 23-Jan-2018

132 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Scala Overview INFX 1616

The Scala Programming Language: An Overview

The perfect blend of object-oriented and functional programming makes for great

scalability.

Patrick Walter

1/29/2016

Page 2: Scala Overview INFX 1616

Programming languages come in many different shapes and sizes. Sometimes they are

designed for a particular application and other times they are made to be a general purpose

language fit for many applications. A programming languages’ paradigm is the fundamental

style of the language which also sometimes defines the capabilities of the language. Peter Van

Roy formally defines a programming paradigm as “an approach to programming a computer

based on a mathematical theory or a coherent set of principles.” (Van Roy, n.d.) While some

languages follow one paradigm, many tend to support multiple paradigms. Almost all

programming languages fall under four main paradigms. The four main programming

paradigms are imperative, functional, logical, and object-oriented. (Nørmark, 2013) An

interesting example of a language that supports multiple programming paradigms is Scala

Programming Language. Scala is a functional object-oriented language which runs on the Java

Virtual Machine and was developed at the Programming Methods Laboratory at École

Polytechnique Fédérale de Lausanne. Scala is a highly functional, scalable, and multifaceted

programming language with many strengths and weaknesses.

Unlike Java and C#, Scala is a purely object-oriented language. By definition, this means

that every value is an object and every operation is a message send. (Odersky, et al., 2006)

Being an object- oriented language, Scala uses a class hierarchy that has a root of Scala.Any

and then splits into two main types, value classes and reference classes. Reference classes are

represented by pointers and value classes are represented directly in memory with any need

for dereference. (Odersky, et al., 2006) As mentioned before, part of this unified object model

includes the notion that all operations are message sends, meaning that they invoke a method.

While many operations in Scala are predefined there is the ability to create user-defined

Page 3: Scala Overview INFX 1616

operations or enhance predefined library operations. (Odersky, et al., 2006) Alone these

attributes of Scala make it very similar to many object-oriented languages such as Java, which it

can actually seamlessly interact with. (Odersky, et al., 2006) However, unlike Java, Scala is also a

fully functional language. All operations in Scala are values. This means that functions, or

methods, can be passed as parameters to other functions or returned as a result. This also

means that all functions are objects since all values in Scala are objects and functions

themselves are values. (Odersky, et al., 2006) The combination of these concepts makes an

easily scalable language, as described by Scala’s developers, “The two programming styles have

complementary strengths when it comes to scalability. Scala’s functional programming

constructs make it easy to build interesting things quickly from simple parts. Its object-oriented

constructs make it easy to structure larger systems and to adapt them to new demands.”

(Odersky, Spoon, & Veners, Scala:A Scalable Language, 2008)

The name for Scala comes from “scalable language”, which means that it is a language

that is designed to not only grow on the users but to grow with the users. (Odersky, Spoon, &

Veners, Scala:A Scalable Language, 2008) From small single user applications, to massive critical

mission applications, Scala is designed to be a versatile language for varying sized systems and

applications. Recently Scala has become increasing important in many big data systems and

projects that use Apache’s Spark and Kafka which are used by companies like Twitter and

LinkedIn. (Mesophere, 2015) However the idea of Scala as a growing language is not only in

terms of its size. Scala is a language that the user may actively adapt and extend to fit their

every need. For example, Scala uses associative maps that are common in scripting languages

but these however these maps are not in the languages syntax. Scala uses library abstractions

Page 4: Scala Overview INFX 1616

to control concepts like associative maps so that they can be extended and adapted by the

user. (Odersky, Spoon, & Veners, 2008) It also supports implicits, operator overloading, and the

ability to enhance libraries of existing methods and classes. (Odersky, et al., 2006)

As mentioned before Scala is similar to the Java Programming Language, so much so

that Java code can be executed within Scala as they both run on the Java Virtual Machine. In

comparison to Java, Scala has a very straightforward and simple syntax. This allows for

significantly less code that is even more human-readable. Inherently immutable objects in Scala

alleviate many thread-safety concerns and its functional paradigm allows for highly functional

programs to be used to implement applications that need to concurrency since all functions are

side effect free. (Ulrich, 2012) While the multi-paradigm versatility and scalability of Scala can

offer many benefits it comes with some costs. Although it’s not a result of the language itself,

the lack of community presence is a downside of all new languages. (Ulrich, 2012) However, if

Scala proves itself to be useful asset its community of experts and followers will grow with time.

Scala is a build to be scalable and adaptable which also has some downsides. In Scala there are

often many ways to do the same thing. The ability to overload operators or enhance or adapt

library methods and classes gives the designer lots of flexibility, it creates many places for

things to go wrong and may create code that is hard to read, trace, and debug. (Moore, 2011)

Due to this perfect blend of two very different programming paradigms, Scala has the

potential to compete with more mainstream object-oriented languages such as Java and C#, or

scripting languages such as Python. In the words of its developers, Scala allows you to

“Construct elegant class hierarchies for maximum code reuse and extensibility, implement their

Page 5: Scala Overview INFX 1616

[behaviour] using higher-order functions. Or anything in-between.” (Scala, n.d.) Scala’s

scalability has be recently getting more recognition in the world of big data to pipeline data

between different points in big data system in many popular social media platforms such as

Twitter and LinkedIn or to be used to control cluster based systems. At the 2012 JavaOne

conference, Scala won the ScriptBowl conference as many developers like its scripting

capabilities. (Odersky, What is Scala, n.d.) Many believe that as Scala becomes more widely

used it will be a valuable asset in a wide variety of applications.

Page 6: Scala Overview INFX 1616

References

Function, O.-O. M. (n.d.). Scala. Retrieved January 29, 2016, from Scala: http://www.scala-

lang.org/index.html

Mesophere, C. (2015, July 24). Learn Everything You Need To Know About Scala And Big Data. Retrieved

January 28, 2015, from Mesophere: https://mesosphere.com/blog/2015/07/24/learn-everything-you-

need-to-know-about-scala-and-big-data-in-oakland/

Moore, J. (2011, September 8). What are the downsides of Scala as a programming language? Retrieved

Janurary 29, 2016, from Quora: https://www.quora.com/What-are-the-downsides-of-Scala-as-a-

programming-language/answer/Justin-Moore

Nørmark, K. (2013, July 2). Aalborg University. Retrieved January 29, 2016, from Overview of the four

main programming paradigms: http://people.cs.aau.dk/~normark/prog3-

03/html/notes/paradigms_themes-paradigm-overview-section.html

Odersky, M. (n.d.). What is Scala. Retrieved January 29, 2016, from Scala: http://www.scala-

lang.org/what-is-scala.html

Odersky, M., Altherr, P., Cremet, V., Dragos, I., Dubochet, G., Emir, B., et al. (2006). An Overview of the

Scala Programming Language. Lausanne, Switzerland: Ecole Polytechnique Federale de Lausanne.

Odersky, M., Spoon, L., & Veners, B. (2008, May 6). Scala:A Scalable Language. Retrieved January 27,

2016, from Artima Developer: http://www.artima.com/scalazine/articles/scalable-language.html

Ulrich, H. (2012, October 23). Pros & Cons of Scala Programming for Agile Software Development.

Retrieved January 29, 2016, from Celerity: http://blog.celerity.com/pros-cons-scala

Van Roy, P. (n.d.). Programming Paradigms for Dummies: What Every Programmer Should Know.

Retrieved January 29, 2016, from Institute of Information and Communications and Communication

Technologies, Electronics and Applied Mathematics:

https://www.info.ucl.ac.be/~pvr/VanRoyChapter.pdf