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

37

Upload: others

Post on 31-May-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Who am I? - IntertechTime 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
Page 2: Who am I? - IntertechTime 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

Who am I?

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

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

Page 3: Who am I? - IntertechTime 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

P.S...

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

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

Page 4: Who am I? - IntertechTime 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

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

Page 5: Who am I? - IntertechTime 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

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.”

Page 6: Who am I? - IntertechTime 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

Who are you?

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

Page 7: Who am I? - IntertechTime 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

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

Page 8: Who am I? - IntertechTime 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

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.

Page 9: Who am I? - IntertechTime 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

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.

Page 10: Who am I? - IntertechTime 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

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.

Page 11: Who am I? - IntertechTime 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

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

Page 12: Who am I? - IntertechTime 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

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

Page 13: Who am I? - IntertechTime 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

Wanna see?

Page 14: Who am I? - IntertechTime 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

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!

Page 15: Who am I? - IntertechTime 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

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.

Page 16: Who am I? - IntertechTime 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

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.

Page 17: Who am I? - IntertechTime 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

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

Page 18: Who am I? - IntertechTime 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

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...

Page 19: Who am I? - IntertechTime 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

Quicksort

100,000 integers

Java: 45msScala: 56ms

Groovy: 12800ms

Reference provided at the end

Page 20: Who am I? - IntertechTime 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

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

Page 21: Who am I? - IntertechTime 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

●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.

Page 22: Who am I? - IntertechTime 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

Source: xkcd.com

Sorry Clojure

Page 23: Who am I? - IntertechTime 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

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.

Page 24: Who am I? - IntertechTime 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

Libraries

● Actors● XML● Collections

Page 25: Who am I? - IntertechTime 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

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

Page 26: Who am I? - IntertechTime 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

Actors

Page 27: Who am I? - IntertechTime 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

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.

Page 28: Who am I? - IntertechTime 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

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

Page 29: Who am I? - IntertechTime 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

Can I still use my tools?

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

Page 30: Who am I? - IntertechTime 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

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.

Page 31: Who am I? - IntertechTime 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

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

Page 32: Who am I? - IntertechTime 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

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...

Page 33: Who am I? - IntertechTime 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

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.

Page 34: Who am I? - IntertechTime 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

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

Page 35: Who am I? - IntertechTime 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

Discuss!

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

Page 36: Who am I? - IntertechTime 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

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

Page 37: Who am I? - IntertechTime 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

Resources

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

● Lift● http://liftweb.net/