Your SlideShare is downloading. ×
0
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Introduction to Scala

1,656

Published on

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

Published in: Business, Technology
1 Comment
3 Likes
Statistics
Notes
  • Get example code at http://tr.im/jA6A
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
1,656
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
50
Comments
1
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. <ul><li>A programming language for the JVM (and .net)
  • 2. Functional / OO hybrid
  • 3. Statically typed
  • 4. Compile to class files
  • 5. Iterpretive Console
  • 6. Flexible syntax </li></ul>What is it?
  • 7. <ul><li>&apos;Scalable Language&apos; </li><ul><li>On the JVM
  • 8. Integrates with existing libraries
  • 9. Integrates readily with other systems (in code XML &amp; JSON support)
  • 10. Flexible syntax – can be like Java or can move to DSLs and higher abstractions. </li></ul></ul>The name
  • 11. <ul><li>Removes Java roadblocks without changing platform or throwing away existing properties </li><ul><li>Tasks that are difficult or tedious in Java can be simplified with minimal investment in time and tools </li></ul><li>Rapid development without losing type safety.
  • 12. Java + new language features: </li><ul><li>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 </li></ul></ul>Why should we care?
  • 13. <ul><li>Code example - Hello World </li><ul><li>Points of interest: </li><ul><li>Object keyword
  • 14. Def keyword
  • 15. Assignment of code block to function
  • 16. scala.Console
  • 17. Application trait </li></ul></ul></ul>See associated source files at http://tr.im/jA6A HelloWorld.scala &amp; HelloWorldWithTrait.scala
  • 18. <ul><li>Using the basic building blocks, we can compose code that looks and feels similar to today&apos;s Java. </li><ul><li>Though not source compatible. Can&apos;t compile Java. </li></ul><li>Package, import, class, object, trait, var, val, def
  • 19. Code example: Cat </li><ul><li>Relaxed naming constraints, constructor arg visibility, constructor overload, function definition, implied static typing, val vs var </li></ul></ul>The basic building blocks Cat.scala
  • 20. <ul><li>Can be very terse
  • 21. Return type implies type of function
  • 22. Naming is greatly relaxed.
  • 23. Code sample: Rational </li><ul><li>Symbols as function names -&gt; infix operators, optional &apos;return&apos; keyword, if statements are ternary, DSLs </li></ul></ul>Functions Rational.scala
  • 24. <ul><li>XML is a native datatype
  • 25. Rich XML operations make parsing and creating XML simple.
  • 26. Code sample: NativeXML </li><ul><li>Eclipse plugin slightly broken – parentheses not required, XML direct in code, nested values, iterated lists, xpath-like functions </li></ul></ul>Native XML NativeXML.scala
  • 27. <ul><li>Implicit functions map one type to another
  • 28. Ascribes new functionality to old friends </li><ul><li>e.g. Make the JDBC library user-friendly </li></ul><li>Code sample: UpperCaseAwareString </li><ul><li>RichString already exists
  • 29. Implicit def declaration
  • 30. Multiple impicit defs, but method calls must be unambiguous at compilation </li></ul></ul>Extending other classes – Monkey Patching UpperCaseCharAwareString.scala
  • 31. <ul><li>Compile time checked duck typing
  • 32. Can define types based on functions signatures
  • 33. Code sample: Duck </li><ul><li>Type keyword, multiple method definitions, includes param and return types, can be inlined </li></ul></ul>Structural types – Duck Typing Duck.scala
  • 34. <ul><li>More than interfaces
  • 35. Less than classes
  • 36. Act as markers
  • 37. Can have methods
  • 38. Can have constructors
  • 39. Code sample: Bravia </li><ul><li>Extend abstract or trait, mixins </li></ul></ul>Traits Bravia.scala
  • 40. <ul><li>Define combinations of types in contracts
  • 41. Code sample: Chess </li><ul><li>Compile time type checking for multiple types </li></ul></ul>Compound types chess.Chess.scala
  • 42. <ul><li>Case objects are akin to enums
  • 43. Case classes are parameterisable
  • 44. Pattern Matching is akin to switch statement, but more powerful
  • 45. Code sample: Months </li><ul><li>No new keyword, no params for object - params for class, match &amp; case, _ wildcard, exposed params when matching on classes, also used for exception handling </li></ul></ul>Case objects/classes and pattern matching Months.scala
  • 46. <ul><li>Functions are objects. Everything is!
  • 47. Can access parent scope (closure)
  • 48. Can be defined inline (&apos;function literal&apos;)
  • 49. Code sample: BookReader </li><ul><li>Function as a parameter, function knows and can modify instance values, functions defined inline. </li></ul></ul>Functions are objects too BookReader.scala
  • 50. <ul><li>Any number of enumerations and filters mixed together to form a new list.
  • 51. Enumerations add values, filters remove them.
  • 52. Lightweight notation
  • 53. Code sample: Condiments </li><ul><li>Note generics, note also list creation. </li></ul></ul>Sequence Comprehensions Condiments.scala
  • 54. <ul><li>Functions with many params can be decomposed into a chain of functions.
  • 55. This is supported and used to construct language extensions.
  • 56. Code sample: AutoResourceManagement </li><ul><li>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. </li></ul></ul>Currying AutoResourceManagement.scala
  • 57. <ul><li>www.scala-lang.org </li><ul><li>Binaries, source, tutorials and doco </li></ul><li>[email_address] - mailing list
  • 58. http://groups.google.com/group/scala-melb - Scala Melbourne User Group
  • 59. http://tr.im/jzQK – Scala for Java devs. </li></ul>Getting started
  • 60. <ul><li>Testing </li><ul><li>http://www.artima.com/scalatest/
  • 61. http://code.google.com/p/specs/
  • 62. http://code.google.com/p/scalacheck/ </li></ul><li>Building </li><ul><li>http://code.google.com/p/simple-build-tool/ </li></ul><li>IDE Support </li><ul><li>Eclipse, NetBeans, IntelliJ </li></ul></ul>Tools

×