Ruby! Useful as a scripting language – script: A small program meant for one time use – Targeted towards small to medium size projects Use by: – Amazon,

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Introduction to Ruby.
Ruby (on Rails) CSE 190M, Spring 2009 Week 2. Arrays Similar to PHP, Ruby arrays… – Are indexed by zero-based integer values – Store an assortment of.
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Programming Languages and Paradigms The C Programming Language.
JavaScript Part for Repetition Statement for statement Cpecifies each of the items needed for counter-controlled repetition with a control variable.
Copyright © by Curt Hill Expressions and Assignment Statements Part 2.
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
Expressions, variables, and for loops (oh my!) spam, spam, spam, spam
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Pointer. Warning! Dangerous Curves C (and C++) have just about the most powerful, flexible and dangerous pointers in the world. –Most other languages.
Introduction to Computers and Programming Lecture 5 Boolean type; if statement Professor: Evan Korth New York University.
Week 2 expressions, variables, for loops Special thanks to Scott Shawcroft, Ryan Tucker, Paul Beck, Hélène Martin, Kim Todd, John Kurkowski, and Marty.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Chapter 2 - Java Programming Fundamentals1 Chapter 2 Java Programming Fundamentals.
Adapted from Dr. Craig Chase, The University of Texas at Austin.
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
Scripting with Ruby What is a scripting language? What is Ruby?
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
String Escape Sequences
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
Ruby (on Rails) CSE 190M, Spring 2009 Week 1. The Players Kelly "Everyday I'm Hustlin' " Dunn Kim "Mouse" Todd Ryan "Papa T" Tucker.
ALBERT WAVERING BOBBY SENG. Week Whatever: PHP  Announcements/questions/complaints.
A First Book of ANSI C Fourth Edition
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
High-Level Programming Languages: C++
CIS Computer Programming Logic
Chapter Nine: Subprograms Lesson 09. What are they  Modularized code  Might return a value  Functions  Or not  Procedures  Subroutines  In object.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Ruby on Rails. What is Ruby? Programming Language Object-oriented Interpreted.
PHP - Basic Language Constructs CSCI 297 Scripting Languages - Day Two.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
Arithmetic Expressions
Unit 2 Expressions and variables; for loops Special thanks to Roy McElmurry, John Kurkowski, Scott Shawcroft, Ryan Tucker, Paul Beck for their work. Except.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Introduction to Java Java Translation Program Structure
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
Data Types Declarations Expressions Data storage C++ Basics.
Week 2 expressions, variables, for loops Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where otherwise.
Week 2 expressions, variables, for loops Special thanks to Scott Shawcroft, Ryan Tucker, Paul Beck, Hélène Martin, Kim Todd, John Kurkowski, and Marty.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
CS241 PASCAL I - Control Structures1 PASCAL Control Structures Modified Slides of Philip Fees.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Scripting with Ruby What is a scripting language? What is Ruby?
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
By Mr. Muhammad Pervez Akhtar
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
End of the beginning Let’s wrap up some details and be sure we are all on the same page Good way to make friends and be popular.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
Basic Data Types & Memory & Representation. Basic data types Primitive data types are similar to JAVA: char int short long float double Unlike in JAVA,
Definition of the Programming Language CPRL
Building Java Programs
Chapter 14 Introduction to Ruby.
Building Java Programs
expressions, variables, for loops
expressions, variables, for loops
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Building Java Programs Chapter 2
Lecture 5: Basic Java Syntax AP Computer Science Principles
Chapter 7 Expressions and Assignment Statements.
Building Java Programs
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Java Programming Language
In this class, we will cover:
Unit 3: Variables in Java
Building Java Programs Chapter 2
PRESENTED BY ADNAN M. UZAIR NOMAN
Introduction to Python
Presentation transcript:

Ruby! Useful as a scripting language – script: A small program meant for one time use – Targeted towards small to medium size projects Use by: – Amazon, Twitter, Yahoo!, White Pages, Reddit

Interpreted C/C++ – Compiled to assembly/Run directly on machine Java – Compiled to bytecode/Interpreted by JVM Ruby – Interpreted (no compilation)

irb (Ruby interpreter) Allows you to type commands one at a time and see results

Our First Program Ruby does not have a main method like Java – Just write your code directly in a file Ruby statements do not end with semicolons Method calls don’t need parenthesis

Expressions Arithmetic is similar to Java – Operators similar to Java + - * / % (plus ** for exponentiation) Precedence – () before ** before * / % before + - Integers vs Real Numbers

Unlimited Precision Java – There is a maximum value for integers – There is a maximum value for longs Ruby – There is no maximum! Fixnum Bignum – Why the distinction?

Declaring Strings “” allows escape sequences ‘’ does not allow escapes (excpet for \’)

Variables/Types Don’t declare types Ruby is looser about Types than Java – Type of variable can change throughout program

String Multiplication Strings can be multiplied by integers – Concatenates string repeatedly

Strings and Ints Integers and Strings cannot be concatenated in Ruby – to_s – converts to string – to_i – converts to integer

Loops The for loop – Java – Ruby

Loops The while loop – Java – Ruby

Constants Ruby doesn’t really have constants – Instead declare a variable at the top of your code and it will be accessible everywhere – You will get a warning if you change a constant, but you can change it anyway (bad style)

Parameters Parameters are declared by writing their names (no types) May seem odd that we can pass ints, strings, or arrays

Duck Typing Actually, we can pass anything that has a + method – This is called Duck Typing – Why would we limit our method to only operating on objects of type Duck? If it looks like a Duck and quacks like a Duck, then it’s a Duck This allows us to write flexible, reusable code

Inspecting Objects How do I know whether an object has a + method? – You can ask the object (with the “methods” method) – Everything is an object in Ruby (no primatives)

Default Parameter Values You can give a default value to parameters – The caller doesn’t have to pass a value

Math The Math module has methods and constants that you can use Has many of the same methods as Java

Returning Values Methods in Ruby return the last value evaluated (only do this if you’re an expert) You can also explicitly return values, and this is less error prone

Reading from the Console Java Ruby

If Statements Java Ruby

elsif Java Ruby

Logical Operators == != >= (just like Java) (not in Java) – Remember, because of Duck Typing these are applicable to more than just numbers – What might be useful for? && || ! (just like Java)

Arrays – More flexible than Java, can mix types – Many useful methods map, sort, delete, each, min, max, include?, select, shuffle, slice – Negative Indexing

Hashes In Java these are Maps – (you will learn about them in 143) – Ruby’s are more flexible; you can mix types Kind of like Arrays, but instead of indexing by numbers, you index by whatever you want

Multiple Assignment Can assign to and return multiple items at a time (uses arrays under the covers)

Reading Files Java Ruby

Writing Files Java Ruby