DOC PREVIEW
UW CSE 341 - Study Notes

This preview shows page 1-2-3-4-5-6-7-50-51-52-53-54-55-56-101-102-103-104-105-106-107 out of 107 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 107 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Page 1Page 2Page 3Page 4Page 5Page 6Page 7Page 8Page 9Page 10Page 11Page 12Page 13Page 14Page 15Page 16Page 17Page 18Page 19Page 20Page 21Page 22Page 23Page 24Page 25Page 26Page 27Page 28Page 29Page 30Page 31Page 32Page 33Page 34Page 35Page 36Page 37Page 38Page 39Page 40Page 41Page 42Page 43Page 44Page 45Page 46Page 47Page 48Page 49Page 50Page 51Page 52Page 53Page 54Page 55Page 56Page 57Page 58Page 59Page 60Page 61Page 62Page 63Page 64Page 65Page 66Page 67Page 68Page 69Page 70Page 71Page 72Page 73Page 74Page 75Page 76Page 77Page 78Page 79Page 80Page 81Page 82Page 83Page 84Page 85Page 86Page 87Page 88Page 89Page 90Page 91Page 92Page 93Page 94Page 95Page 96Page 97Page 98Page 99Page 100Page 101Page 102Page 103Page 104Page 105Page 106Page 107TCS Developer’s SIG February 6, 2007William Mitchell (whm)Mitchell Software Engineering (.com)A Look at RubyA Look at Ruby Slide 2William H. Mitchell, [email protected] Look at Ruby Slide 3William H. Mitchell, [email protected] is Ruby?Running RubyEverything is an objectVariables have no typeRuby's philosophy is often "Why not?"A Look at Ruby Slide 4William H. Mitchell, [email protected] is Ruby?"A dynamic, open source programming language with a focus on simplicity and productivity.It has an elegant syntax that is natural to read and easy to write." — ruby-lang.orgRuby is commonly described as an "object-oriented scripting language".Ruby was invented by Yukihiro Matsumoto ("Matz"), a "Japanese amateur languagedesigner" (his words). Here is a second-hand summary of a posting by Matz:"Well, Ruby was born on February 24, 1993. I was talking with my colleague about thepossibility of an object-oriented scripting language. I knew Perl (Perl4, not Perl5), but Ididn't like it really, because it had smell of toy language (it still has). Theobject-oriented scripting language seemed very promising." http://www.rubygarden.org/faq/entry/show/5Another quote from Matz:"I believe that the purpose of life is, at least in part, to be happy. Based on this belief,Ruby is designed to make programming not only easy but also fun. It allows you toconcentrate on the creative side of programming, with less stress. If you don’t believeme, read this book and try Ruby. I’m sure you’ll find out for yourself."A Look at Ruby Slide 5William H. Mitchell, [email protected] is Ruby?Ruby is a language in flux.• Version 1.8.5 is the stable, recommended version. Version 1.9 is available.• There is no written standard for Ruby. The language is effectively defined byMRI—Matz' Ruby Implementation.Ruby is getting a lot of attention and press at the moment. Two popular topics:• Ruby on Rails, a web application framework.• JRuby, a 100% pure-Java implementation of Ruby. With JRuby, among other things,you can use Java classes in Ruby programs. (jruby.codehaus.org)A Look at Ruby Slide 6William H. Mitchell, [email protected] RubyOne way to execute Ruby code is with irb, the Interactive Ruby Shell.irb evaluates expressions as are they typed.% irb>> 1 + 2=> 3>> "testing" + "123"=> "testing123">> it.upcase My ~/.irbrc defines it as the previous result.=> "TESTING123">> it.class=> String>> Math.cos(Math::PI / 3)=> 0.5A Look at Ruby Slide 7William H. Mitchell, [email protected] Ruby, continuedSource code in a file can be executed with the ruby command.By convention, Ruby files have the suffix .rb.Here is "Hello" in Ruby:% cat hello.rbputs "Hello, world!"% ruby hello.rbHello, world!%Note that the code does not need to be enclosed in a method—"top level" expressions areevaluated when encountered. (Later we'll see how to enclose code in a method.)Existing Ruby implementations have no notion of compilation to a binary. There are no"executables", intermediate code files, etc.A Look at Ruby Slide 8William H. Mitchell, [email protected] is an objectIn Ruby, every value is an object.Methods are invoked using value.method(parameters...).>> "testing".index("i")=> 4>> "testing".slice(2,3)=> "sti"Parentheses can be omitted from an argument list:>> "testing".gsub /[aeiou]/, "-"=> "t-st-ng"If a method requires no parameters the parameter list can be omitted.>> "testing".length=> 7A Look at Ruby Slide 9William H. Mitchell, [email protected] is an object, continuedOf course, "everything" includes numbers:>> 7.class => Fixnum>> 1.2.class => Float>> (30-40).abs => 10>> Math.exp(1).to_s=> "2.71828182845905">> 17**50=> 33300140732146818380750772381422989832214186835186851059977249>> it.class => BignumA Look at Ruby Slide 10William H. Mitchell, [email protected] have no typeIn languages like C and Java, variables are declared to have a type. The compiler ensuresthat all operations are valid for the types involved.Variables in Ruby do not have a type. Instead, type is associated with values.>> x = 10 => 10>> x = "ten" => "ten">> x.class => String>> x = x.length => 3Here's another way to think about this: Every variable can hold a reference to an object. Because every value is an object, any variable can hold any value.A Look at Ruby Slide 11William H. Mitchell, [email protected] have no type, continuedIt is often said that Java uses static typing. Ruby, like most scripting languages, usesdynamic typing.Sometimes the term strong typing is used to characterize languages like Java and weak typingis used to characterize languages like Ruby but those terms are now often debated andperhaps best avoided.Another way to describe a language's type-checking mechanism is based on when thechecking is done. Java uses compile-time type checking. Ruby uses run-time type checking.Some statically-typed languages do some type checking at run-time. An example of a run-time type error is Java's ClassCastException. C does absolutely no type-checking at run-time. Ruby does absolutely no type-checking at compile-time.Here's one discussion: http://www.artima.com/weblogs/viewpost.jsp?thread=46391A Look at Ruby Slide 12William H. Mitchell, [email protected] have no type, continuedIn a statically typed language a number of constraints can be checked at compile time. Forexample, all of the following can be verified when a C# program is compiled:x.getValue() x must have a getValue methodx * y x and y must


View Full Document

UW CSE 341 - Study Notes

Documents in this Course
Macros

Macros

6 pages

Macros

Macros

6 pages

Macros

Macros

3 pages

Mutation

Mutation

10 pages

Macros

Macros

17 pages

Racket

Racket

25 pages

Scheme

Scheme

9 pages

Macros

Macros

6 pages

Load more
Download Study Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Study Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Study Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?