Combining these two contents, we have:
Hatched by Jaeyeol Lee
Oct 07, 2023
4 min read
3 views
Combining these two contents, we have:
"Simple View Presenter Pattern in Rails without using Gems and Body doubling for ADHD: Definition, how it works, and more"
The default Rails way model-view-controller architecture often leads to a bloated model layer. It also helps to reduce the logic in the view layer and makes testing easier. If logic is complex, I usually prefer to implement a single "happy path" integration spec and test edge cases using low-level unit tests. Another downside of putting logic into views is that it's challenging to test it in isolation. But the inclusion of ActionView::Helpers::TextHelper in the model indicates that we're mixing up unrelated layers. From my experience refactoring legacy projects, putting logic into helpers can also lead to the terrible practice of including them in controllers to keep things DRY. Overusing gem dependencies is a simple way to unnecessarily bloat a Rails app memory usage. But, adding a gem is always a risky investment.
On the other hand, ADHD body doubling is a practice where a person with ADHD works on and completes potentially frustrating tasks with another person. The inattentive form affects concentration and makes a person vulnerable to distraction, while the hyperactive form makes sitting still difficult.
Now, you may wonder how these two seemingly unrelated topics can be connected. Well, let's dive into the concept of body doubling and see if we can find any similarities or insights that can be applied to the development process in Rails.
The idea behind body doubling is to provide external support and accountability to individuals with ADHD. By working alongside someone else, they are more likely to stay focused, complete tasks, and overcome challenges. Similarly, in Rails development, we can benefit from external support and accountability in the form of simple view presenter patterns.
Instead of relying heavily on gems and complex dependencies, we can implement a straightforward approach to separate concerns and reduce bloat in our codebase. By implementing the presenter pattern, we can extract logic from our views and models into dedicated presenter objects. These presenters act as intermediaries between the view and the model, providing a clean and organized way to handle complex logic and data manipulation.
Just like body doubling provides an external perspective and helps individuals with ADHD stay on track, the presenter pattern allows us to maintain a clear separation of concerns and keep our codebase focused and manageable. By delegating responsibilities to dedicated presenter objects, we can ensure that our views remain clean and free from unnecessary logic.
To implement the simple view presenter pattern in Rails without using gems, we can follow these actionable advice:
-
Identify the logic in your views and models that can be extracted into separate presenter objects. Look for complex calculations, data manipulation, or conditional rendering that can be delegated to a dedicated presenter.
-
Create plain old Ruby objects (POROs) for each presenter and define methods that encapsulate the specific logic for that view or model. This will help keep your codebase organized and modular.
-
Use the presenter objects in your views instead of directly accessing the model. This will allow you to test the presenter in isolation and keep your views clean and focused on presentation logic.
By following these steps, you can avoid unnecessary gem dependencies, reduce bloat in your codebase, and improve the testability and maintainability of your Rails application.
In conclusion, the simple view presenter pattern in Rails without using gems provides a clean and organized approach to handling complex logic and data manipulation. It allows us to separate concerns and keep our codebase focused and manageable. Similarly, body doubling in ADHD provides external support and accountability to individuals, helping them stay on track and complete tasks. By incorporating the principles of body doubling into our development process, we can improve our productivity, code quality, and overall success in building Rails applications.
Actionable advice:
- Identify the logic in your views and models that can be extracted into separate presenter objects.
- Create plain old Ruby objects (POROs) for each presenter and define methods that encapsulate the specific logic.
- Use the presenter objects in your views instead of directly accessing the model.
By following these steps, you can implement the simple view presenter pattern without relying on gems and improve the overall quality of your Rails application.
Sources
Hatch New Ideas with Glasp AI 🐣
Glasp AI allows you to hatch new ideas based on your curated content. Let's curate and create with Glasp AI :)
Start Hatching 🐣