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

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

Using Scala in CS241

Scala, Your Next Programming Language

CS 241 Data Organization using C

First Programming Language in CS Education The Arguments for Scala

CSE : Python Programming

Practically Functional. Daniel Spiewak

CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP. Dan Grossman Winter 2013

COMP 410 Lecture 1. Kyle Dewey

Welcome to... CS113: Introduction to C

n n Official Scala website n Scala API n

CS 241 Data Organization. August 21, 2018

CIS192: Python Programming

CSE 341, Autumn 2015, Ruby Introduction Summary

Ruby logistics. CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP. Ruby: Not our focus. Ruby: Our focus. A note on the homework

Lecture 1: Overview

Lecture 21: The Many Hats of Scala: OOP 10:00 AM, Mar 14, 2018

Thinking Functionally

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Overview. Elements of Programming Languages. Objects. Self-Reference

Project 5 Due 11:59:59pm Tuesday, April 25, 2017

Exam 2. Name: UVa ID:

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

Scala, Lift and the Real Time Web

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

The fringe of a binary tree are the values in left-to-right order. For example, the fringe of the following tree:

Intro. Scheme Basics. scm> 5 5. scm>

CSC209. Software Tools and Systems Programming.

Scala in Martin Odersky

CSC 326H1F, Fall Programming Languages. What languages do you know? Instructor: Ali Juma. A survey of counted loops: FORTRAN

TA hours and labs start today. First lab is out and due next Wednesday, 1/31. Getting started lab is also out

Alan J. Perlis - Epigrams on Programming

ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1

COSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26

Review: Using Imported Code. What About the DrawingGizmo? Review: Classes and Object Instances. DrawingGizmo pencil; pencil = new DrawingGizmo();

CSE 341, Autumn 2005, Assignment 3 ML - MiniML Interpreter

Scala Compiler Phase and Plug-In Initialization for Scala 2.8

G Programming Languages - Fall 2012

CS 351: Design of Large Programs.

COMP-202: Foundations of Programming. Lecture 26: Review; Wrap-Up Jackie Cheung, Winter 2016

Project 5 Due 11:59:59pm Wed, Nov 25, 2015 (no late submissions)

Object-Oriented Programming CSCI-UA

Computer Science 210: Data Structures

C311 Lab #3 Representation Independence: Representation Independent Interpreters

Haskell Review COMP360

JAVA MOCK TEST JAVA MOCK TEST II

CSE341: Programming Languages Lecture 9 Function-Closure Idioms. Dan Grossman Winter 2013

COMP 250 Winter 2011 Reading: Java background January 5, 2011

CS1 Lecture 4 Jan. 23, 2019

Lecture 02, Fall 2018 Friday September 7

CS153: Compilers Lecture 1: Introduction

CS50 Quiz Review. November 13, 2017

Strings are not collections, but they behave like them in almost every way. For example,

6.189 Project 1. Readings. What to hand in. Project 1: The Game of Hangman. Get caught up on all the readings from this week!

Introduction to Programming System Design CSCI 455x (4 Units)

Subclassing for ADTs Implementation

CS1 Lecture 13 Feb. 13, 2019

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

Using Scala for building DSL s

CSE 341: Programming Languages

Overview. Elements of Programming Languages. Objects. Self-Reference

Chamberlin and Boyce - SEQUEL: A Structured English Query Language

Week - 01 Lecture - 04 Downloading and installing Python

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.

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

Review: Object Diagrams for Inheritance. Type Conformance. Inheritance Structures. Car. Vehicle. Truck. Vehicle. conforms to Object

CS205: Scalable Software Systems

Ruby: Objects and Dynamic Types

Racket. CSE341: Programming Languages Lecture 14 Introduction to Racket. Getting started. Racket vs. Scheme. Example.

These notes are intended exclusively for the personal usage of the students of CS352 at Cal Poly Pomona. Any other usage is prohibited without

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

CS Lecture 6: Map and Fold. Prof. Clarkson Fall Today s music: Selections from the soundtrack to 2001: A Space Odyssey

CSE341: Programming Languages Lecture 9 Function-Closure Idioms. Dan Grossman Fall 2011

Procedural Abstraction

CS558 Programming Languages

Chapter 3. Interactive Software Development Assistants Logic-based Software Representation. Logic-based Software Analysis

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

CS24 Week 3 Lecture 1

CS 2340 Objects and Design - Scala

Static type safety guarantees for the operators of a relational database querying system. Cédric Lavanchy

Assignment 19 Deadline: Nov pm COSC211 CRN15376 Session 15 (Nov. 7)

Scheme: Expressions & Procedures

Computer. CSE 373 Summer 2017 Due 5:00pm on Friday, July 14th

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

Chapter 4C Homework Functions III Individual Assignment 30 Points Questions 6 Points Script 24 Points

4.1 Review - the DPLL procedure

Prelim 1 SOLUTION. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants. Recursion OO Short answer

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

Scala Style Guide Spring 2018

Gene Kim 9/9/2016 CSC 2/444 Lisp Tutorial

CS150: Exam 2 Due: Mon Apr 20th by 3:30pm (in class) or by 6:30pm (OLS 219) UVA ID: Directions

HOW WE MOVED FROM JAVA TO SCALA

Programming in Scala Second Edition

(Refer Slide Time: 05:25)

CMPSCI 187 / Spring 2015 Implementing Sets Using Linked Lists

G52CPP C++ Programming Lecture 9

CS/ENGRD 2110 SPRING Lecture 3: Fields, getters and setters, constructors, testing

Data Structures (list, dictionary, tuples, sets, strings)

COMP19612 exam performance feedback 2014

CSC209. Software Tools and Systems Programming.

Transcription:

CS162 Week 1 Kyle Dewey

Overview Basic Introduction CS Accounts Scala survival guide

Office Hour Choose an hour from within: Tuesday/Thursday 11 AM - 1 PM Friday 11 AM - 4 PM Also available by appointment

Google Group We have a Google group (162w14) Feel free to discuss, even post test cases Pretty much anything CS162-related that doesn t involve sharing code

-This is mostly so I m not swamped with emails right before a project. It gets ugly. -Certain things are obviously directed at me: what is my grade for this? However, much project help is better fit for the Google group Communication Policy Assume I ll take 24 hours to respond to any email I m usually a lot faster than that Google group is usually a better resource I can still answer it Other people can see it Someone else may respond faster

CS Account You will need a CS account One can be created at: https://accounts.engr.ucsb.edu/create/

Collaboration You may discuss ideas I.e. check if the list is sorted You may exchange test cases I.e. this test fails if your code does not check if the list is sorted All these can be freely posted to the Google group, too

Collaboration You may not exchange or discuss code I.e. this code checks if a list is sorted I.e. you need a function that uses three variables that returns... We automatically determine similarity scores for code via a proven reliable method

Protect Your Code Do not host your code on a public repository Execute chmod 600 filename for each file in your project (chmod 600 *.scala usually does the trick) Otherwise, people can and have taken other people s code In general, it is not possible to determine who stole from who -Can get up to 5 free private repositories on GitHub as a student, and private bitbucket repositories are always free

Discussion / Lecture Importance These are not mandatory, but it is nearly impossible to do the assignments without them nearly impossible means expect to take several hours studying the lecture and discussion notes before you can implement it If you cannot make lecture/discussion, arrange for someone else to take notes for you

-Your entire grade is based on 7 assignments, so the difficulty needs to come from somewhere -Start early! Assignment Difficulty The assignments are intended to be very difficult and take multiple sittings to do It is ill-advised to do them alone It is even more ill-advised to do them the night before

Assignment Difficulty Most of the difficulty will be in figuring out exactly what needs to be done and how to do it The coding is accidental Historically, shorter complete solutions tend to pass more tests -This doesn t mean the instructions are ambiguous; this means that the concepts are that new and potentially that difficult to understand

Scala

Scala Discussion It s not possible to cover everything in these slides in-depth in one section This is intended as a strong foundation for the class assignments Examples are on my website (scala_examples.zip)

What? A non-java language that runs on the Java Virtual Machine (JVM) Essentially a better Java Better suited for object-oriented programming and functional programming

Why Less boilerplate More expressive (read: less code) Think more, type less Clarity -It is not unheard of to spend an hour on several lines of code -See boilerplate.scala, boilerplate.java

Properties and Idioms Everything is an object (unlike Java) Emphasis on immutable state In other words, avoid reassignment

Variable Declaration Two forms: val and var val creates a runtime constant, much like final in Java var creates a typical mutable variable (HIGHLY discouraged and will typically negatively impact grade) -See variables.scala

Method Definition Uses the def reserved word Everything is public by default The result of the last expression in the function is what is returned - no need for return (which should be avoided) -See method.scala

Type Inferencer Can automatically determine the type of Variables Function return values Anonymous function parameters Not completely foolproof, but usually excellent -See type_inference.scala

Higher-Order Functions Functions can take other functions as parameters, or even return functions Functions (well, closures) can be created on the fly Note: this is strictly more powerful than function pointers For the JavaScript people: think callbacks -See higher_order.scala

Classes Created with the class reserved word Defaults to public access Constructors are not typical -See class.scala

Traits Created with the trait reserved word Like a mixin in Ruby Think Java interfaces, but they can have methods defined on them More powerful than that, but not relevant to this course -See trait.scala

object Used in much the same way as static is in Java Defines both a class and a single instance of that class (and only a single instance) Automated implementation of the Singleton design pattern Keeps everything consistently an object -See object.scala and object.java

equals, ==, and eq As with Java, if you want to compare value equality, you must extend equals Case classes automatically do this for you However, instead of saying x.equals(y), merely say x == y If you want reference equality, say: x eq y

-Regular classes can be used in pattern matching as well, but you usually need to put more effort into it (see the unapply method) -See case_class.scala Case Classes Behave just like classes, but a number of things are automatically generated for you Including hashcode, equals, and getters Typically used for pattern matching

Pattern Matching Used extensively in Scala Like a super-powerful if Used with the match reserved word, followed by a series of cases -See pattern_matching.scala

null In general, null is an excellent wonderful/ terrible feature Often poorly documented whether or not null is possible Checking for impossible cases Not checking for possible cases

Option A solution: encode null as part of a type For some type, say Object, if null is possible say we have a NullPossible<Object> Scala has this, known as Option In general, if null is possible, use Option -See option.scala

Tuples For when you want to return more than one thing Can be created by putting datums in parenthesis Can pattern match on them -See tuples.scala, tuples_revisited.scala

Sequence Processing Functions AKA: Why while is rare and for isn t for

Looping Scala has a while loop, but its use is highly discouraged (again, point loss) It s not actually needed General functional programming style is recursion, but this is usually overkill

foreach Applies a given function to each element of a Seq -See foreach.scala

map Like foreach, in that it applies a given function to each element of a sequence However, it also returns a new sequence that holds the return values of each of the function calls -See MapExample.scala, MapExample.java

filter Takes a predicate, i.e. a function that returns true or false Applies the predicate to each item in a list A new list is returned that contains all the items for which the predicate was true -See FilterExample.java, FilterExample.scala

foldleft Extremely flexible, but sometimes unwieldy Takes a base element Takes a function that takes a current result and a current list element The function will manipulate result with respect to the current element -See fold.scala, FoldLeftExample.java, FoldLeftExample.scala

flatmap Like map, but made especially for functions that return Seqs Will internally flatten all of the inner Seqs into a single Seq More on this later in the course -see flatmap.scala

for Comprehensions Much like Python s list comprehensions Internally translated into a series of foreach, flatmap, map, and filter operations -See for.scala

Compiling/Running Code Use scalac to compile code Use scala to run the code scala and scalac are all on CSIL

Running the REPL Just type scala at the command line Pretty nifty to quickly check to see what an expression does

Development If you want an IDE, IntelliJ IDEA has been recommended Personally, I use emacs and the scalamode plugin (needs to be downloaded)

Assignment 1 Due Tuesday, January 14 Will need most everything shown here Hint hint useful APIs: Seq.mkString Seq.reverse Seq.head Seq.tail