• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Scala 2.10
 

Scala 2.10

on

  • 589 views

Presentation about new features of Scala 2.10. It was presented by Jakub Janeček at the May's Czech Scala Enthusiasts meetup held at Faculty of Information Technology in Prague.

Presentation about new features of Scala 2.10. It was presented by Jakub Janeček at the May's Czech Scala Enthusiasts meetup held at Faculty of Information Technology in Prague.

Statistics

Views

Total Views
589
Views on SlideShare
586
Embed Views
3

Actions

Likes
1
Downloads
10
Comments
0

1 Embed 3

https://twitter.com 3

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Scala 2.10 Scala 2.10 Presentation Transcript

    • Scala 2.10Czech Scala EnthusiastsMay 28th 2013Jakub Janeček
    • What does it bring?
    • Language Modularization
    • Language Modularization•  some features are confusing,“dangerous” orstill experimental
    • Language Modularization•  some features are confusing,“dangerous” orstill experimental•  since 2.10 they have to be explicitly enabled(otherwise warning or error is emitted)
    • Language Modularization•  some features are confusing,“dangerous” orstill experimental•  since 2.10 they have to be explicitly enabled(otherwise warning or error is emitted)•  for example:– implicit conversions
    • Language Modularization•  some features are confusing,“dangerous” orstill experimental•  since 2.10 they have to be explicitly enabled(otherwise warning or error is emitted)•  for example:– implicit conversions– macros
    • Example: Postfix OperatorsList(1, 2, 3) reverse
    • Example: Postfix OperatorsList(1, 2, 3) reverseimport language.postfixOps
    • Example: Postfix OperatorsList(1, 2, 3) reverse> scalac –language:postfixOps
    • What does it bring?
    • String Interpolation
    • String Interpolation•  Remember?"1 + 1 = " + (1 + 1)
    • String Interpolation•  Remember?"1 + 1 = " + (1 + 1)•  No more!s"1 + 1 = ${1 + 1}"
    • String Interpolation"1 + 1 = " + (1 + 1)•  No more!s"1 + 1 = ${1 + 1}"Standard interpolatorWe also have f and rawEscape character•  Remember?
    • Example: Interpolator revdef rev(args: Any*): String = …•  Extension method of StringContext:
    • Example: Interpolator revdef rev(args: Any*): String = …rev”this will be reversed"•  Extension method of StringContext:
    • What does it bring?
    • “value”Value Classes
    • Value Classes•  allow extends AnyVal
    • Value Classes•  allow extends AnyVal•  compiler can usually avoid allocating runtimeobjects à performance with type safety
    • Value Classes•  allow extends AnyVal•  compiler can usually avoid allocating runtimeobjects à performance with type safety•  they have limitations
    • Example: MyIntcase class MyInt(val underlying: Int)extends AnyVal {def plusOne = MyInt(underlying + 1)}MyInt(5).plusOne
    • Example: MyIntcase class MyInt(val underlying: Int)extends AnyVal {def plusOne = MyInt(underlying + 1)}MyInt(5).plusOne
    • Example: MyIntcase class MyInt(val underlying: Int)extends AnyVal {def plusOne = MyInt(underlying + 1)}MyInt(5).plusOneMyInt$.MODULE$.plusOne$extension(5)
    • What does it bring?
    • Cute Puppy
    • Cute Puppy Implicit Classes
    • Implicit Classes•  remove a lot of boilerplate code
    • Implicit Classes•  remove a lot of boilerplate code•  class must have only one parameter in itsconstructors first parameter list
    • Implicit Classes•  remove a lot of boilerplate code•  class must have only one parameter in itsconstructors first parameter list•  implicit conversion is generated
    • Implicit Classes•  remove a lot of boilerplate code•  class must have only one parameter in itsconstructors first parameter list•  implicit conversion is generated•  often used withValue Classes
    • Implicit Classes•  remove a lot of boilerplate code•  class must have only one parameter in itsconstructors first parameter list•  implicit conversion is generated•  often used withValue Classes•  must be defined inside other class/trait/object
    • Example: MyIntimplicit class MyInt(val i: Int)extends AnyVal {def plusOne = i + 1}2.plusOne
    • Example: MyIntimplicit class MyInt(val i: Int)extends AnyVal {def plusOne = i + 1}2.plusOne
    • What does it bring?
    • Trait Dynamic
    • Trait Dynamic•  allows calling methods not existing in the statictype
    • Trait Dynamic•  allows calling methods not existing in the statictype•  useful for DSLs and integration with dynamiclanguages
    • Trait Dynamic•  allows calling methods not existing in the statictype•  useful for DSLs and integration with dynamiclanguages•  empty marker trait Dynamic
    • Trait Dynamic•  allows calling methods not existing in the statictype•  useful for DSLs and integration with dynamiclanguages•  empty marker trait Dynamic•  if type check fails it is rewritten to one of–  applyDynamic–  applyDynamicNamed–  selectDynamic–  updateDynamic
    • Example: Dynamic DBcase class Record(id: Long, name: String)
    • Example: Dynamic DBcase class Record(id: Long, name: String)object Record extends Dynamic {def applyDynamic(sel: String)(arg: Any): Record = …}
    • Example: Dynamic DBcase class Record(id: Long, name: String)object Record extends Dynamic {def applyDynamic(sel: String)(arg: Any): Record = …}Record.findById(1)
    • Example: Dynamic DBcase class Record(id: Long, name: String)object Record extends Dynamic {def applyDynamic(sel: String)(arg: Any): Record = …}Record.findById(1)Record.applyDynamic("findById")(1)
    • What does it bring?
    • Macros
    • Macros•  compile-time metaprogramming
    • Macros•  compile-time metaprogramming•  basically functions that are loaded andexecuted by the compiler
    • Macros•  compile-time metaprogramming•  basically functions that are loaded andexecuted by the compiler– given context and AST of arguments
    • Macros•  compile-time metaprogramming•  basically functions that are loaded andexecuted by the compiler– given context and AST of arguments– returned AST inlined and type-checked at thecall site
    • Example: logginglogger.debug(s"${expensive} message!")
    • Example: loggingif (logger.isDebugEnabled) {logger.debug(s"${expensive} message!")}
    • Example: loggingif (logger.isDebugEnabled) {logger.debug(s"${expensive} message!")}macro
    • Example: loggingif (logger.isDebugEnabled) {logger.debug(s"${expensive} message!")}macro expanded at compile-time
    • And last…
    • Triple Question Markdef complexMethod() = ???•  Defined in class Predefdef ??? : Nothing = throw new NotImplementedError