• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Intro To Scala
 

Intro To Scala

on

  • 960 views

High level overview of some Scala concepts.

High level overview of some Scala concepts.

Statistics

Views

Total Views
960
Views on SlideShare
955
Embed Views
5

Actions

Likes
0
Downloads
0
Comments
0

2 Embeds 5

http://www.linkedin.com 4
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

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

    Intro To Scala Intro To Scala Presentation Transcript

    • Intro to Scala
    • What is Scala?
      • Hybrid Language, blending OO and FP
      • Statically Typed
      • Runs on the JVM
    • OO Features
    • Classes
      • No need to add getters/setters for parameters
      Default Constructor
    • Objects
      • No Concept of Static in Scala
      • Standalone
      • Companion
    • Standalone Object Calling the method
    • Companion Object
      • Object and Class must have the same name
      • Declared in the same file with the class def is contained within the object def
    • Methods Don’t need a return statement. The last line of the method is What gets returned.
    • Imports & Packages Import Statements Scoped Packages
    • Type System
    • Type System
      • Java
      • List<String>
      • Contravariant
        • List<T super Foo>
      • Covariant
        • List<T extends Foo>
      • Supplied when a class is used
      • Scala
      • List[String]
      • Contravariant
        • List[-T]
      • Covariant
        • List[+T]
      • Supplied when a class is defined
    • Type System
      • Covariant: narrower -> wider.
        • Double -> float
      • Contravariant: wider -> narrower
        • Float -> double
      • Invariant: Cannot convert
    • Type System
    • Type System Call drawAll on Canvas with a list of circles
    • Type System
      • Looks interesting but what's the catch?
        • All examples used immutable types. When working with mutable types in Scala they have to be invariant.
      Immutable Mutable
    • Implicits
    • Implicit Conversion Implicit Conversions provide a nice way to extend libraries and functionality without changing the original code. Example: Add methods to String
    • Implicit Conversion Must Import the Object in order to use the new methods It looks like we are calling the repeat method on the string class!
    • Implicit Parameters Implicit parameters are used in a functions parameter list to denote that the parameter Is optional. Declare the parameter to be implicit Label the list as implicit so the compiler knows Which list to use.
    • Traits
    • Traits Like an interface with an implementation. Traits are mixed into classes by using the keyword with. Allowed to have abstract as well as concrete implementation of methods. Version 1
    • Traits Version 2
    • Traits It is possible to have multiple traits that have the same method. This is known as stackable modifications By extending Arithmetic we are saying that this is only valid for classes that extend Arithmetic Calls the next compute method in line A hint to the compiler that you are “stacking” traits
    • Traits Output: 8 Output: 16
    • Traits If you remember from the last example the result between the two runs were different. This is because we changed the order of the traits between the two executions. Ordering of traits makes a difference! By using something called linearization classes and all of the traits are put into a linear order (right to left).  By putting them in this order, each time you call super  the next method up the chain is invoked. 2 + 2 = 4 4 * 4 = 16 2 * 2 = 4 4 + 4 = 8
    • Functional Features
    • Immutability
      • First class concept in Scala
      • By default all Collection implementations are immutable
      • val & var
        • var can be reassigned
        • val cannot, and must be assigned to something when first declared.
    • Concurrency
      • Actor Based. With each actor having a mailbox.
      • Message sends are asynch
      • Implemented on top of Java Threads
    • Concurrency Event Based Actors In event based actors a thread pool is used and each actor is given a thread to execute.
    • Concurrency Thread Based Actors With thread based actors, every actor is tied to a thread.
    • Concurrency Starting an actor and sending a message:
    • Pattern Matching
      • Allow for pattern matching on objects
      • “ added value” when you declare a case class
        • Factory method with name of class
        • Parameters are maintained as fields
      • Patterns are meant to be linear
    • Pattern Matching Basic Example: Matching a String or Int Output: “Look a String!” Output: “Look an Int!” Simple instanceof check
    • Pattern matching Implementing the visitor pattern:
    • Functions
    • Functions Partial Function: Passing a function as a parameter: Returning a function from a method:
    • Other Notable Features
      • Named & Default Args
      • Continuations
      • Lazy evaluation (lazy keyword)
      • REPL
      • Scoped imports
      • Collections API