Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I am constantly guarding against AR callbacks as well as the insane number of queries that come from lazy loading relationships.

Might have to explore your suggestions a bit.



Good idea. The lazy loading has been particularly bad in the code-base I worked on recently, to the point that pieces of code thought to be entirely isolated from the database were actually accessing the entirety of it.

Callbacks to me are just an indicator of what is missing, an object that encapsulates the "user case". There is a need to do "other things once the data is written", but that is specific to the location where the writing is happening. Modifying a post content from an administrator's perspective could trigger an email to inform the user "your post has been moderated", but the user modifying it's own post shouldn't. Yes you can have callbacks with IFs, but the use-cases will keep piling up. Now you have a rake task that fixes some posts' content due to a bug in the whatever part of the code parsed the text. It shouldnt' trigger the email, but you do have a callback in there.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: