Upload
ziming-hu
View
1.273
Download
2
Embed Size (px)
Citation preview
Why not Ruby?Why not Ruby?Why not Ruby?Why not Ruby?
vs. pythonvs. python
Wang Yu HuiPorss Inc., [email protected]
History and Motivation• Ruby is a programming language developed by YukihiroMatsumoto (a.k.a. Matz) in 1993 It was originally designed to be a better Perl than Perl (that‘s the
reason for its name)• It is available on multiple platforms such as Linux, MacOS X,Windows• According to Matz its primary application domains are Textprocessing, CGI-, Network-, GUI-, XML-programming,Prototyping, Programming education• Ruby has adopted features from languages such as Perl, Lisp,Smalltalk• It is very popular in Asia, especially in Japan
What’s Ruby?• Paradigm: Pure OO language• Simple and without surprises: Easy to learn and
understand• Potential: Powerful and expressive• Add Ons: Rich library support• Productive: Rapid development• Non commercial: Open Source• Robust: Garbage Collector on Board• Flexible: Untyped, dynamic language• And of course: It‘s cool!
Small Example#This is just to show you an example
class MyFirstRubyProgramdef SayHello(name=“Cooler“)
puts "Hello, #{name}!"end
end
MyFirstRubyProgram.new.SayHello(“Benjamin")
Comments
Define a class
Default parameter
Define a function
Everything is an object• "Hello World!".length• -42.abs• nil is a regular object
Regular expressions are well supported
s = "Hello World"p s.gsub(/[aeiou]/,“*")H*ll* W*rld
t = "11:55:00“if t =~ /\d\d:\d\d:\d\d/then
puts "yes"else
puts "no"endyes
Ruby Vs. Python• http://c2.com/cgi/wiki?PythonVsRub
y• GUI, Graphics, Web, Libs …
Overview• HighLevel, GarbageCollected, and
DynamicallyTyped
Heritage and Philosophy
• Ruby– from Smalltalk and Perl– EverythingIsAnObject – ThereIsMoreThanOneWayToDoIt
• Python– from Algol and Lisp– There should be one - and preferably only one - obvious
way to do it.
Code Style• Red/Black Tree ImplementationRuby : http://www.dmh2000.com/cjpr/RBRuby.htmlPython: http://www.dmh2000.com/cjpr/RBPython.html
Python indenting vs. Ruby explicit 'end‘Python requirement for explicit 'self' parameter to
methods and instance variable access is very annoyingRuby OO completeness is a win over PythonRuby rescue/ensure vs. Python try/catch/finallyRuby “Syntax error” vs. Python “call stack”
Community and Documentation
• Ruby– Rubyforge.org– Ruby-lang.org– Ruby-doc.org– …
• Python– CPUG
I think ruby community is better and more friendly
Libs• Python has better UNICODE support• Python's libraries are more plentiful and more
mature• Ruby, however, can take advantage of Python
libraries through the use of Ruby/Python• Ruby's API for C integration is much, much
cleaner than Python's
GUI• Ruby
– Tcl/tk• Python
– Tcl/tk– wxPython– PyGTK– PyQT– PySWT
Graphics and Images• Ruby
– rmagick• Python
– PIL: Python Imaging Library– PyOpenGL– Blender– matplotlib– yapgvb
Web Development• Ruby
– Ruby On Rails• Python
– mod python + Apache– zope/plone– karrigell– cherrypy– django– turbogears
Ruby on Rails• full-stack, open-source web framework (support
structure) in Ruby • Creating a weblog in 15 minutes• Model-View-Control pattern• From theAjax in the view, to the request and response in the
controller, to the domain model wrapping the database
• Web2.0
Websites• http://www.37signals.com/• http://www.43things.com
• http://www.soopie.com
Embedded• Ruby
– Ruby for Symbian• Python
– Python for Symbian
Lib Install• Ruby
– RubyGems• Python
– Every module has it’s own method
Resources• Programming Ruby • Learning Ruby from an Indian• Why Ruby?
• Ruby-lang.org• Ruby-doc.org• Rubyforge.org• RubyOnRails.org