Developer Experience

Summarized using AI

Python for Ruby Programmers

Mike Leone • February 21, 2013 • Burbank, CA

In the video "Python for Ruby Programmers," Mike Leone explores the similarities and differences between Python and Ruby, aiming to ease the transition for Ruby developers into Python. Leone emphasizes the shared principles of craftsmanship within the developer community and highlights the importance of continuously learning from different programming languages.

Key points discussed include:
- Introduction to Python: Leone sets the stage by apologizing for presentation formatting issues and prepares the audience for a fast-paced session, committing to cover Python's basics in 30 minutes.
- Profile of the Speaker: As the founder of Panoptic Development, Leone shares his journey from Ruby to Python, emphasizing how his experiences have enhanced his appreciation of both languages.
- Similarities: 13 similarities between Python and Ruby are outlined, such as:

- Both are dynamically typed and treat everything as an object.

- They support familiar data structures like arrays/lists and hash tables/dictionaries.

- Both languages embrace functional programming paradigms and allow named parameters.

- Reflective capabilities of objects are strong in both languages.

  • Differences: Leone enumerates 13 differences, including:

    • Ruby’s blocks versus Python's lack of this feature.
    • Python's first-class functions and stricter lambda constraints.
    • Python emphasizes readability through enforced indentation.
    • Python's explicit return requirements versus Ruby's implicit behavior.
  • Use Cases: Leone discusses five specific problem domains:

    • Web Development: Ruby is known for Rails, while Python excels with Django and Flask.
    • Mobile Development: Both languages have lesser-known capabilities, with RubyMotion and Python’s Kivy.
    • Desktop Applications: Python offers more mature frameworks compared to Ruby.
    • Scientific Programming: Python stands out with libraries like NumPy.
    • Windows Deployment: Python’s support leads to easier deployment compared to Ruby.
  • Conclusions and Takeaways: Leone encourages Ruby developers to embrace Python, asserting that it can enhance their skills and broaden their hiring possibilities. He believes that although Ruby's expressiveness offers elegance, Python’s clarity can lead to more maintainable code. In closing, he underscores the potential for both languages to coexist and complement each other in various development environments, inviting questions from the audience about either language.

Overall, the talk is designed to provide Ruby programmers with insight and guidance as they venture into Python programming while recognizing each language's unique strengths.

Python for Ruby Programmers
Mike Leone • February 21, 2013 • Burbank, CA

You've probably heard of Python, the _other_ popular, dynamic, multi-paradigm programming language. It occupies much of the same space as Ruby, has many similar language features, and the syntax even looks pretty similar. But what are the specific strengths and weaknesses of Python when compared to Ruby? What use cases are conducive to one language versus the other? In this talk, we look at some of the differences in language design, exploring how they affect application development and maintenance. Later, we look at some specific scenarios and show how the strengths of each language apply.

Help us caption & translate this video!

http://amara.org/v/FGdM/

LA RubyConf 2013

00:00:24.279 Hello, everyone. This is Mike Leone, starting off with Python for Ruby programmers. One thing about the Ruby community that I have always loved is the emphasis on learning and not getting religiously hung up on our language or tools.
00:00:30.519 We focus on software craftsmanship, continually looking to apply it and improve what we're doing, even if that sometimes means moving away from something that we once considered sacred.
00:00:39.520 As I mentioned, this is Mike Leone's session on Python for Ruby programmers. Following this talk, we have another presentation about Backbone, and then a third talk that delves into JRuby. All these topics are important tools that contribute to software development overall, and each has a focus on craftsmanship and the desire to improve.
00:01:07.400 With that said, I’d like to introduce Mike. He is the founder of Panoptic Development based in Rhode Island. He came to us from the East Coast, and I’m going to go ahead and hand the mic over to him, despite the awkward phrasing. Let’s get started with his presentation. Thank you.
00:01:34.680 Great, thank you! Alright everyone, welcome to Python for Ruby programmers. First, I would like to apologize for the formatting in this presentation. I had to switch laptops just before starting, so I will post the correctly formatted slides online right after this.
00:02:08.840 This presentation is going to be fast-paced. I'm going to teach you the basics of Python in about 30 minutes. But don't worry, coming from a Ruby background will make it very easy! First, a little about me. I'm the founder and principal engineer at Panoptic Development, where we build web, mobile, and embedded applications. We primarily use Ruby, JavaScript, and of course, Python.
00:02:40.120 This gives us a different perspective compared to most folks. We are based in the beautiful state of Rhode Island, which is known for its excellent seafood, massive political corruption, and of course, Family Guy. I started doing Ruby professionally in 2006, and then when a specific client application required Python, I began working with it in 2010.
00:03:06.319 It's been a great experience, and I have developed a new appreciation for the design decisions in each programming language. I believe this has made me a better Rubyist. Today, we will cover a quick example program in both languages, look at 13 language design similarities, discuss 13 differences, and talk briefly about five different problem domains.
00:03:41.080 Finally, I will share my personal feelings, which gives me the liberty to make wild statements without having to back them up. We won’t go into detail about specific implementations of either language. We also won’t really discuss performance, except to say that for the problem domains of each language, performance tends to be good enough, with Python usually performing a bit better.
00:04:05.400 I won’t discuss parallelism or multi-threaded programming because I'm not an expert. However, I will mention that the C implementations of both languages feature a global interpreter lock, making it difficult to write performant multi-threaded programs in those implementations.
00:04:40.000 I also won’t talk about minor syntax differences between the two languages, as they are truly minor. You'll catch on to them quickly, and I believe you’ll find it easy to read the code. What I'm going to try to convince you of during this presentation is that these two languages are very similar. Despite some major differences, they are more alike than different.
00:05:06.400 Moreover, you're already ready to start writing Python because of your Ruby experience—the jump is not a big one. Learning Python will make you a better Rubyist, and I hope to encourage you to consider hiring Python programmers even for Ruby programming positions.
00:05:39.960 Here are a few things I've extracted from the Zen of Python that I believe are relevant: 1. Explicit is better than implicit. 2. Flat is better than nested. 3. Readability counts. 4. There should generally be only one obvious way to do something. 5. Namespaces are a great idea—let's do more of those. Now, let’s create a Person class in both languages based on those principles. The requirements are that a person should have a name and an age, be able to greet you, know if they are Justin Bieber, and greet some folks from the Google board of directors.
00:06:40.199 Let’s look at the Ruby implementation, which is very straightforward. You declare a Person class and create an array of Google directors as a constant within that class. The typical initialize method sets the name and age, and you also have a few instance methods. The greeting method prints a statement with the name and age, and if the name matches exactly "Justin Bieber" and the age is exactly 18, it recognizes that. The method for greeting the Google directors loops through this array of directors and prints a greeting for each.
00:07:07.640 Now let’s look at this in Python. You create a Person object, define the Google directors constant within the class, and have an __init__ function to set the name and age. You also have the same instance methods. The loop syntax for greeting the Google directors is a bit different, but it's easy to follow.
00:07:36.520 You might notice a few differences, such as the self parameter used frequently and that the is_justin_bieber method explicitly returns a value. There are minor differences, but if we visually compare the two implementations, they are quite similar. In Python, methods do not end with an 'end' keyword; they simply use 'def'.
00:08:22.960 Let’s explore 13 similarities between the two languages: 1. Both languages are dynamically typed. For example, in Python, a print_object function can take any object as a parameter, as long as that object responds to the read method. If a file is passed, the function will return the file's contents. 2. Pretty much everything is an object in both languages. In Python, functions themselves are objects, which arguably makes it more consistent than Ruby. 3. Both languages support arrays (or lists in Python). In Ruby, it's called an array, while in Python, it's called a list, but they operate similarly. 4. Both languages also support hash tables. In Ruby, it's called a hash, while in Python, it's known as a dictionary (dict). Both allow similar access using the bracket notation. 5. Both languages support strong functional programming paradigms, such as using map and filter. You can pass functions as arguments in Python similarly to Ruby.
00:09:53.480 6. Optional or named arguments are supported in both languages. For example, in Python, a greet function can have a name parameter with a default greeting, allowing you to call it in multiple ways. 7. Argument unpacking works similarly in both languages, allowing you to pass a variable list of names to a function. 8. Raising and handling exceptions is very similar in both languages, and the control structures are mostly the same.
00:10:54.439 9. Both languages feature nice interactive shells. In Python, you can simply call it from the command line, while Ruby uses a different program for the interactive experience. 10. Each language features strong object reflection capabilities. For example, calling the class method on an instantiated object in Python will return the object's class. 11. Each language is significantly simpler than C++ or Java. 12. Each language supports one-line conditionals, with Ruby using 'if' at the end of a line and Python placing 'if' at the beginning.
00:12:03.920 Finally, 13. Both languages have strong object reflection features, enabling you to introspect the properties and methods available on an object easily. All these similarities indicate a common foundation in their design philosophies.
00:13:20.080 Now, let’s discuss 13 differences between them. One big difference is that Python does not have blocks. In Ruby, blocks are a killer feature that enables powerful metaprogramming, allowing you to create DSLs easily. While Python does have decorators, they are not as flexible or straightforward as Ruby's blocks.
00:13:55.520 Another major difference is that Python has first-class functions, which Ruby lacks. In Python, you can treat functions as variables, enabling you to pass them around directly without parentheses. Ruby can do something similar, but it’s more verbose and less intuitive.
00:14:38.680 Third, in Python, lambdas must be one line, which some might find limiting compared to Ruby, where lambdas can be multi-line, allowing for more complex anonymous functions. Generally, Python encourages more granular, named functions for readability.
00:15:30.080 Fourth, Python provides tuples, which are immutable lists, while Ruby has arrays that can be modified. This creates additional considerations for developers who need to manage state.
00:16:22.040 Five, Python has more fine-grained importing of libraries. For instance, when requiring libraries in Ruby, you typically bring in everything, which can be cluttered, whereas in Python, you can specify exact components to import.
00:17:24.000 Sixth, Python enforces indentation, which some developers find restrictive, but I believe it encourages consistency and readability in coding style. Seventh, Python has more values that evaluate to false, including empty lists and zero, compared to Ruby's simpler false and nil. Eighth, Python lacks Enumerable, which is a powerful Ruby feature. While Python provides built-in functions, they are not as robust as Ruby's Enumerable.
00:18:27.720 Ninth, Python's conditionals are simpler, utilizing if, elif, and else instead of case statements found in Ruby. Tenth, Python does not have 'unless', which can create confusion, while Ruby offers this additional control structure. Eleventh, Python functions require an explicit return statement to avoid getting None, which could lead to confusion for Rubyists who expect automatic returns.
00:19:25.720 Twelfth, Python requires the self argument for every instance method to make the reference explicit, which can seem verbose compared to Ruby's implicit handling. Thirteenth, Python has limited metaprogramming features compared to Ruby, including the inability to modify classes dynamically as you can in Ruby.
00:20:24.919 Next, let's explore five problem domains briefly. First, in web development, while Ruby is known for Rails and Sinatra, Python has popular frameworks like Django, Flask, and Pyramid, which serve similar purposes.
00:21:24.960 Secondly, while both languages are not primarily used for mobile applications, both have libraries to support mobile development. Ruby has RubyMotion, while Python has Kivy and BeeWare.
00:22:00.240 When it comes to desktop applications, while Python has tools like Tkinter and wxPython, Ruby lacks mature frameworks but does have the Gardener and Shoes libraries.
00:22:47.560 In the realm of scientific programming, Python is well-regarded for libraries like NumPy and SciPy, which facilitate scientific computing, while Ruby still lacks equivalent mature libraries.
00:23:38.600 Finally, with Windows deployment, Python's popularity translates to a more significant number of available ports and test cases, making it easier to deploy applications on Windows compared to Ruby, where deployment can be cumbersome due to fewer community resources.
00:24:49.720 Wrapping this up, I believe that Python has a clearer, more concise coding style that encourages readability and maintainability. Although Ruby offers greater expressiveness and elegance, the two languages can complement each other in various scenarios. I encourage you to try Python and discover its strengths, especially if you're accustomed to Ruby.
00:25:29.120 At this point, I’d like to discuss my personal feelings about the two languages. I think it’s harder to write confusing code in Python due to its strict syntax and limited constructs. The grammar is smaller, which means the way Python code looks is likely to be similar across different users.
00:26:02.680 In contrast, Ruby's flexibility can lead to diverse coding styles and practices, which sometimes produces contentious discussions among developers. However, I also believe Ruby has a certain elegance and power that allows for expressive code.
00:26:43.200 Specifically for web development, Ruby continues to have a stronghold due to frameworks like Rails, which facilitate rapid development. I still believe that Rails remains unmatched in delivering robust web applications. However, Python’s frameworks like Django have their strengths and advantages.
00:27:28.560 Considering hiring practices, Python developers are currently more abundant than Ruby developers. Those involved in hiring should consider the feasibility of hiring talented Python developers even for Ruby projects, as they might adapt quickly to Ruby with their foundational programming skills.
00:28:16.320 In conclusion, I hope you find the transition from Ruby to Python as rewarding as I have. There are opportunities and challenges with both languages, but they can work together and complement one another in various ways.
00:29:07.600 Thank you for your time today, and I’m happy to take any questions you may have about Python or Ruby. I appreciate your attention!
Explore all talks recorded at LA RubyConf 2013
+6