If you can't read please download the document
Upload
aizat-faiz
View
7.709
Download
0
Embed Size (px)
Citation preview
Ruby
A Programmer's Best Friend
http://creativecommons.org/licenses/by/2.5/
Disclaimer:This ((might|will) be|is) a Technical Talk
Disclaimer:This might be a Technical TalkThis will be a technical talkThis is a Technical talk
You decide.
aizat.who?
Ezwan Aizat Bin Abdullah Faiz
Web Developer
Ruby, Ruby on Rails, PHP, LAMP
(Previous) MyOSS Meetup Organizer
My Background
Still a University Student
Monash University
10 years ago
Basic HTML
Took a long break
5 years ago, I tried to learn
C++
3 years ago, I learned
PHP
1 year ago, I experimented with
C, Ruby, Python
Winner of the eGenting Competition 2006
using Ruby
Ruby.is_a?
Programming Language
Interpreted Scripting Language
Duck language
Inspired from:
Smalltalk, Perl, Lisp, Python, CLU, Dylan
Syntax is generally like all other programming languages
Ruby's History and Background
Developed in Japan
Yukihiro Matsumoto
Was in Malaysia last year for AsiaOSS
First public Release in 1995
Aim was in trying to make Ruby natural, not simple,
Often people, especially computer engineers, focus on the machines. They think, "By doing this, the machine will run faster. By doing this, the machine will run more effectively. By doing this, the machine will something something something."They are focusing on machines. But in fact we need to focus on humans, on how humans care about doing programming or operating the application of the machines.We are the masters. They are the slaves.
Yukihiro Matsumoto
Basic Features
Classes, Inheritance
Threads
Cross Platform
Iterators and Closures
Garbage Collection
Exception Handling
Object Oriented
Regular Expressions
Variables are not typed
Powerful string operations
Operator Overloading
Introspection, Reflection, Meta programming
To Ruby From Java
Similarities
Garbage Collector
Objects are strongly typed
public, private and protected methods
Embedded doc tools
Differences
Don't need to compile code, just run it
No static type checking
No casting
http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/
To Ruby From PHP
Similarities
Dynamically typed
eval
Fairly large standard library
Arrays and hashes work like expected
Differences
Strong typing
Everything is an object
No abstract classes or interfaces
Almost everything is a method call
http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php/
Ruby declared TIOBE's Programming Language of 2006
http://www.oreillynet.com/ruby/blog/2007/01/ruby_declared_tiobes_programmi.html
TIOBE Programming Community Index
TIOBE Programming Community Index
In the recent past it was necessary to have a large company behind the language to get it in the spotlight (Sun with Java, Microsoft with C#), but nowadays a killer app appears to be sufficient. Viral marketing via the Internet works! The winners of the last 2 years, PHP and Java, are the losers of this year.
Generally its like all other programming languages,
Except with a few syntax changes
Conditions
General
Ruby
if condition # ...elsif condition2 # ...else # ...end
b = a if condition
unless condition # ...else # ...end
b = a unless condition
if (condition) { # ...} else if (condition2) { # ...} else { # ...}
Loops
General
Ruby
while i < 5 # ...end
until i == 5 # ...end
apples.each { |apple| ... }shapes.each do |shape| puts shape.polygon? puts shape.sides?end
while (condition) { # ...}
for (int i; i < array.length; i++) { # ...}
Exception Handling
Ruby
General
try { # ...} catch (Exception e) { # ...} finally { # ...}
begin # ...rescue RuntimeException => e # ...rescue e # ...ensure # ...end
The Differences
Ruby is simple in appearance, but is very complex inside, just like our human body
Yukihiro Matsumoto
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/2773
Optional SyntaxFull of Expression
Expression
Parentheses are optionals (sometimes)
Semicolons are optional
Methods can include '!' and '?'
array.uniq.sort
Ruby IS THE BOMB.downcase!
Regular expressions are fun.gsub(/fun/, 'sweet')
Wasting space .strip!
Simpler AND Nicerlooking code
Everything is an Object
Numbers and other primitive types are not objects
1.upto(100) { |i| puts i }
3.14159265.ciel
2.71828182845905.floor
Meta Programming
(or shooting oneself in the foot)
What is Meta Programming?
Metaprogramming is the writing of computer programs that write or manipulate other programs (or themselves) as their data or that do part of the work during compile time that is otherwise done at run time.
In many cases, this allows programmers to get more done in the same amount of time as they would take to write all the code manually.Taken from http://en.wikipedia.org/wiki/Metaprogramming
Magic!
Santize a string
Convert all non alphanumeric to a 'underscore'
class String def sanitize self.gsub(/[^a-z1-9]+/i, '_') endendputs "Ruby gives you alot of $$$ yo!".sanitize# Ruby_gives_you_alot_of_yo_
Need to shuffle an array?
class Array def shuffle size.downto(1) { |n| push delete_at(rand(n)) } self endend%w[a b c d e f g].shuffle# ["c", "e", "f", "g", "b", "d", "a"]
Why Ruby?
Simpler and concise
Full of expression
Easier to understand
Productive
Large number of libraries
But, mainly because it's a lot more FUN
Who uses Ruby?
HP
Sun
Microsoft
Intel
NASA
NOAA
37 signals
etc...
Whole community built around it
Ruby Central - Non Profit Organization
Ruby Conference
etc...
Ruby on Rails
Convention over Configuration
http://www.rubyonrails.com
Hottest thing to hit Web Development
Web Application Framework
Rapid Application/Iterative Development
AJAX ready
Convention over Configuration
Why Ruby?
Dynamic
Flexible
Utilizes Meta Programming heavily
Domain specific language
Buzz Words Buzz Words Buzz Words
Popular Sites
Basecamp
Project Management
What are you doing?
Why not Ruby?
Several Limitations
Slow performance
not massively, just marginally
Benefit is better code
Now a days we have processing cycles to waste
Write it in Ruby C Extensions!
Fixed in Ruby 2.0
Limited Unicode Support
Fixed in Ruby 2.0
So when is Ruby 2.0 coming out?
Hopefully soon...
ResourcesPrograms
IRB Interactive Ruby
Experiment with Ruby from the command line
Write quick code snippets
Enhanceable using Ruby
Support syntax highlighting
$ irb>> puts Hello WorldHello World=> nil>>
RI Ruby Information
Quick Ruby documentation
Takes from both the ruby core code and the external libraries (rubygems)
$ ri String#chop!Returns a new String with the last character removed. If the string ends with \r\n, both characters are removed. Applying chop ...
ResourcesSites
Informational
Ruby Progamming Language
http://www.ruby-lang.org
Wikipedia
all knowing, all powerful Wikipedia
http://www.ruby-lang.org
Learning
Why's (Poignant) Guide to Ruby
http://poignantguide.net/ruby/
Ruby In Twenty Minutes
http://www.ruby-lang.org/en/documentation/quickstart/
MyOSS Meetup
Bob Sutor
Speaking on Open Source, Open Standards and ODF
The Shift to 'Open': Boost or Brakes for Innovation and Business
20th April (next Friday)
Open University Malaysia (near KLCC)
7:00-9:30pm
http://foss.org.my/projects/meetups/april-2007
Questions?
Thank You
Let's Dive Into Ruby
Click to edit the title text format
Click to edit the outline text format
Second Outline Level
Third Outline Level
Fourth Outline Level
Fifth Outline Level
Sixth Outline Level
Seventh Outline Level
Eighth Outline Level
Ninth Outline Level
http://foss.org.my