who am i? - intertechtime for the bad stuff... you didn't think i'd forget about that, did...

Post on 31-May-2020

1 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Who am I?

● Harlan Iverson.● Programming enthusiast.● Seeker of truth.● Imperfect.

● I'll be wrong about some things. Please correct me if you can.

P.S...

● I hate boring presentations. Please, engage and stay awake!

● Mental note: every slide ends with 'what else?'

My experience in general

● Many JEE 5 web projects● A huge Java app. Focus on rules and unit

testing.● A few large Javascript apps.● A lot of networking stuff.● LOTS of tinkering with everything.

● I love Open Source

My experience with Scala

● Played with Lift.● Integrated with Spring and JEE.● Have never used Scala in production.

● “I'm just trying to make some fun.”

Who are you?

● Programmer?● Java?● With a thing on the side?● ...looking for a thing on the side?● With a dynamic language?● Scala? :D

What is Scala?

● Programming language

● Designed by Martin Odersky

● Short for Scalable Language.

● Skay-lah, Skah-lah. It doesn't matter; OP says so.

– Skay-lay? Probably not

● First appeared in 2003.

● 2.0 appeared in 2006.

● Currently 2.7.7, appeared 6 days ago.

● Many dynamic features, but compiles to static code.● Functional-object hybrid

● Runs in the JVM

● Open Source

● Known best for concurrency with Actors

Why care about Scala?

● Has exciting features.● Tackles XML and Concurrency in interesting ways.

● Ability to slowly migrate from Java● Add or port individual classes to Scala

● Use Java classes directly

● Compiles to Java byte code.● Your entire ecosystem is there for the taking. Just add one jar.

● Has a passionate community.● My lifetime earnings from Scala: $0.

● But my soul is on top of a pyramid scheme.

● Lots of momentum behind alternative JVM languages.● It is a GREAT platform, as we all know :)

● The secret is getting out.

What about Groovy?

● Groovy is probably cool.● Anyone worked with it?

● "I can honestly say if someone had shown me the Programming in Scala book [...] back in 2003 I'd probably have never created Groovy." -James Strachan (creator of Groovy)● Sounds compelling.

Language Features

● There are a lot. I will miss some, and not fully understand others.

● Fully Object Oriented● Functional● Dynamic● In general the language is lean. Functionality is

added through libraries.

Compare to Java

● Statically typed● Compile time checking

● Supports class inheritance as we Java folks know it... with a few tweaks.

● Uses Java interfaces for List, Set, Map.● Supports Generics and Annotations

● Annotation support is being revamped in 2.8

Contrast to Java

● Type inference● No primitives

● ... as far as the programmer knows. But the compiler is smart.

● No static● Classes can have companion objects.

● No final● var vs. val

● Public by default● No class / file connection● Semi-colons are optional

Wanna see?

Object oriented

● implicit def

● package

● import ● on Objects● in lexical scopes

● Traits ● Mixin inheritance

● Option● the end of null

● Operator overloading● Friendly to DSLs. But be careful!

Infamous C++ features

● I might as well address these first.● Multiple inheritance

● Not so evil in Scala.● Coherent strategy means you know exactly what

you're getting from where.● ... ruby programmers like it (mixin)!

● Infix/Postfix operator overloading● Yea, avoid it unless you're writing a DSL.

Scala is statically typed.

● It is powerful like a dynamic language.● But it isn't scary like a dynamically typed

language.● Namely: you don't need to unit test for typos.

● Compiles to normal Java byte code.

Normal byte code?

● Groovy/JRuby/Jython use reflection and have a 'runtime' to help out.

● Scala does not. It has a language library.● Yes, Scala's multiple inheritance and dynamic

goodness compile to static Java classes!● Fire up javap, see for yourself.● Performance

Oh, performance.

● On par with Java code.● I don't need to convince you that Java is fast.

● Or hard to accurately benchmark.

● But for the record...

Quicksort

100,000 integers

Java: 45msScala: 56ms

Groovy: 12800ms

Reference provided at the end

Ray Tracing

● Java vs. Scala vs. Groovy● Granted you probably won't ray trace in

Groovy...

ray.java 12.89sray.scala 11.224sray.groovy 2h 31m 42s

●LISPiness

● Closures

● Lambdas (functions as objects)

● Cool functional list operations● Map, filter, fold, etc

● Pattern matching● Case Classes● XML

● For/sequence comprehensions

● Partial function application

● Higher order functions

● Love or hate them, no parentheses.

Source: xkcd.com

Sorry Clojure

Case Classes

● Shorthand creates few things automatically● Thanks, Scala.

● Extractor Objects ● unapply() as inverse of apply()

● Mutators for constructor arguments● Function for creation without new● There are also case Objects.

Libraries

● Actors● XML● Collections

Actors

● Based on academic idea for parallel programming● Thread or Event based● Similar style to JMS messaging ● Uses Fork/Join internally, being included in Java 7● There is a clustered/fault-tolerant implementation that

uses Terracotta● Interesting implication for web applications...

● more on that soon

Actors

XML

● XML is part of the language syntax ● (thanks to infix/postfix operator overloading?)

● Pattern matching● Schema2src● Pull parsing doesn't work well● Can't use pattern matching on non-scala.xml

nodes.● Not surprising, but can be inconvenient.

Collections

● Being a functional/object hybrid is a tough job.● Mutable

● Good for OO style

● Immutable● Good for FP style and concurrency

● Java Compatibility (JCL)● Typically not used directly, as conversion can

happen implicitly

Can I still use my tools?

● Yes!● Scala compiles to regular Java byte code.● Works in Google App Engine

Integration with Java Tools

● Spring MVC● Java EE 6● Maven

● In the central repo● There is also a scala plugin

● JRebel● Free license for Scala developers

● Mocking frameworks● The debugger

● Since it's legit Java byte code.

Some cool Scala stuff

● Lift● Interesting COMET support via Actors● Easy to get started through Maven archetype● All the advantages of being in a JVM

● ScalaTest● Integrates several testing styles into one

package● Can be used for Java or Scala code● Has a DSL for Spec style testing

IDE Support

● This is not the strongest point.● Netbeans, IntelliJ IDEA, Eclipse plugins.● But they lack support for Scala-specific● Netbeans is what I know

● infix/postfix and unary operator syntax detection● No auto-complete for Scala classes in Java code.● examples...

Time for the bad stuff...

● You didn't think I'd forget about that, did you?

● New language, few established conventions

● Liberal syntax means bad code can be REALLY bad code● But at least you know it does something since it is statically typed?

● Java interop isn't as pretty as plain Scala● Namely: need to check for nulls :(● Annotations don't work well in 2.7; flawless in 2.8.

● Binary / language compatibility and core feature stability● It has changed with minor versions

● XML Library is awesome but doesn't support pluggable parsers / serializers /etc.

Getting Started

● Run it in your browser.● http://simplyscala.com● (runs in Google App Engine)

● Download it● http://scala-lang.org

● Get an IDE plugin● http://scala-lang.org/node/91

Discuss!

Source: http://blogs.usyd.edu.au/theoryandpractice/2007/02/chapter_ten_aristocles_plato.html

References

● A Tour of Scala

● http://www.scala-lang.org/node/104

● Quicksort Benchmark

● http://stronglytypedblog.blogspot.com/2009/07/java-vs-scala-vs-groovy-performance.html

● Ray Tracing Benchmark

● http://dmy999.com/article/26/scala-vs-groovy-static-typing-is-key-to-performance

● Scala XML

● http://www.ibm.com/developerworks/library/x-scalaxml/

● Fork/Join in Scala / Java 7

● http://www.infoq.com/news/2008/03/fork_join

● Scala Thread-less Concurrency

● http://java.dzone.com/articles/scala-threadless-concurrent

● Scala Collections for the Easily Bored

● http://www.codecommit.com/blog/scala/scala-collections-for-the-easily-bored-part-1

Resources

● ScalaTest● http://www.scalatest.org/

● Lift● http://liftweb.net/

top related