Introduction to Scala

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

1 comments

Comments 1 - 1 of 1 previous next Post a comment

Post a comment
Embed Video
Edit your comment Cancel

2 Favorites

Introduction to Scala - Presentation Transcript

    • A programming language for the JVM (and .net)
    • Functional / OO hybrid
    • Statically typed
    • Compile to class files
    • Iterpretive Console
    • Flexible syntax
    What is it?
    • 'Scalable Language'
      • On the JVM
      • Integrates with existing libraries
      • Integrates readily with other systems (in code XML & JSON support)
      • Flexible syntax – can be like Java or can move to DSLs and higher abstractions.
    The name
    • Removes Java roadblocks without changing platform or throwing away existing properties
      • Tasks that are difficult or tedious in Java can be simplified with minimal investment in time and tools
    • Rapid development without losing type safety.
    • Java + new language features:
      • Closures, actors, infix operators, case classes, pattern matching, list and map operations, native XML, implicits, defaults, nested elements, no primitives, currying, sequence comprehension, compound types, structural types, function literals … etc
    Why should we care?
    • Code example - Hello World
      • Points of interest:
        • Object keyword
        • Def keyword
        • Assignment of code block to function
        • scala.Console
        • Application trait
    See associated source files at http://tr.im/jA6A HelloWorld.scala & HelloWorldWithTrait.scala
    • Using the basic building blocks, we can compose code that looks and feels similar to today's Java.
      • Though not source compatible. Can't compile Java.
    • Package, import, class, object, trait, var, val, def
    • Code example: Cat
      • Relaxed naming constraints, constructor arg visibility, constructor overload, function definition, implied static typing, val vs var
    The basic building blocks Cat.scala
    • Can be very terse
    • Return type implies type of function
    • Naming is greatly relaxed.
    • Code sample: Rational
      • Symbols as function names -> infix operators, optional 'return' keyword, if statements are ternary, DSLs
    Functions Rational.scala
    • XML is a native datatype
    • Rich XML operations make parsing and creating XML simple.
    • Code sample: NativeXML
      • Eclipse plugin slightly broken – parentheses not required, XML direct in code, nested values, iterated lists, xpath-like functions
    Native XML NativeXML.scala
    • Implicit functions map one type to another
    • Ascribes new functionality to old friends
      • e.g. Make the JDBC library user-friendly
    • Code sample: UpperCaseAwareString
      • RichString already exists
      • Implicit def declaration
      • Multiple impicit defs, but method calls must be unambiguous at compilation
    Extending other classes – Monkey Patching UpperCaseCharAwareString.scala
    • Compile time checked duck typing
    • Can define types based on functions signatures
    • Code sample: Duck
      • Type keyword, multiple method definitions, includes param and return types, can be inlined
    Structural types – Duck Typing Duck.scala
    • More than interfaces
    • Less than classes
    • Act as markers
    • Can have methods
    • Can have constructors
    • Code sample: Bravia
      • Extend abstract or trait, mixins
    Traits Bravia.scala
    • Define combinations of types in contracts
    • Code sample: Chess
      • Compile time type checking for multiple types
    Compound types chess.Chess.scala
    • Case objects are akin to enums
    • Case classes are parameterisable
    • Pattern Matching is akin to switch statement, but more powerful
    • Code sample: Months
      • No new keyword, no params for object - params for class, match & case, _ wildcard, exposed params when matching on classes, also used for exception handling
    Case objects/classes and pattern matching Months.scala
    • Functions are objects. Everything is!
    • Can access parent scope (closure)
    • Can be defined inline ('function literal')
    • Code sample: BookReader
      • Function as a parameter, function knows and can modify instance values, functions defined inline.
    Functions are objects too BookReader.scala
    • Any number of enumerations and filters mixed together to form a new list.
    • Enumerations add values, filters remove them.
    • Lightweight notation
    • Code sample: Condiments
      • Note generics, note also list creation.
    Sequence Comprehensions Condiments.scala
    • Functions with many params can be decomposed into a chain of functions.
    • This is supported and used to construct language extensions.
    • Code sample: AutoResourceManagement
      • Partial function takes var args of Closable type, chained function takes a function that takes no params and returns nothing (Unit), makes AOP mainly redundant, note foreach and exception syntax.
    Currying AutoResourceManagement.scala
    • www.scala-lang.org
      • Binaries, source, tutorials and doco
    • [email_address] - mailing list
    • http://groups.google.com/group/scala-melb - Scala Melbourne User Group
    • http://tr.im/jzQK – Scala for Java devs.
    Getting started
    • Testing
      • http://www.artima.com/scalatest/
      • http://code.google.com/p/specs/
      • http://code.google.com/p/scalacheck/
    • Building
      • http://code.google.com/p/simple-build-tool/
    • IDE Support
      • Eclipse, NetBeans, IntelliJ
    Tools
SlideShare Zeitgeist 2009

+ SynessoSynesso Nominate

custom

939 views, 2 favs, 0 embeds more stats

An introduction to Scala features. See associated c more

More info about this document

© All Rights Reserved

Go to text version

  • Total Views 939
    • 939 on SlideShare
    • 0 from embeds
  • Comments 1
  • Favorites 2
  • Downloads 28
Most viewed embeds

more

All embeds

less

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

Cancel
File a copyright complaint
Having problems? Go to our helpdesk?

Categories