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

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Introduction to Ruby.
Advertisements

Written by: Dr. JJ Shepherd
Language of the Month If it’s December, it must be Ruby! Adam Coffman and Brent Beer.
CSE341: Programming Languages Lecture 19 Introduction To Ruby; Dynamic OOP; "Duck Typing" Dan Grossman Fall 2011.
CSE341: Programming Languages Lecture 20 Blocks & Procs; Inheritance & Overriding Dan Grossman Fall 2011.
Road Map Introduction to object oriented programming. Classes
12-Jun-15 JavaScript Language Fundamentals I. 2 About JavaScript JavaScript is not Java, or even related to Java The original name for JavaScript was.
Dynamic Object-Oriented Programming with Smalltalk 1. Introduction Prof. O. Nierstrasz Summer Semester 2006.
PZ06BX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ06BX - Introduction to Smalltalk Programming Language.
Programming in Scala Chapter 1. Scala: both object-oriented and functional Scala blends –object-oriented and –functional programming in a –statically.
Object-oriented programming and design 1 Smalltalk in a Nutshell Objects & classes Messages & methods Inheritance & metaclasses.
CSE341: Programming Languages Introduction To Ruby; Dynamic OOP; "Duck Typing" Alan Borning Autumn 2012 (slides borrowed from Dan Grossman)
CSE 413 Programming Languages & Implementation Hal Perkins Autumn 2012 Ruby: Multiple Inheritance, Interfaces, Mixins 1.
Ruby (on Rails) CSE 190M, Spring 2009 Week 1. The Players Kelly "Everyday I'm Hustlin' " Dunn Kim "Mouse" Todd Ryan "Papa T" Tucker.
The Ruby Programming Language
Comparison of OO Programming Languages © Jason Voegele, 2003.
A TOUR OF RUBY 2011 ACM Class, Dong Xie. What is Ruby?  Dynamic programming language  Complex but expressive grammar  A core class library with rich.
3A-1 1 Introduction to Smalltalk History of Smalltalk The philosophy of Smalltalk:  “...we have a universe of well-behaved objects that courteously ask.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
Java Tutorial. Object-Oriented Programming Concepts Object –a representation of some item state  fields/members and should be encapsulated behavior 
CSCI-383 Object-Oriented Programming & Design Lecture 13.
CSE 425: Object-Oriented Programming I Object-Oriented Programming A design method as well as a programming paradigm –For example, CRC cards, noun-verb.
Ruby on Rails. What is Ruby? Programming Language Object-oriented Interpreted.
An Introduction to Python Blake Brogdon. What is Python?  Python is an interpreted, interactive, object-oriented programming language. (from python.org)
CSE 413 Programming Languages & Implementation Hal Perkins Autumn 2012 Late binding and dynamic dispatch (Based on CSE 341 slides by Dan Grossman) 1.
CSE 341 Programming Languages Introduction to Ruby Zach Tatlock Spring 2014.
Chapter 12 Support for Object oriented Programming.
Objects & Dynamic Dispatch CSE 413 Autumn Plan We’ve learned a great deal about functional and object-oriented programming Now,  Look at semantics.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
CSE 341, S. Tanimoto Java brief review - 1 Java Brief Review Java’s strengths Object-oriented terminology Inheritance Interfaces An example with inheritance.
+ Ruby and other programming Languages Ronald L. Ramos.
CSE 413 Programming Languages & Implementation Hal Perkins Autumn 2012 Introduction to Ruby (adapted from CSE 341, Dan Grossman) 1.
02/14/2005 Introduction to Programming with Java, for Beginners Midterm 1 Review.
Chapter 12 Support for Object-Oriented Programming.
CSE 413 Languages & Implementation Hal Perkins Autumn 2012 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) 1.
Copyright © 2005 Elsevier Object-Oriented Programming Control or PROCESS abstraction is a very old idea (subroutines!), though few languages provide it.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
1 Getting Started with Ruby. 2 What’s Ruby? Ruby is an OO, dynamic, agile language –Everything’s an object For example, try puts -1.abs –Derives strengths.
Written by: Dr. JJ Shepherd
Interfaces, Mixins, & Multiple Inheritance CSE 413 Autumn 2008 Credit: Dan Grossman, CSE341, Sp08.
Ruby Duck Typing, Classes & Inheritance CSE 413 Autumn 2008.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
OOP Basics Classes & Methods (c) IDMS/SQL News
CSE 341 Section 10 Subtyping, Review, and The Future.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
Ruby Tien Ho and Brandon Hostetter. Overview ▸ Object-oriented, functional, imperative, and reflective ▸ Interpreted language ▸ Influenced by Perl, Smalltalk,
Programming Languages Dan Grossman 2013 Everything is an Object.
Programming Languages Dan Grossman 2013 Classes and Objects.
Presented By P.SRIVIDYA 085D1A0552 Programming Language.
CSE 413 Programming Languages & Implementation Hal Perkins Autumn 2012 Multiple Inheritance, Interfaces, Mixins 1.
Programming Languages Dan Grossman 2013
CSE341: Programming Languages Lecture 21 Dynamic Dispatch Precisely, and Manually in Racket Dan Grossman Spring 2016.
Objects as a programming concept
Programming Languages Dan Grossman 2013
Ruby: An Introduction Created by Yukihiro Matsumoto in 1993 (named after his birthstone) Pure OO language (even the number 1 is an instance of a class)
CSE341: Programming Languages Lecture 21 Dynamic Dispatch Precisely, and Manually in Racket Dan Grossman Winter 2013.
CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP
CSE341: Programming Languages Lecture 21 Dynamic Dispatch Precisely, and Manually in Racket Dan Grossman Spring 2017.
CSE341: Programming Languages Lecture 21 Dynamic Dispatch Precisely, and Manually in Racket Dan Grossman Autumn 2017.
Alan Borning Spring 2018 (slides borrowed from Dan Grossman)
CSE341: Programming Languages Lecture 21 Dynamic Dispatch Precisely, and Manually in Racket Dan Grossman Autumn 2018.
PHP.
Tonga Institute of Higher Education
Introduction to Smalltalk
CSE 3302 Programming Languages
CSE341: Programming Languages Lecture 21 Dynamic Dispatch Precisely, and Manually in Racket Dan Grossman Spring 2019.
SPL – PS3 C++ Classes.
Presentation transcript:

Introduction to Ruby CSE 413 Autumn 2008 Credit: Dan Grossman, CSE341

Why Ruby? Because:  Pure object-oriented language Interesting, not entirely obvious implications  Interesting design decisions (compare Java) Particularly type system, mixins, etc. Interesting, but not our focus  Scripting language  RAILS and other frameworks

Getting Ruby Link to on course web. Documentation & downloads Implementations:  Windows: get the “one-click installer”  OS X: Ruby 1.8 is part of developer tools  Linux: Should be available from your distro. Be sure to include the irb interactive interpreter too.

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

Languages Compared One way to get an overview of what these mean and how other languages relate dynamically typedstatically typed functionalSchemeML (not in 413) object-orientedRubyJava

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  Huge 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(!) (Don’t mispell 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(!)

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

Visibility. 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

Unusual syntax (add to this list as you discover things) Newlines often matter – example: don’t need semi-colon when a statement ends a line Message sends (function calls) often don’t need parentheses Infix operations are just message sends Can define operators including =, [ ] Classes don’t need to be defined in one place Loops, conditionals, classes, methods are self- bracketing (end with “end”)  Actually not unusual except to programmers who have too much prior 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}