ruby an overall approach
DESCRIPTION
An overall approach of Ruby. Presentation given at a paradigm programming course at FEUP ’12.TRANSCRIPT
![Page 1: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/1.jpg)
RUBYan overall approach
Felipe Schmitt PPRO@FEUP 2012
![Page 2: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/2.jpg)
@schmittfelipe
![Page 3: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/3.jpg)
CONTENTS
• Ruby’s history
• What is Ruby?
• Programming paradigms insight
• How it works?
• Ruby’s usage
• Where can I learn more?
![Page 4: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/4.jpg)
RUBY’S HISTORY
![Page 5: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/5.jpg)
Yukihiro Matsumoto
Timeline: 1993 - 2000
• Created in 1993
• Popular only in Japan
• All documentation written in Japanese
![Page 6: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/6.jpg)
Timeline: 2000 - 2004
• First english language book published in 2000
• Ruby has gained a lot of interest in Agile Development community but still unknown elsewhere
![Page 7: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/7.jpg)
Timeline: 2004 - Today
• Ruby on Rails, the framework that allowed ruby to step up to the spotlight
• Ruby v1.9
• Core 100% documented
• 96 standard libraries
![Page 8: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/8.jpg)
WHAT IS RUBY?
![Page 9: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/9.jpg)
“I wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. That's why I decided to design my own language.”
-Yukihiro Matsumoto
![Page 10: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/10.jpg)
INFLUENCES
Smalltalk
Perl
Python
CLU
Lisp
Ruby
![Page 11: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/11.jpg)
WHAT 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.
![Page 12: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/12.jpg)
PROGRAMMING PARADIGMS
![Page 13: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/13.jpg)
• Functional
• Object oriented
• Imperative
• Reflective
It also has a dynamic type system and automatic memory management;
Multi-paradigm programming language
![Page 14: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/14.jpg)
HOW IT WORKS?
![Page 15: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/15.jpg)
VS
![Page 16: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/16.jpg)
class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); }}
HelloWorld.java
Getting Started
![Page 17: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/17.jpg)
puts “Hello World!”
HelloWorld.rb
No main statement
No semicolons
Getting Started
( )’s are optional
![Page 18: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/18.jpg)
Object
String s = String.ValueOf(1);Java
![Page 19: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/19.jpg)
Object
s = 1.to_sRuby
String s = String.ValueOf(1);Java
![Page 20: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/20.jpg)
Everything is an object!
Object
String s = String.ValueOf(1);Java
s = 1.to_sRuby
![Page 21: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/21.jpg)
public void foo(ArrayList list) {list.add(“foo”);}
Java
Types
![Page 22: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/22.jpg)
Types
def foo listlist << “foo”
end
Ruby
public void foo(ArrayList list) {list.add(“foo”);}
Java
![Page 23: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/23.jpg)
Types
(?) return
(?) Object type
def foo listlist << “foo”
end
Ruby
public void foo(ArrayList list) {list.add(“foo”);}
Java
![Page 24: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/24.jpg)
If list is a string: ‘foo’
If list is an array: [‘foo’]
If list is a stream: foo is written to stream
Types
def foo listlist << “foo”
end
Ruby
![Page 25: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/25.jpg)
Duck Typing
“If it walks like a duck and quacks like a duck, it must be a duck.”
- Pragmatic Dave Thomas
![Page 26: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/26.jpg)
Loops N + 1 errors
Iterators
No for loops:
array.each { |item| puts item }
Ruby
Objects manage their own transversal
![Page 27: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/27.jpg)
Open classes
class Array def average inject do |sum, var|
sum + varend / size
endend
nums = [1,2,3,4,5]puts nums.average
Ruby
Existing classes can be modified at any time.
#prints: 3
![Page 28: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/28.jpg)
WHO’S USING RUBY?
![Page 29: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/29.jpg)
![Page 30: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/30.jpg)
RECAP
• Perl’s syntax
• Smalltalk’s semantics
• Python’s design philosophy
Influences• Everything is an object
• Flexible
• Large standard library
Overall• Simplicity
• Productivity
• Elegant syntax
Style
“Actually, I'm trying to make Ruby natural, not simple.”- Matz
![Page 31: Ruby an overall approach](https://reader033.vdocuments.us/reader033/viewer/2022052410/555219b9b4c9054c668b463a/html5/thumbnails/31.jpg)
http://www.fincher.org/tips/Languages/Ruby/
MORE STUFF
http://www.slideshare.net/vishnu/the-top-10-reasons-the-ruby-programming-language-sucks
http://www.slideshare.net/mbowler/ruby-for-java-programmers
http://www.ruby-lang.org/
Agile Web Development with Rails (2011) 4th edition Pragmatic Programmers by Sam Ruby, Dave Thomas and David Heinemeier Hansson
Books
Web
The Ruby Programming Language (2008)O’reilly by David Flanagan and Yukihiro Matsumoto
Beginning Ruby: From Novice to Professional (2009)The Expert’s Voice by Peter Cooper