Upload
felipe-schmitt
View
1.133
Download
0
Tags:
Embed Size (px)
DESCRIPTION
An overall approach of Ruby. Presentation given at a paradigm programming course at FEUP ’12.
Citation preview
RUBYan overall approach
Felipe Schmitt PPRO@FEUP 2012
@schmittfelipe
CONTENTS
• Ruby’s history
• What is Ruby?
• Programming paradigms insight
• How it works?
• Ruby’s usage
• Where can I learn more?
RUBY’S HISTORY
Yukihiro Matsumoto
Timeline: 1993 - 2000
• Created in 1993
• Popular only in Japan
• All documentation written in Japanese
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
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
WHAT IS RUBY?
“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
INFLUENCES
Smalltalk
Perl
Python
CLU
Lisp
Ruby
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.
PROGRAMMING PARADIGMS
• Functional
• Object oriented
• Imperative
• Reflective
It also has a dynamic type system and automatic memory management;
Multi-paradigm programming language
HOW IT WORKS?
VS
class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); }}
HelloWorld.java
Getting Started
puts “Hello World!”
HelloWorld.rb
No main statement
No semicolons
Getting Started
( )’s are optional
Object
String s = String.ValueOf(1);Java
Object
s = 1.to_sRuby
String s = String.ValueOf(1);Java
Everything is an object!
Object
String s = String.ValueOf(1);Java
s = 1.to_sRuby
public void foo(ArrayList list) {list.add(“foo”);}
Java
Types
Types
def foo listlist << “foo”
end
Ruby
public void foo(ArrayList list) {list.add(“foo”);}
Java
Types
(?) return
(?) Object type
def foo listlist << “foo”
end
Ruby
public void foo(ArrayList list) {list.add(“foo”);}
Java
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
Duck Typing
“If it walks like a duck and quacks like a duck, it must be a duck.”
- Pragmatic Dave Thomas
Loops N + 1 errors
Iterators
No for loops:
array.each { |item| puts item }
Ruby
Objects manage their own transversal
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
WHO’S USING RUBY?
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
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