Introduction to Scala
Upcoming SlideShare
Loading in...5
×
 

Introduction to Scala

on

  • 2,998 views

An introduction to Scala features. See associated code at http://tr.im/jA6A

An introduction to Scala features. See associated code at http://tr.im/jA6A

Statistics

Views

Total Views
2,998
Views on SlideShare
2,973
Embed Views
25

Actions

Likes
3
Downloads
48
Comments
1

4 Embeds 25

http://www.linkedin.com 16
http://www.slideshare.net 5
http://www.e-presentations.us 3
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

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…
  • Get example code at http://tr.im/jA6A
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Introduction to Scala 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