The Evolution of Scala / Scala進化論

Download The Evolution of Scala / Scala進化論

Post on 24-Jan-2015

1.948 views

Category:

Software

2 download

Embed Size (px)

DESCRIPTION

Presentation material with Japanese subs, by Prof. Martin Odersky at ScalaMatsuri 2014 http://scalamatsuri.org/en/

TRANSCRIPT

<ul><li> 1. The Evolution Of ScalaMartin OderskyEPFL and TypesafeScala </li></ul> <p> 2. 10 Years of ScalaScala 10 3. Pre History1980s Modula-2, Oberon1990-95 Functional Programming1995-98 Pizza1998-99 GJ, javac2000-02 Functional Nets, Funnel3Scala 4. 4Minimal programming language based on type members and functional nets (a variant of join calculus)Analogous to Pict (Pierce and Turner 2001) for Pi-calculus. (join) 5. A Minimal LanguageIdea of Funnel: Show that we can build a general programming language that can be understood as thin syntactic sugar over a core calculus.General: OO, functional + imperative, concurrentCore calculus: Functional netsSugar: Records, Lambdas, Type members.Wrote some programs (including parts of the Funnel library) in Funnel.Quickly became apparent that encodings suck:Confusing for beginnersBoring to do them over and over again for experts5: 6. Motivation for ScalaGrew out of FunnelWanted to show that we can do a practical combination of OOP and FP.What got dropped:Concurrency was relegated to librariesNo tight connection between language and core calculus (fragments were studied in the Obj paper and others.)What got added:Native object and class model, Java interop, XML literals (!).6Scala : OOP FP 7. Why a New Language?The OO dogma ruled then: Encapsulate mutable data with methods.Infamous example: Java beans.There was no place for functional programming in this.New at the time: Webservices that process immutable (semi-)structured data.Service sees the data from the outside.Functional programming supports that view, e.g. using pattern matching, recursion.Rationale given: Would be good to have a new FP language for webservices7OOwebFP 8. 8Really, Why a new Language?The work on Scala was motivated by two hypotheses:Hypothesis 1: A general-purpose language needs to be scalable; the same concepts should describe small as well as large parts.Hypothesis 2: Scalability can be achieved by unifying and generalizing functional and object-oriented programming concepts.1: 2: OOP FP 9. How That Worked Out9(from:James Iry: A Brief, Incomplete, and Mostly Wrong History of Programming Languages)OOFP () 10. Scala and PizzaPizza (Odersky and Wadler 96) was another language on the JVM that added functional elements to Java:algebraic datatypes and pattern matchingfunction valuesgenericsScala was more ambitious:More innovation on the OOP sideMore functional, e.g. immutable values, by-name parameters,Better integration of functional/oop, e.g. case classes.Not backwards compatible with Java10Pizza: Scala: OOPFP 11. Java Features Not kept in ScalapublicstaticvoidEnumerationsAnnotation SyntaxWildcard typesRaw typesPrimitive typesArray typesDefinite assignment rules11Statements:breakcontinuesynchronizedassertfor (C-style)try (resource)super(...)Expressions:primitive operatorscast syntaxconditional x ? y : zarray selection a[i]Java 12. Scala Beginnings2003: First internal useto teach Functional and Logic Programming Course at EPFL. (2nd year, ~ 150 participants),despite being not really ready for the task.2004: Official announcement of Scala 1.0First vocal outside users: Miles Sabin, John Pretty @ SygnecaTogether with Iulian Dragos and myself these are probably the only people who have used Scala continuously for 10 years.122003 EPFL 2004 Scala 1.0 13. Scala Reloaded2006: Scala 2.0 releasedCompiler written in ScalaFollowed the cake-pattern described Scalable Component Abstractions [Odersky&amp;Zenger 05].A few new features:Semicolon inference (!)Generalization of implicits and traitsAutomatically added empty parameter lists ()Additions in 2.1, 2.2:Qualified access: private[C], protected[C]Multi-line string literals: this is a line and this is anotherProcedure syntax: def sort(xs: Array[T]) {...}132.0 Scala : implicit trait 14. Scala Reloaded2006: Scala 2.0 releasedCompiler written in ScalaFollowed the cake-pattern described Scalable Component Abstractions [Odersky&amp;Zenger 05].A few new features:Semicolon inference (!)Generalization of implicits and traitsAutomatically added empty parameter lists ()Additions in 2.1, 2.2:Qualified access: private[C], protected[C]Multi-line string literals: this is a line and this is anotherProcedure syntax: def sort(xs: Array[T]) {...}14() 15. Learning from ExperienceScala 1.x hadParameterless methods supporting the uniform access principle.def length: Int = ...Partially applied functions that are always eta-expanded:def sum(f: Int =&gt; Int)(bounds: Range) = ...val sumSquares = sum(x =&gt; x*x)The combination of these two was a source of common pitfalls:println(abc.length) // prints: 151.x eta 16. Avoiding the Pitfalls1.Auto-add () for references f is to nullary functionsdef f() = ...2.Eta-expand only ifexpected type is a functionormissing parameters are specified with `_16f () _ eta 17. The Growth Year2007: Scala 2.3-2.7 add lots of new features:Extractors object Email { def unapply ... } case Email(name, domain) =&gt; ...Tuples (1, a, true)Assignment operators +=, *=, ..._ notation for functions (_ + 1)Early initialization object Foo extends { val x = 3 } with SomeTraitLazy values lazy val rest = f()Higher-kinded types class Functor[F[_]] { ... }Structural types { val key: String }Existential types Map[T, T] forSome { type T }172007: 18. Why The Rapid Growth?People asked for itIf Scala only had this one new feature, I could use it in my organizationPeople volunteered to do itLots of thoughtful suggestions on the mailing list.PhD students were keen to see their thesis work applied.18ML 19. Community Formation2007: Lift web framework launched.2008: First Scala liftoff unconference (50 particants)Twitter goes public with Scala, hype starts2009: More Scala liftoffs.2010-14: Scala Days2010 EPFL 180 participants2011 Stanford 2802012 London 4002013 New York 500 Scala Workshop Montellier2014 Berlin 800 Scala Symposium UppsalaLots of other meetups and conferences19 20. Scala 2.8 and 2.9: Consolidation2010: Scala 2.8, withNew collections with bitrot prevention.Fixed leaky array model.New semantics of nested packages.Better type inference for implicit resolutionLots of bug-fixes2011: Scala 2.9, withParallel collectionsSpecial trait DelayedInit, used in AppTrait Dynamic, to interface with dynamic languages202010: 2.8 2011: 2.9 21. Scala 2.10: Differentiation2012: Scala 2.10, withNew features, added through the Scala Improvement Process (SIPs):Value classes class Meter(x: Long) extends AnyValImplicit classes implicit class StringOps(s: String)String interpolation syou have $n new callsExperimental featuresMacros def await(x: Future[T]) = macro ...ReflectionThese are only enabled when compiling with XexperimentalLanguage imports require explicit enabling of some features available previously.212012SIP 22. Features Controlled by SIP-18From language:Implicit ConversionsDynamicPostfix OperatorsDynamic dispatch on structural typesExistential typesHigher-kinded typesFrom language.experimentalMacros22SIP-18 23. Now: Scala 2.11Smaller:broke out parts of libraries into separate modulesFasterBetter incremental compilationStronger:Lots of bug fixes, tooling improvements23Scala 2.11: 24. Now: Scala.JSWhy a Scala for Javascript?JS is becoming ubiquitous.Desire to use the same language on client and server.But not everybody likes Javascript or dynamic languages.Scala.JS profits from Scalas tradition of interoperating with a host language through very general abstractions.Can combine JS DOM and Scala collections.For the young age of the project, very mature and well- received.24JS Scala.JS Scala 25. InvariantsIn all this evolution, what stays constant?What are some of the essential traits that make Scala what it is?25?Scala ? 26. 1st Invariant: A Scalable LanguageInstead of providing lots of features in the language, have the right abstractions so that they can be provided in libraries.This has worked quite well so far.It implicitly trusts programmers and library designers to do the right thing, or at least the community to sort things out.261: 27. Libraries on top of Scala27SBTChiselSparkSprayKafkaAkkaScalaTestSquerylSpecsshapelessScalazSlickScala 28. Growable = Good?In fact, its a double edged sword.DSLs can fracture the user community (The Lisp curse)Besides, no language is liked by everyone, no matter whether its a DSL or general purpose.Host languages get the blame for the DSLs they embed.Growable is great for experimentation.But it demands conformity and discipline for large scale production use.28DSL 29. Scalas core is its type system.Most of the advanced types concepts are about flexibility, less so about safety.2nd Invariant: Its about the Types29Flexibility / Ease of UseSafetyScalaTrend in Type-systemsGoals of PL design2: 30. Stunted Evolutionnull - The Million Dollar MistakeWhy does Scala not have null-safety?We had plans to do ityou can see the traces in the stdlib with marker trait NotNull.But by then everybody was using already Option.So NPEs are actually quite rare in Scala code.Dont want two ways to do the same thing.30null Option 31. Whats Next?Scala 2.12 will be a fairly conservative evolution of 2.11Main feature: Java 8 interop.Scala and Java lambdas can understand each otherSAM method convention added to ScalaShould make use of Java 8 streamsDefault methods for traits?312.12 Java 8 interop 32. And After That?Main Goals: Make the language and its librariessimpler to understand,more robust,better performingWant to continue to make it the language of choice for smart kids.32 33. Scala AidaWill concentrate on the standard library.Reduce reliance on inheritanceMake all default collections immutable (e.g. scala.Seq will be an alias of scala.immutable.Seq)Other small cleanups that are possible with a rewriting step (e.g. rename mapValues)Projects which might make it if they mature fast enough:scala.meta, the new, simplified approach to macros and reflection.Collection fusion in the style of ScalaBlitzBetter specialization through miniboxing.33: Aida 34. Scala Don GiovanniConcentrates on the languageSimple foundations:A single fundamental concept - type members can give precise meaning to generics, existential types, and higher-kinded types.Intersection and union types.Theoretical foundations given by minimal core calculus (DOT).Cleaned-up syntax:Trait parameters instead of early definition syntaxXML string interpolation instead of XML literalsProcedure syntax is dropped.Simplified and unified type syntax for all forms of information elision, forSome syntax is eliminated.34: Don GiovanniDOT 35. Scala Don GiovanniRemoving puzzlers:Result types mandatory for implicit definitions.Inherited explicit result types take precedence over locally- inferred ones.String + needs explicit enabling.Avoid surprising behavior of auto-tupling.Backwards compatibility:A migration tool will upgrade sources automatically.Should work for almost all commonly used code.Will not generally work for code using XexperimentalBut we aim to have features that can support analogous functionality.35 36. The Growth Year, RevisitedExtractors object Email { def unapply ... } case Email(name, domain) =&gt; ...Tuples (1, a, true) Assignment operators +=, *=, ++= Annotations @volatile, @deprecated _ notation for functions (_ + 1) Early initialization object Foo extends { val x = 3 } with SomeTraitHigher-kinded types class Functor[F[_]] { ... } Structural types { val key: String } Lazy values lazy val rest = f() Existential types Map[T, T] forSome { type T } 36 37. ConclusionLanguages are not cast in stone; they evolve whether you like it or not.Community mattersCommunity will take a language where you never expected it to go.In the end languages are as much social phenomena as technical ones.37 </p>