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

Similar documents
CSE 341: Programming Languages

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

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

Overview of the Ruby Language. By Ron Haley

Interfaces, Mixins, & Multiple Inheritance

Ruby: Introduction, Basics

CS 5142 Scripting Languages

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

Ruby: Introduction, Basics

Ruby. Mooly Sagiv. Most slides taken from Dan Grossman

CSE 505: Concepts of Programming Languages

Ruby: Introduction, Basics

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

Objects and Classes. Basic OO Principles. Classes in Java. Mark Allen Weiss Copyright 2000

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

Java Bytecode (binary file)

15.1 Origins and Uses of Ruby

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

Introduction to Typed Racket. The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples

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

What is it? CMSC 433 Programming Language Technologies and Paradigms Spring Approach 1. Disadvantage of Approach 1

UMBC CMSC 331 Final Exam

CMSC 330: Organization of Programming Languages. OCaml Expressions and Functions

Language Reference Manual

CS558 Programming Languages

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

Forth Meets Smalltalk. A Presentation to SVFIG October 23, 2010 by Douglas B. Hoffman

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

CS558 Programming Languages

Programming Languages 2nd edition Tucker and Noonan"

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

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

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018

CSE 341, Spring 2011, Final Examination 9 June Please do not turn the page until everyone is ready.

JavaScript. Training Offer for JavaScript Introduction JavaScript. JavaScript Objects

Recap: Functions as first-class values

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

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

CS 360 Programming Languages Interpreters

G52CPP C++ Programming Lecture 9

Programming with Math and Logic

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

Beyond Blocks: Python Session #1

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

Installation Download and installation instructions can be found at

Classes, interfaces, & documentation. Review of basic building blocks

CMSC 331 Second Midterm Exam

CSE 341: Programming Languages

CS558 Programming Languages

Writing a Lexer. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, February 6, Glenn G.

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

LAMBDA EXPRESSIONS. Summer 2018

data_type variable_name = value; Here value is optional because in java, you can declare the variable first and then later assign the value to it.

Principles of Programming Languages, 2

CS312: Programming Languages. Lecture 21: JavaScript

The Environment Model. Nate Foster Spring 2018

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

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

CPS 506 Comparative Programming Languages. Programming Language

UNIT I Programming Language Syntax and semantics. Kainjan Sanghavi

Outline Smalltalk Overview Pragmatic Smalltalk Closing. Pragmatic Smalltalk. David Chisnall. February 7,

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

Concepts of Programming Languages

Introduction to Programming Using Java (98-388)

Dynamic Languages Strike Back. Steve Yegge Stanford EE Dept Computer Systems Colloquium May 7, 2008

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

Object-Oriented Programming


CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.

Program Fundamentals

Programming Languages. Function-Closure Idioms. Adapted from Dan Grossman's PL class, U. of Washington

CS 231 Data Structures and Algorithms, Fall 2016

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

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

Programming with Java

Programming Paradigms

News. CSE 130: Programming Languages. Environments & Closures. Functions are first-class values. Recap: Functions as first-class values

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension.

Written by John Bell for CS 342, Spring 2018

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Typical workflow. CSE341: Programming Languages. Lecture 17 Implementing Languages Including Closures. Reality more complicated

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

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications

JavaScript. History. Adding JavaScript to a page. CS144: Web Applications

CSE Lecture 3: Objects 2 September Nate Nystrom University of Texas at Arlington

APCS Semester #1 Final Exam Practice Problems

Mathematics/Science Department Kirkwood Community College. Course Syllabus. Computer Science CSC142 1/10

CS558 Programming Languages

G52CPP C++ Programming Lecture 7. Dr Jason Atkin

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Review sheet for Final Exam (List of objectives for this course)

Inheritance. Transitivity

Comp215: More lists. Dan S. Wallach (Rice University) Copyright 2015, Dan S. Wallach. All rights reserved.

Java Object Oriented Design. CSC207 Fall 2014

Web Application Development

CS152: Programming Languages. Lecture 7 Lambda Calculus. Dan Grossman Spring 2011

CGS 3066: Spring 2015 JavaScript Reference

CS 11 Haskell track: lecture 1

Transcription:

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

Why? Because: Pure object-oriented language Interesting, not entirely obvious implications Interesting design decisions Type system, mixins, syntax, big ( friendly ) etc. Also interesting, but we re ignoring: Scripting language RAILS and other frameworks

Initially Basics of Ruby programs: Syntax Classes, methods Variables, fields, scope Dynamic typing Read-eval-print loop (like Scheme!), main class, etc.

Getting Ruby Link to www.ruby-lang.org/en on course web. Documentation & downloads Versions: 1.8.7 is ubiquitous use that 1.9 is close enough if you insist Implementations: Windows: get the one-click installer OS X: Ruby 1.8 is part of developer tools Linux: Add it if not present (be sure to include irb)

References Thomas Programming Ruby is the standard tutorial introduction / reference Chs. 1-9 in Ruby 1.8 (2 nd ) edition Same except for regexp chapter in Ruby 1.9 edition Or chs. 1-8 in free online 1 st edition Lots of good/free tutorials & references on ruby-lang and elsewhere

Ruby Pure object-oriented: all values are objects Contrast w/java primitive vs reference types Class-based Dynamically Typed vs static typing in Java Convenient reflection

You now have seen most of these Design choices for O-O and functional languages dynamically typed statically typed functional Scheme Haskell, ML (not in 413) object-oriented Ruby Java

Ruby vs Smalltalk (1) Smalltalk is the classic example of a pure OO, class-based, dynamically-typed language Basically unchanged since the 80 s Tiny language, regular, can learn whole thing Integrated into a powerful, malleable, GUI environment Uses blocks (closures) for control structures

Ruby vs Smalltalk (2) Ruby Large language, why not attitude make programmers happy Scripting language, minimal syntax Massive library (strings, regexps, RAILS) Mixins (somewhere between Java interfaces and C++ multiple inheritance very neat) Blocks and libraries for control structures and functional-programming idioms

Ruby Key Ideas (1) Everything is an object (with constructor, fields, methods) Every object has a class, which determines how it responds to messages Dynamic typing (everything is an object) Dynamic dispatch (like Java; later) Sends to self (same as this in Java)

Ruby Key Ideas (2) 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 And a few C/Java-like features (loops, return, etc.)

No Variable Declarations If you assign to a variable, it s mutation If the variable is not in scope, it is created(!) (Do not mispeal things!!) Scope is the current method Same with fields: if you assign to a field, that object has that field So different objects of the same class can have different fields(!) Fewer keystrokes in programs, but compiler catches fewer bugs does it matter?

Naming Conventions Used to distinguish kinds of variables Constants and ClassNames start with caps local_vars and parameters start w/lower case @instance_variables @thing = thing sets an instance variable from a local name and creates @thing if it doesn t exist! @@class_variables $global $VARS $CONSTANTS

Protection? Fields are inaccessible outside instance Define accessor/mutator methods as needed Methods are public, protected, private protected: only callable from class or subclass object private: only callable from self Both of these differ from Java (how?)

Unusual syntax (add to this list as you discover things) Newlines often matter example: don t need semi-colon if a statement ends a line Message sends (function calls) often don t need parentheses Infix operations are just message sends Can define operators including =, [ ] Operators like + are just message sends e1 if e2 and similar things (as well is if e1 then e2)

Unusual syntax (add to this list as you discover things) Classes don t need to be defined in one place (similar to C#, not Java, C++) Class names must be capitalized self is Java s this Loops, conditionals, classes, methods are self-bracketing (end with end ) Actually not unusual except to programmers who have too much exposure to C/Java, etc.

A bit about Expressions Everything is an expression and produces a value nil means nothing, but it is an object (an instance of class NilClass) nil and false are false in a boolean context; everything else is true (including 0) strings are taken literally (almost) strings allow more substitutions including #{expressions}