Scala, Your Next Programming Language

Similar documents
First Programming Language in CS Education The Arguments for Scala

Notes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.)

Using Scala for building DSL s

Programming in Scala Second Edition

Scala : an LLVM-targeted Scala compiler

Who am I? Harlan Iverson. Programming enthusiast. Seeker of truth. Imperfect. I'll be wrong about some things. Please correct me if you can.

G Programming Languages - Fall 2012

Concepts of Programming Languages

Ruby: Introduction, Basics

Scala, Lift and the Real Time Web

Ruby: Introduction, Basics

CSE 341, Autumn 2015, Ruby Introduction Summary

CSCI-GA Scripting Languages

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309


G Programming Languages - Fall 2012

CS162 Week 1. Kyle Dewey. Friday, January 10, 14

CMSC 330: Organization of Programming Languages

Ruby: Introduction, Basics

CS 349 / SE 382 Scripting. Professor Michael Terry March 18, 2009

CS152 Programming Language Paradigms Prof. Tom Austin, Fall Syntax & Semantics, and Language Design Criteria

Python I. Some material adapted from Upenn cmpe391 slides and other sources

Introduction. COMP 524: Programming Language Concepts Björn B. Brandenburg. The University of North Carolina at Chapel Hill

Semantic Analysis. Lecture 9. February 7, 2018

Index. Comma-separated values (CSV), 30 Conditional expression, 16 Continuous integration (CI), 34 35, 41 Conway s Law, 75 CurrencyPair class,

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

The Script Bowl Featuring Groovy, JRuby, Jython and Scala. Raghavan Rags N. Srinivas CTO, Technology Evangelism

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited

Using Scala in CS241

Functional Programming and the Web

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

Chapter 7 Control I Expressions and Statements

Writing Evaluators MIF08. Laure Gonnord

Functional Programming

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking

CS Exam #1-100 points Spring 2011

CERTIFICATE IN WEB PROGRAMMING

Project 1: Scheme Pretty-Printer

Concepts of Programming Design

Arne Brüsch Philipp Wille. Pattern Matching Syntax

Programming Kotlin. Extracted from: Creating Elegant, Expressive, and Performant JVM and Android Applications. The Pragmatic Bookshelf

An Overview of Scala. Philipp Haller, EPFL. (Lots of things taken from Martin Odersky's Scala talks)

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

CHAPTER 1: INTRODUCING C# 3

! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented

INSTITUTE OF AERONAUTICAL ENGINEERING

The role of semantic analysis in a compiler

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

Objects and Classes Lecture 1

Programming Languages, Summary CSC419; Odelia Schwartz

What is a compiler? Xiaokang Qiu Purdue University. August 21, 2017 ECE 573

Unifying functional and object-oriented programming with Scala 齐琦, 海南大学计算机发展前沿系列课程


What is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done

Apache Spark and Scala Certification Training

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

CS 360 Programming Languages Interpreters

Executive Summary. It is important for a Java Programmer to understand the power and limitations of concurrent programming in Java using threads.

Compiler principles, PS1

A Tour of Language Implementation

Topic 1: Introduction

Programming Kotlin. Familiarize yourself with all of Kotlin s features with this in-depth guide. Stephen Samuel Stefan Bocutiu BIRMINGHAM - MUMBAI

CPSC 3740 Programming Languages University of Lethbridge. Control Structures

CIS192: Python Programming

Seminar on Languages for Scientific Computing Aachen, 6 Feb Navid Abbaszadeh.

Typescript on LLVM Language Reference Manual

Topics Covered Thus Far CMSC 330: Organization of Programming Languages

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)

CPL 2016, week 10. Clojure functional core. Oleg Batrashev. April 11, Institute of Computer Science, Tartu, Estonia

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p.

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

JavaScript: Sort of a Big Deal,

n Closed book n You are allowed 5 cheat pages n Practice problems available in Course Materials n Check grades in Rainbow grades

A Simple Syntax-Directed Translator

Java Bytecode (binary file)

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming

PYTHON TRAINING COURSE CONTENT

CSCE 314 Programming Languages. Type System

Full file at

Scala Concurrency and Parallel Collections

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

Safely-Composable Type-Specific Languages

C++11 and Compiler Update

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Final-Term Papers Solved MCQS with Reference

Type Inference. Prof. Clarkson Fall Today s music: Cool, Calm, and Collected by The Rolling Stones

Software Development Time. Compilers in Real Life. Lessons from Real Life. Software Maintenance. Solutions for Real Life. Celebrity Endorsements

Richard Mallion. Swift for Admins #TEAMSWIFT

Combining Concurrency Abstractions

Informal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures

Multi-catch. Future Features. Sometimes we need to handle more than one exception in a single catch block:

Domain-Specific. Languages. Martin Fowler. AAddison-Wesley. Sydney Tokyo. With Rebecca Parsons

CSE 341: Programming Languages

CMSC 330: Organization of Programming Languages. Functional Programming with OCaml

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

PYTHON CONTENT NOTE: Almost every task is explained with an example

Transcription:

Scala, Your Next Programming Language (or if it is good enough for Twitter, it is good enough for me) WORLDCOMP 2011 By Dr. Mark C. Lewis Trinity University

Disclaimer 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 Fortress

Basics 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 inference

Too Complex? Reasons for perception Scala is different Functional isn't broadly known Scalability power Bloggers show cool examples Simpler in many ways Uniform syntax

Shorter Language Specification Static Typed Language Spec Length (pages) Dynamic Typed Language Spec Length (pages) C 552 Common LISP 1153 C++ 1325 Ruby 341 C# 553 PHP 244 Java 684 JavaScript 252 VB.NET 597 Python 3.1 119 Scala 191 Scheme 50 F# 250

Fewer Keywords http://carlosqt.blogspot.com/2011/01/how-many-keywords-in-your-source-code.html

Past Complaints Documentation API Books Web resources Tools Improved IDE support Support Typesafe

Current Challenges Compile Time Smart, multipass compiler Optimization in progress Binary Compatibility Changes in traits require recompilation Uniform Style Many paradigms Need guidelines Tools coming

Jobs

Language 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 1

Usage Methods REPL for simple tests Scripting for short programs Good for gluing things together Applications Declare object with main Model is much like Java

Difference for Classes Take arguments No body required Code in body run at construction Special methods Symbols Property assignment apply update Case classes

Object Declarations Creates singleton objects No static in Scala Companion objects Apply method commonly used for object construction No arguments Can inherit

Traits Not interfaces Allow method implementations and data No arguments Can inherit from many Call order is linearized Key benefits Rich interfaces Extension of supertypes

Type Hierarchy

Collections 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 Streams

Standard

Immutable

Mutable

Match/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 break

For Expressions Not your normal for Technically for-each More options Multiple generators Variable declarations If guards Patterns No break, continue, or goto

Implicit 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 write

Useful Scripting scala.sys.process added in 2.9 Simple system calls Piping between programs Conditional calls Allows Java library calls Glue things together

Regular Expressions Triple quote string literals The r method on String Work as a pattern Combine with for loop Skip non-matches

XML Literals Pattern matching Loads DOM Xpath style searching \ for immediate contents \\ for deep search Use @ for properties

Combinatorial Parsers CF grammar parser ^^ to specify return Quick to parse trees

Parallelism 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 loops

More Parallel Actors Communicate through messages Single threaded in an actor Scala Actors Akka

DSLs Libraries look like language features Pass-by-name semantics Use implicits for built-in types Can use combinatorial parsers

Web Frameworks Lift Written for Scala Different approach Play! Also for Java Scala version uses Scala idioms

Conclusions 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 use DSLs