Python for Ruby Programmers

2 min read Original article ↗

A presentation comparing the Python and Ruby programming languages. I gave this talk at LA RubyConf 2013.

Avatar for Mike Leone

Transcript

  1. About Me

  2. Web Mobile Embedded

  3. That's it.

  4. Ruby: 2006 Python: 2010

  5. New appreciation Better Rubyist

  6. What we'll cover

  7. What we WON'T cover

  8. What I'll try to convince you:

  9. Zen of Python (abridged)

  10. Example: Create a Person class

  11. 13 Similarities

  12. 1. Dynamically Typed

  13. 2. Everything is an Object (even functions!)

  14. 3. Arrays

  15. 4. Hash Tables

  16. 5. No special line terminators (no semicolons!)

  17. 6. Strong functional programming paradigms

  18. 7. Awesome function parameters

  19. Optional / named arguments

  20. Argument Unpacking

  21. 8. Raising Exceptions

  22. 9. Handling Exceptions

  23. 10. One-line conditionals

  24. 11. Nice interactive shells

  25. 12. Strong object reflection features

  26. 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']

  27. 13. Radically simpler than C++/Java!

  28. 13 Differences

  29. 1. No blocks

  30. Blocks are the killer feature of Ruby

  31. 1. Powerful metaprogramming 2. DSLs 3. Great frameworks (Rails)

  32. Decorators are a powerful Python feature similar to blocks.

  33. 2. First-class Functions

  34. Functions as variables

  35. 3. One-line lambdas, by design

  36. Python pushes you to factor things out into granular methods.

  37. Python even supports inner methods to this end.

  38. 4. Python has “tuple,” an immutable list.

  39. 5. Python has more fine-grained importing

  40. 6. Python enforces indentation

  41. In practice, this is pretty awesome.

  42. Doesn't cause headaches. Makes code style more consistent.

  43. 7. Python has more values that evaluate to False.

  44. False None (nil) [ ], (), {} ' ' 0

  45. 8. Instead of Enumerable, Python has built-in functions

  46. filter() map() reduce()

  47. Convenient, but not as powerful as Enumerable.

  48. 9. Python has simpler conditionals

  49. 10. No automatic return values

  50. 11. “self” as an argument to every class instance method

  51. 12. No powerful module mixins like Ruby.

  52. Multiple inheritence only (yuck)

  53. 13. Ruby has stronger metaprogramming features

  54. Python doesn't have define_method class_eval method_missing

  55. 5 Problem Domains

  56. 1. Web Development

  57. Ruby: Rails, Sinatra Ruby community is dominated by web development

  58. 2. Mobile Applications

  59. 3. Desktop Applications

  60. 4. Scientific Programming

  61. 5. Windows Deployment (if you must)

  62. The Python community is just bigger.

  63. “Feelings”

  64. Rails still wins for web development.

  65. Need to hire a Rubyist? Hire a Pythonista instead.

  66. Wrap-up

  67. MIKE LEONE panopticdev.com leone.panopticdev.com @panopticdev @facebiff THANK YOU!