A presentation comparing the Python and Ruby programming languages. I gave this talk at LA RubyConf 2013.
Transcript
-
About Me
-
Web Mobile Embedded
-
That's it.
-
Ruby: 2006 Python: 2010
-
New appreciation Better Rubyist
-
What we'll cover
-
What we WON'T cover
-
What I'll try to convince you:
-
Zen of Python (abridged)
-
Example: Create a Person class
-
13 Similarities
-
1. Dynamically Typed
-
2. Everything is an Object (even functions!)
-
3. Arrays
-
4. Hash Tables
-
5. No special line terminators (no semicolons!)
-
6. Strong functional programming paradigms
-
7. Awesome function parameters
-
Optional / named arguments
-
Argument Unpacking
-
8. Raising Exceptions
-
9. Handling Exceptions
-
10. One-line conditionals
-
11. Nice interactive shells
-
12. Strong object reflection features
-
steve = Person("Steve Ballmer", 54) steve.__dict__ >>> {'age': 54, 'name':
'Steve Ballmer'} steve.__class__ >>> <class 'person.Person'> dir(steve) # all methods/attrbutes ['GOOGLE_DIRECTORS', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'age', 'greet', 'greet_google_directors', 'is_justin_beiber', 'name', 'say_name_and_age']
-
13. Radically simpler than C++/Java!
-
13 Differences
-
1. No blocks
-
Blocks are the killer feature of Ruby
-
1. Powerful metaprogramming 2. DSLs 3. Great frameworks (Rails)
-
Decorators are a powerful Python feature similar to blocks.
-
2. First-class Functions
-
Functions as variables
-
3. One-line lambdas, by design
-
Python pushes you to factor things out into granular methods.
-
Python even supports inner methods to this end.
-
4. Python has “tuple,” an immutable list.
-
5. Python has more fine-grained importing
-
6. Python enforces indentation
-
In practice, this is pretty awesome.
-
Doesn't cause headaches. Makes code style more consistent.
-
7. Python has more values that evaluate to False.
-
False None (nil) [ ], (), {} ' ' 0
-
8. Instead of Enumerable, Python has built-in functions
-
filter() map() reduce()
-
Convenient, but not as powerful as Enumerable.
-
9. Python has simpler conditionals
-
10. No automatic return values
-
11. “self” as an argument to every class instance method
-
12. No powerful module mixins like Ruby.
-
Multiple inheritence only (yuck)
-
13. Ruby has stronger metaprogramming features
-
Python doesn't have define_method class_eval method_missing
-
5 Problem Domains
-
1. Web Development
-
Ruby: Rails, Sinatra Ruby community is dominated by web development
-
2. Mobile Applications
-
3. Desktop Applications
-
4. Scientific Programming
-
5. Windows Deployment (if you must)
-
The Python community is just bigger.
-
“Feelings”
-
Rails still wins for web development.
-
Need to hire a Rubyist? Hire a Pythonista instead.
-
Wrap-up
-
MIKE LEONE panopticdev.com leone.panopticdev.com @panopticdev @facebiff THANK YOU!