Talks
Speakers
Events
Topics
Sign in
Home
Talks
Speakers
Events
Topics
Leaderboard
Use
Analytics
Sign in
Suggest modification to this talk
Title
Description
What happens with Rails ends and our custom business logic begins? Many of us begin writing "service objects", but what exactly is a service object? How do we break down logic within the service object? What happens when a step fails? In this talk, we'll go over some of the most common approaches to answering these questions. We'll survey options to handle errors, reuse code, organize our directories, and even OO vs functional patterns. There isn't a perfect pattern, but by the end, we'll be much more aware of the tradeoffs between them.
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
In the talk titled "Missing Guide to Service Objects in Rails" presented by Riaz Virani at RailsConf 2021, the speaker explores the concept of service objects within the Ruby on Rails framework and the rationale for their use. The presentation outlines the transition from Rails as a 'batteries included' framework, which provides standard patterns for application structure, to recognizing the limitations when implementing custom business logic. The speaker emphasizes that while Rails offers their basic components like MVC and Active Job, developers often encounter complexity when deep business logic is involved. Key points discussed in the talk include: - **Definition of Service Objects**: Service objects are defined as code that represents and executes business processes specific to an application. Their purpose is to encapsulate the steps necessary for tasks such as user creation or order processing. - **Patterns for Implementation**: The speaker contrasts object-oriented (OO) patterns with functional patterns for structuring service objects. Using OO can result in tightly coupled code that is harder to reuse, whereas functional programming allows clearer sequencing of operations. - **Error Handling**: Riaz discusses various ways to handle errors within service objects including: - Nested conditionals, which can produce complex and unreadable code. - Raising exceptions, which, while familiar, can lead to performance issues due to stack trace overhead. - Utilizing Ruby's throw/catch for clean error handling without the performance penalties associated with exceptions. - **Return Values and Communication**: Options for return values from service objects include simple Booleans, structs, or custom classes. The choice of structure affects how the controller receives feedback about success or errors in processing. - **Organizing Code**: There is a flexible approach to organizing service object code, suggesting developers can group by domain rather than adhere to rigid directories. Throughout the discussion, the speaker uses code examples to illustrate the concepts, emphasizing the choice of the LightService library as a facilitator for employing functional patterns effectively. Throughout the talk, the primary takeaway is that service objects, while not mandatory, can significantly improve code organization and error handling in complex applications. The speaker encourages developers to experiment with different patterns to find what fits their needs best, supporting the overarching theme that there is no one-size-fits-all solution in programming. In conclusion, Riaz's insights prompt a deeper reconsideration of Rails best practices, advocating for the thoughtful incorporation of service objects to enhance maintainability and readability in Ruby on Rails applications.
Suggest modifications
Cancel