scala for n00bs by a n00b

19
BRANDON L. GULLA CS722 - FALL 2014 A quick introduction to:

Upload: brandongulla

Post on 13-Jul-2015

146 views

Category:

Technology


0 download

TRANSCRIPT

BRANDON L. GULLA

CS722 - FALL 2014

A quick introduction to:

History of Scala

Founded in 2001 by Martin Odersky at the Ecole Polytechnique Fédérale de Lausanne in France (surprise).

Wanted to create a language to solve functional programming problems from the research/scientific fields while maintaining the awesomeness that comes with object-oriented programming languages such as Java.

Scala's codebase had roots in Martin's previous work named Funnel.

Martin was lazy* though...

*you'll get the pun later.

Java as a foundation.

Odersky decided to create his new language on top

of the Java Virtual Machine.

Scala is actually a library included in the Java

CLASSPATH.

Martin decided to make the Scala language translate into

Java byte code, a instruction set that could be read on

everything from toasters to high-end enterprise work

stations.

Confused?

Java Byte Code, Demystified

What's Scala look like? Hello World!

• Scala source code files are saved as ___.scala just like ___.java

• You compile scala with the scalac tool (included in the scala binary libraries)

But I like bells and whistles...

Scala was born to solve functional problems that mathematicians

and Data-Scientists were facing.

Just because the language is powerful for extremely nerdy problems, it doesn't mean that it can't be pretty too!

Since Scala shares the same VirtualMachine as Java, it can actually

use ANY Java package available, including GUI libraries such as

Swing!

JOptionPane in Scala

But Why Scala? Isn't Java awesome enough?

No!

Well, actually Java is pretty awesome, but you can extend that

awesomeness in Scala by using the same packages!

Example: import apache.commons.io._

Scala was created to meet the increasing scalability concerns of

distributed computing clusters.

Big Data Big Data Big Data.

How is Scala Different?...

Like languages such as SmallTalk and Objective-C, everything in Scala is

an object.

There are no primitives in Scala (int, double, etc) but have been replaced

by Int, Double, Float, etc. Even operators (+,-) are objects and thus can be

re-defined!

Lambda / Anonymous Functions:

Scala allows you to create anonymous or Lambda functions. Lambda functions

are functional definitions that are not bound to an identifier. They are often

passed to another function as an argument. An example is below.

You can actually pass a function as an argument parameter to another

function!

How is Scala Different?...

(continued)

Reduced boilerplate. Map Reduce job in Java takes ~130 lines, but it only takes 4 lines in Scala.

val s = for (x <- 1 to 25 if x*x > 50) yield 2*x

While everything is technically an object, Scala is a strictly-typedprogramming language. This is a huge improvement over previously used programming languages such as python and ruby.

Scala code can be decompiled to readable Java code, with the exception of certain constructor operations.

The return operator is unnecessary in a function (although allowed); the value of the last executed statement or expression is normally the function's value.

Polymorphism in Scala is identical to Java.

How is Scala Different?...

(continued some more )

Functions do not need parenthesis to be called. Function or method

foo() can also be called as just foo and method foo.toString() can

also be called as just foo toString.

Default visibility in Scala is ‘public’.

It's fast.

Scala can be run in an interactive

shell!

Examples

Examples Continued

Future of Scala in Industry

Scala is the Hipster of Programming

Languages

• Who Uses Scala?

Questions?

****( I'm no expert, so be nice)

Scala is open-sourced! Check it out on GitHub (github.com/scala)

Check out books such as Scala for the Java Developer and Scala

for the Impatient.