CSE 341: Programming Languages

Similar documents
Smalltalk: developed at Xerox Palo Alto Research Center by the Learning Research Group in the 1970 s (Smalltalk-72, Smalltalk-76, Smalltalk-80)

CSE 413 Spring Introduction to Ruby. Credit: Dan Grossman, CSE341

CSE 341, Autumn 2015, Ruby Introduction Summary

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

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

Interfaces, Mixins, & Multiple Inheritance

CS 5142 Scripting Languages

CSE 341: Programming Languages

Ruby. Mooly Sagiv. Most slides taken from Dan Grossman

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

CSE 303: Concepts and Tools for Software Development

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++

CSE 341: Programming Languages

CSE 413 Programming Languages & Implementation. Hal Perkins Winter 2019 Ruby Containers, Blocks, and Procs

Lecture Notes on Programming Languages

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

Why Discuss JavaScript? CS312: Programming Languages. Lecture 21: JavaScript. JavaScript Target. What s a Scripting Language?

CSE 401/M501 Compilers

CS312: Programming Languages. Lecture 21: JavaScript

CSE 341: Programming Languages

From Java to C++ From Java to C++ CSE250 Lecture Notes Weeks 1 2, part of 3. Kenneth W. Regan University at Buffalo (SUNY) September 10, 2009

Data Abstraction. Hwansoo Han

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

CS-XXX: Graduate Programming Languages. Lecture 22 Class-Based Object-Oriented Programming. Dan Grossman 2012

UNIT I Programming Language Syntax and semantics. Kainjan Sanghavi

QUIZ. How could we disable the automatic creation of copyconstructors

C++: Overview and Features

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

CSE341: Programming Languages Lecture 4 Records, Datatypes, Case Expressions. Dan Grossman Spring 2013

CSE341: Programming Languages Spring 2017 Unit 7 Summary Dan Grossman, University of Washington

QUIZ. How could we disable the automatic creation of copyconstructors

Today. CSE341: Programming Languages. Late Binding in Ruby Multiple Inheritance, Interfaces, Mixins. Ruby instance variables and methods

CSCI B522 Lecture 11 Naming and Scope 8 Oct, 2009

Overview of the Ruby Language. By Ron Haley

CSE341: Programming Languages Lecture 26 Course Victory Lap. Dan Grossman Spring 2016

Don t Believe the Hype. CS152: Programming Languages. Lecture 21 Object-Oriented Programming. Class-based OOP. So what is OOP?

Principles of Programming Languages, 2

Ruby II. Classes. Classes are straight forward in Ruby.

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

Object-Oriented Design

Java Bytecode (binary file)

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Lecture 15: Object-Oriented Programming

Ruby: Introduction, Basics

Announcements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy

CSE 341: Programming Languages. Section AC with Nate Yazdani

CSE341: Programming Languages Lecture 20 Arrays and Such, Blocks and Procs, Inheritance and Overriding. Dan Grossman Spring 2017

CSE 505: Concepts of Programming Languages

CPS 506 Comparative Programming Languages. Programming Language

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

Lecture 24 Wrap Up. Final Logistics CSE 331. Today. CSE 331 Software Design and Implementation. Wednesday, 8:30-10:20 AM

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

CSE : Python Programming. Decorators. Announcements. The decorator pattern. The decorator pattern. The decorator pattern

CSE 331 Software Design and Implementation. Lecture 24 Wrap Up

CEU s (Continuing Education Units) 12 Hours (i.e. Mon Thurs 5 9PM or Sat Sun 8AM 5PM)

Concepts of Programming Languages

CSci 4223 Lecture 18 April 3, 2013 Topics: OOP vs. FP

CSE 374 Programming Concepts & Tools. Laura Campbell (thanks to Hal Perkins) Winter 2014 Lecture 6 sed, command-line tools wrapup

Ruby: Introduction, Basics

CSE 401/M501 Compilers

About this exam review

UEE1302 (1102) F10: Introduction to Computers and Programming

CS 314 Principles of Programming Languages

COMP 1130 Lambda Calculus. based on slides by Jeff Foster, U Maryland

Ruby: Introduction, Basics

CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping. Dan Grossman Winter 2013

Programming language design and analysis

The Environment Model. Nate Foster Spring 2018

First Programming Language in CS Education The Arguments for Scala

CSE341: Programming Languages Lecture 22 OOP vs. Functional Decomposition; Adding Operators & Variants; Double-Dispatch. Dan Grossman Autumn 2018

Scala, Your Next Programming Language

Dialects of ML. CMSC 330: Organization of Programming Languages. Dialects of ML (cont.) Features of ML. Functional Languages. Features of ML (cont.

CSE 331 Software Design & Implementation

Matlab Advanced Programming. Matt Wyant University of Washington

Object Orientation. Chapter Sixteen Modern Programming Languages, 2nd ed. 1

Programming Languages

CSE 341: Programming Languages

Functional Programming. Introduction To Cool

Previously, on Lesson Night... From Intermediate Programming, Part 1

Programming Languages and Techniques (CIS120)

CSE341: Programming Languages Lecture 23 Multiple Inheritance, Mixins, Interfaces, Abstract Methods. Dan Grossman Autumn 2018

Object-Oriented Software Engineering Practical Software Development using UML and Java. Chapter 2: Review of Object Orientation

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language

CSE 331 Software Design & Implementation

Computer Science Seminar. Whats the next big thing? Ruby? Python? Neither?

CSE341 Spring 2017, Final Examination June 8, 2017

Web Application Development

CSE 331 Software Design & Implementation

Contents in Detail. Who This Book Is For... xx Using Ruby to Test Itself... xx Which Implementation of Ruby?... xxi Overview...

G Programming Languages Spring 2010 Lecture 9. Robert Grimm, New York University

Lecturer: William W.Y. Hsu. Programming Languages

Object-Oriented Programming

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

A A B U n i v e r s i t y

Written by John Bell for CS 342, Spring 2018

Object-Oriented Software Engineering. Chapter 2: Review of Object Orientation

CSE 333. Lecture 11 - constructor insanity. Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington

Programming for Engineers in Python

Chapter 10 :: Data Abstraction and Object Orientation

Transcription:

CSE 341: Programming Languages Hal Perkins Spring 2011 Lecture 19 Introduction to Ruby Hal Perkins CSE341 Spring 2011, Lecture 19 1

Today Why Ruby? Some basics of Ruby programs Syntax Classes, Methods Variables, fields, scope Dynamic typing The rep-loop, the main class, etc. Note: Read Thomas book chapters 1 9 (2 nd ed), chs. 1 10 (3 rd ed) (or free first edition 1 8) Skip/skim regexps and ranges Not every detail: focus on OO, dynamic typing, blocks, mixins Hal Perkins CSE341 Spring 2011, Lecture 19 2

Ruby Pure object-oriented: all values are objects Class-based Dynamically typed Convenient reflection A good starting point for discussing what each of these means and what other languages look like. dynamically typed statically typed functional Scheme ML object-oriented Ruby Java Hal Perkins CSE341 Spring 2011, Lecture 19 3

Ruby vs. Smalltalk Smalltalk, unchanged since 1980, is also pure OO, class-based, dynamically-typed. Smalltalk: tiny language (smaller than Scheme), elegant, regular, can learn whole thing Smalltalk: integrated into cool, malleable GUI environment Ruby: large language with a why not? attitude Ruby: scripting language (light syntax, some odd scope rules) Ruby: very popular, massive library support especially for strings, regular expressions, Ruby on Rails Won t be our focus at all Ruby: mixins (a cool, advanced OO modularity feature) Ruby: blocks, libraries encourage lots of FP idioms Hal Perkins CSE341 Spring 2011, Lecture 19 4

Really key ideas Really, everything is an object (with constructor, fields, methods) Every object has a class, which determines how the object responds to messages. Dynamic typing (everything is an object) Dynamic dispatch (focus of next lecture) Sends to self (a special identifier; Java s this) Everything is dynamic evaluation can add/remove classes, add/remove methods, add/remove fields, etc. Blocks are almost first-class anonymous functions (later) Can convert to/from real lambdas (class Proc) (Also has some more Java/C like features loops, return, etc.) Hal Perkins CSE341 Spring 2011, Lecture 19 5

Lack of variable declarations If you assign to a variable in scope, it s mutation. If the variable is not in scope, it gets created (!) Scope is the method you are in Same with fields: an object has a field if you assign to it So different objects of the same class can have different fields (!) This cuts down on typing but catches fewer bugs (misspellings) A hallmark of scripting languages (an informal term) Hal Perkins CSE341 Spring 2011, Lecture 19 6

Protection? Fields are inaccessible outside of instance Define accessor/mutator methods as desired Use attr_read and attr_writer Good OO design: subclasses can override accessors/mutators Methods are public, protected, or private protected: only callable from class or subclass object private: only callable from self Later: namespace management, but no hiding Hal Perkins CSE341 Spring 2011, Lecture 19 7

Unusual syntax Just a few random things (keep your own mental list): Variables and fields are written differently (@ for fields) @@ for class fields (Java s static fields) Newlines often matter need extra semicolons, colons, etc. to put things on one line Message sends do not need parentheses (especially with 0 arguments) Operators like + are just message sends Class names must be capitalized self is Java s this... Hal Perkins CSE341 Spring 2011, Lecture 19 8