Service Objects as Functions: A functional approach to build business flows in Ruby on Rails

I wrote this article last year and want to see what you guys think? I have not received much feedback when sharing on LinkedIn.
Original idea was to have a 3-4 post series, but I am not sure is it worth it and if its something people are interested to read about.
16
Upvotes
18
u/art-solopov Oct 12 '24
My feedback about the idea.
module_function).9
u/joelparkerhenderson Oct 12 '24 edited Oct 12 '24
You're asking for feedback. In my opinion, your ideas are good. I use Ruby service objects and I like functional programming styles.
In my opinion, your specific choices of nouns and verbs are difficult for U.S. English, and may interfering with your readers learning from you.
As some specific examples... "Employee" is generally singular yet "EmployeePayroll" would typically mean a payroll for all the employees. "Taxes" seems to be both singular and plural. "LineItem" is vague. Your functional-application naming has contradictory ways such as a prefix (e.g. "CalculatedLineItem") versus a suffix (e.g. "LineItemWithPolicy").
I believe you have an opportunity to make your points more clear by changing from "Employee" and "Payroll" to anything else such as a shopping metaphor with "Item" and "Cart", or an event metaphor with "Movie" and "TIcket", etc. Avoid "LineItem" or similar vague terms. Decide if you want functional-application naming conventions to use a prefix or a suffix, then be consistent about it.
I hope this may be helpful-- your article is making good points, and yes please keep writing more.
4
u/kallebo1337 Oct 12 '24
are you the guy who had his rejection due to over engineering?
We know why :(
3
u/[deleted] Oct 13 '24
It’s nice but you could change API around and make it more cleaner by using objects properly while still benefiting from FP approach. FP is less about using functions per se, but more about referential transparency and composition. You can do those things while still benefiting from Ruby way.
Clean “service objects” are the way, but your particular implementation needs more polishing. Or maybe example is just bad in this case.
Take a look at Trailblazer and dry-rb to see what I mean
2
u/kahns Oct 12 '24
Sorry guys, looks like I dont know how to handle reddit posts.
https://medium.com/@beard-programmer/service-objects-as-functions-a-functional-approach-to-build-business-flows-in-ruby-on-rails-bf34bf18331d
3
u/Kinny93 Oct 12 '24
Without even diving into specifics, it’s just more complicated & harder to follow.