RailsConf 2023 - Rails as a piece of birthday cake by Vladimir Dementyev

Learn how to use abstractions effectively in your Rails applications. Explore the benefits and drawbacks of service objects, understand the principles of good abstraction, and discover how to choose the right third-party libraries for your project.

Key takeaways
  • Abstraction by definition is a kind of encapsulation. It carries many features. First of all, abstraction by definition is a kind of encapsulation that provides a common definition of service object. It could be everything from pure Ruby objects to interactors.
  • Service objects are not a good abstraction. They can introduce coupling and make testing more difficult.
  • A good abstraction should be easy to understand, use, and maintain. It should also be flexible enough to accommodate changes in the future.
  • When introducing a new abstraction, it is important to consider the following:
    • The purpose of the abstraction
    • The scope of the abstraction
    • The impact of the abstraction on the rest of the codebase
  • It is also important to remember that abstractions are not always necessary. Sometimes, it is better to just use a simple solution that is easy to understand and maintain.
  • When in doubt, it is always better to err on the side of simplicity. A complex abstraction that is difficult to understand and maintain is worse than no abstraction at all.
  • Rails provides a number of built-in abstractions that can be used to improve the maintainability and readability of your code. These abstractions include models, controllers, views, and helpers.
  • It is important to understand how these abstractions work together in order to use them effectively. By following the Rails conventions, you can create code that is easy to read, understand, and maintain.
  • In addition to the built-in abstractions, there are a number of third-party libraries that can be used to add additional functionality to your Rails applications. These libraries can help you with tasks such as authentication, authorization, and data validation.
  • When choosing a third-party library, it is important to consider the following:
    • The features of the library
    • The documentation of the library
    • The support for the library
  • It is also important to remember that third-party libraries can introduce dependencies into your codebase. These dependencies can make it more difficult to upgrade your application in the future.
  • **By following these tips, you can use abstractions effectively to improve the maintainability and readability of your Rails code.