DOC PREVIEW
Scala

This preview shows page 1-2-16-17-18-33-34 out of 34 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 34Scala, Your Next Programming Language(or if it is good enough for Twitter, it is good enough for me)WORLDCOMP 2011ByDr. Mark C. LewisTrinity UniversityDisclaimer●I am writing a Scala textbook that is under contract with CRC Press.●I would do this tutorial anyway, just because I like Scala that much.Compiled Links●http://www.cs.trinity.edu/~mlewis/ScalaLinks.html●This is a collection of links for those who want more information on Scala.How I got into Scala●Grad schools and type systems●Functional Programming and ML●Interest in X10 and FortressBasics of Scala●“Scalable Language”●Multi-Paradigm●Productivity of scripting languages●Expressivity of functional languages●Scalability of standard OO languages●Speed of compiled, statically-typed languages●All OO●Highly Functional●Static-typing with local type inferenceToo Complex?●Reasons for perception●Scala is different●Functional isn't broadly known●Scalability → power–Bloggers show “cool” examples●Simpler in many ways●Uniform syntaxShorter Language SpecificationStatic Typed LanguageSpec Length (pages)Dynamic Typed LanguageSpec Length (pages)C 552 Common LISP 1153C++ 1325 Ruby 341C# 553 PHP 244Java 684 JavaScript 252VB.NET 597 Python 3.1 119Scala 191 Scheme 50F# 250Fewer Keywordshttp://carlosqt.blogspot.com/2011/01/how-many-keywords-in-your-source-code.htmlPast Complaints●Documentation●API●Books●Web resources●Tools●Improved IDE support●Support●TypesafeCurrent Challenges●Compile Time●Smart, multipass compiler●Optimization in progress●Binary Compatibility●Changes in traits require recompilation●Uniform Style●Many paradigms●Need guidelines●Tools comingJobsLanguage Intro●General rules●All values are objects●Operators are methods●All expressions are valid statements●Almost everything is an expression●Declarations●Begin with keyword–val, var, def, type, class, object, trait●Value parameters use ()●Type parameters use []Syntactic Sugar●Semicolon inference●Newlines become semicolons when it fits●Explicit works too●Operator notation●Leave off dot and parens●Methods with arity 0 or 1Usage Methods●REPL for simple tests●Scripting for short programs●Good for gluing things together●Applications●Declare object with main●Model is much like JavaDifference for Classes●Take arguments●No body required●Code in body run at construction●Special methods●Symbols●Property assignment●apply●update●Case classesObject Declarations●Creates singleton objects●No static in Scala●Companion objects●Apply method commonly used for object construction●No arguments●Can inheritTraits●Not interfaces●Allow method implementations and data●No arguments●Can inherit from many●Call order is linearized●Key benefits●Rich interfaces●Extension of supertypesType HierarchyCollections●Rich collection libraries●Array, List, Set, Map, etc.●Multiple varieties–Mutable/immutable●Creation●Companion object methods–fill, tabulate●Higher-Order Methods●map, filter, foreach, …●Views●StreamsStandardImmutableMutableMatch/Patterns●Match is not just switch●Cases can be patterns and bind variables.●Examples of patterns●Tuples●Array, List, etc.●RegEx●XML●much more●No breakFor Expressions●Not your normal for●Technically for-each●More options●Multiple generators●Variable declarations●If guards●Patterns●No break, continue, or gotoImplicit Conversions●“Pimp my Interface”●Strict rules●Must be in scope●Only one applied●Allows extension of●java.lang.String●Arrays●Any code you didn't writeUseful Scripting●scala.sys.process added in 2.9●Simple system calls●Piping between programs●Conditional calls●Allows Java library calls●Glue things togetherRegular Expressions●Triple quote string literals●The r method on String●Work as a pattern●Combine with for loop●Skip non-matchesXML●Literals●Pattern matching●Loads DOM●Xpath style searching●\ for immediate contents●\\ for deep search●Use @ for propertiesCombinatorial Parsers●CF grammar → parser●^^ to specify return●Quick to parse treesParallelism●Full access to Java libs●Functional makes it easier●Parallel collections●Added in 2.9●Call par method●Fast conversions, O(1)●Uses work stealing●Works with for loopsMore Parallel●Actors●Communicate through messages●Single threaded in an actor●Scala Actors●AkkaDSLs●Libraries look like language features●Pass-by-name semantics●Use implicits for built-in types●Can use combinatorial parsersWeb Frameworks●Lift●Written for Scala●Different approach●Play!●Also for Java●Scala version uses Scala idiomsConclusions●Get most of the best of all worlds●Less boiler plate●Static type safety and speed●High expressivity●Keep current JVM functionality●Easier parallel●High level libraries●Look like language features●Easy to


Scala

Download Scala
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Scala and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Scala 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?