Talks
Speakers
Events
Topics
Sign in
Home
Talks
Speakers
Events
Topics
Leaderboard
Use
Analytics
Sign in
Suggest modification to this talk
Title
Description
Defensive programming is one of those abstract ideas that seems great. We all want to use these ideas to ensure the long-term maintainability of our codebases. It is, however, often unclear what we should be defending against and what form those defenses should take. We can find places where defensive patterns could be added by looking at the edge cases that occur in our system. Where it seems appropriate, we can then apply ideas and patterns from defensive programming. In this talk we'll look at some of the extremely defensive patterns that have been driven out in RSpec throughout the years. We'll look at building Ruby that works accross a wide range of interpreters and versions (including 1.8.7!). We'll investigate how you can write code that defends against objects that redefine methods like send, method and is_a?. We'll also see how the behaviour of prepend can occasionally confuse even the most mature source bases. You should come to this talk if you want to learn about inheritence and method resolution in Ruby, defensive programming techniques and cross interpreter Ruby patterns. Help us caption & translate this video! http://amara.org/v/H4Ob/
Date
Summarized using AI?
If this talk's summary was generated by AI, please check this box. A "Summarized using AI" badge will be displayed in the summary tab to indicate that the summary was generated using AI.
Show "Summarized using AI" badge on summary page
Summary
Markdown supported
### Introduction In the talk "Extremely Defensive Coding" presented at ArrrrCamp 2015 by Sam Phippen, the focus is on the importance of defensive programming in Ruby, particularly within the context of testing frameworks like RSpec. Defensive programming helps ensure code maintainability and robustness by anticipating and guarding against potential issues arising from external modifications and peculiarities of the Ruby environment. ### Key Points - **Understanding Defensive Programming:** - Defensive programming involves anticipating edge cases and potential changes to the methods that might be redefined by users or libraries. - It emphasizes the need for consistency in overriding core Ruby methods to make objects behave as expected. - **The Challenge of RSpec:** - RSpec as a testing tool has complexities due to its necessity to adapt to various Ruby objects that might redefine core behavior, such as the `method` method. - A key question posed during the talk was about the appropriate scenarios to override methods on objects to maintain consistency. - **Gem Convenience vs. Implementation Complexity:** - Phippen argues that while a gem's functionality is important, its interface is crucial as it should allow developers to leverage the gem's capabilities without requiring them to understand its complex internal workings. - The effectiveness of a gem can depend on how well it integrates with different Ruby versions and environments. - **User Examples in RSpec:** - The talk illustrates the user's perspective through a user story related to stubbing objects in RSpec. Users expect that operations like stubbing should not alter the original methods on their objects after tests run, emphasizing the need for RSpec to handle method restoration seamlessly. - **Defensive Coding Techniques:** - Phippen elaborates on the technique of saving method objects and dealing with dynamic method redefinition by employing Ruby's metaprogramming capabilities. - The robustness of the RSpec framework relies on its ability to adopt variations in how Ruby interpreters handle method definitions and object behaviors, ensuring it functions correctly across different Ruby environments. ### Conclusion The talk concludes with a reiteration of the necessity of dealing with the unpredictability of user-defined changes in Ruby. The underlying message is that good gems are those that hide their complexity behind a simple interface, allowing users to work effectively without interference from the inner workings. Ultimately, Phippen emphasizes the importance of writing code that defends against potential issues to uphold code quality and reliability in the face of future changes in Ruby's dynamic environment. ### Key Takeaways - Embrace defensive programming to anticipate and mitigate issues arising from method redefinitions. - Aim to create convenient interfaces for gems that mask internal complexities. - RSpec exemplifies adaptive behavior to accommodate the diverse Ruby landscape, making it a valuable tool for developers.
Suggest modifications
Cancel