20
Why not Ruby? Why not Ruby? vs. python vs. python Wang Yu Hui Porss Inc., Ltd yuhui.wang@gmail. com

20061216 rubyvspython

Embed Size (px)

Citation preview

Page 1: 20061216 rubyvspython

Why not Ruby?Why not Ruby?Why not Ruby?Why not Ruby?

vs. pythonvs. python

Wang Yu HuiPorss Inc., [email protected]

Page 2: 20061216 rubyvspython

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

Page 3: 20061216 rubyvspython

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!

Page 4: 20061216 rubyvspython

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

Page 5: 20061216 rubyvspython

Everything is an object• "Hello World!".length• -42.abs• nil is a regular object

Page 6: 20061216 rubyvspython

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

Page 7: 20061216 rubyvspython

Ruby Vs. Python• http://c2.com/cgi/wiki?PythonVsRub

y• GUI, Graphics, Web, Libs …

Page 8: 20061216 rubyvspython

Overview• HighLevel, GarbageCollected, and

DynamicallyTyped

Page 9: 20061216 rubyvspython

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.

Page 10: 20061216 rubyvspython

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”

Page 11: 20061216 rubyvspython

Community and Documentation

• Ruby– Rubyforge.org– Ruby-lang.org– Ruby-doc.org– …

• Python– CPUG

I think ruby community is better and more friendly

Page 12: 20061216 rubyvspython

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

Page 13: 20061216 rubyvspython

GUI• Ruby

– Tcl/tk• Python

– Tcl/tk– wxPython– PyGTK– PyQT– PySWT

Page 14: 20061216 rubyvspython

Graphics and Images• Ruby

– rmagick• Python

– PIL: Python Imaging Library– PyOpenGL– Blender– matplotlib– yapgvb

Page 15: 20061216 rubyvspython

Web Development• Ruby

– Ruby On Rails• Python

– mod python + Apache– zope/plone– karrigell– cherrypy– django– turbogears

Page 16: 20061216 rubyvspython

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

Page 17: 20061216 rubyvspython

Websites• http://www.37signals.com/• http://www.43things.com

• http://www.soopie.com

Page 18: 20061216 rubyvspython

Embedded• Ruby

– Ruby for Symbian• Python

– Python for Symbian

Page 19: 20061216 rubyvspython

Lib Install• Ruby

– RubyGems• Python

– Every module has it’s own method

Page 20: 20061216 rubyvspython

Resources• Programming Ruby • Learning Ruby from an Indian• Why Ruby?

• Ruby-lang.org• Ruby-doc.org• Rubyforge.org• RubyOnRails.org