acts_as_what?

by aaron

This guy’s expression pretty much sums up my reaction whenever a new acts_as_* shows up in my RSS feed for AgileWebDevelopment plugins. As of today, there are 1,115 plugins listed there, 129 of which start with acts_as. That’s about 11.5% and I’m not even including ones like acts_as_hasselholf or acts_as_rickroll ;)

acts_as_chuck_norris is impossible – the only thing that can act like Chuck Norris is Chuck Norris

acts_as_* has sort of become the joke of the Rails community. Everything is acts_as whether it makes sense or not. Something simple like auto_validations becomes acts_as_auto_validated. And, in all honesty, I was sucked right into it like everyone else until I realized how ridiculous it had become. The majority of these plugins have names that are just terrible at describing what it is they do.

chuck_norris_fu consists of one move: the roundhouse kick

*_fu isn’t exactly much better. It seemed like once people started realizing that acts_as_* was becoming old, worn, and so last year, they resorted to suffixing every plugin with _fu. So instead of calling it auto_validations, it would be called validation_fu. The names changed, but the problems remained the same.

Where’s my acts_as_soviet_russia plugin?

Coming up with a name isn’t easy and isn’t always going to be witty and unique. Try to create something that’s, first and foremost, descriptive of what it is that your plugin provides… or you can just get lost in the acts_as_shuffle :-p Either way, I can at least say I warned you!

Disclaimer: I know I have a plugin that starts with acts_as… but I swear it actually makes sense in its context! :D

Comments

15 Responses to “acts_as_what?”

  1. ruby licious on July 6th, 2008 9:25 am

    Some good points there :) .. made me think of my acts_as_mysqlsearchable-plugin naming.

  2. Clemens Kofler on July 6th, 2008 1:32 pm

    As you say, acts_as_* is very 2006/2007. 2007/2008 was the year of *_fu. From now an, I guess the trend will be can_has_*! ;-)
    Oh and by the way: CakePHP uses actsAs for adding any extra functionality to models. In my only CakePHP project, I had to calculate a person’s age – this quicky became var $actsAs = array(“humanBeing”). ;-)

  3. Wynn Netherland on July 10th, 2008 3:09 pm

    Very funny! Having pub’d acts_as_redeemable to agilewebdevelopment.com just last night, I can’t help but wonder if I pushed you over the edge.

    I’m with you on *_fu, and I’ve heard the derision aimed at the acts_as_ plugins, but I think most model-related plugins make perfect sense to name acts_as_. I think it goes to consistency. When I see that prefix in a model, I know where to go looking to find the implementation.

  4. Zack on July 10th, 2008 6:14 pm

    I’ve been working on a plugin called acts_as_active_action, but I haven’t decided what it will do yet.

  5. ActsAsFlinn on July 10th, 2008 9:07 pm

    Don’t forget about http://actsasflinn.com ;-)

    @Clemens – yeah 2006/2007 for acts_as is right on, I registered my domain Jan of 07. If I reg’d it Jan of 08 I might have called it flinn_fu.com instead.

  6. adam french on July 10th, 2008 10:57 pm

    I don’t entirely understand why rails needs it’s own plugin management system….why not just release a gem?

  7. aaron on July 10th, 2008 11:14 pm

    @Clemens – Unfortunately CakePHP made the mistake of re-using a bad “convention” :(

    @Wynn – I definitely agree that there are acts_as_* plugins that make sense at times .. but more than 1/2 the time I think it’s a stretch. It’s sort of become convention to use that prefix for plugins focused on model extensions, but does that indicate a failure in us being able to properly categorize plugins? You don’t tend to see that with something like WordPress plugins.

    @Zack – I was surprised to see that someone had actually already created acts_as_fu :)

    @adam – I am in complete agreement with you and my thoughts on that matter can span several blog posts. I get a lot of people asking me the exact same question. I feel it was a complete mistake to invent something called a “plugin” that didn’t just mean gems meant for extending Rails. As far as I’m concerned, I release them both as a “plugin” and a gem, so people can use it in any way they like.

  8. Thom on July 11th, 2008 8:48 am

    I’ve started migrating to a new naming convention which I think is much more readable. :)

  9. Darcy Laycock on July 12th, 2008 4:21 am

    I’m also guilty of having migrated to the can has over the last half year or so.

    long live can_has_*

  10. Adam on July 12th, 2008 2:10 pm

    Let me suggest that these prefixes and suffixes can be useful but, like rope, they can be used to hurt yourself or others (http://www.instructables.com/id/Rope-Weapons/). I think that they have a role to play in communicating what one of these class level methods does. These tags (for lack of a better term) can be shorthand for intention revealing names.

    The trick is to agree upon what the tags mean. If we come to that agreement, then we can merrily go on our way renaming things where necessary. I think that there are 4 mutually independent tags for us to consider, all of which you’ve seen:

    acts_as_* — I think that the best examples of this are acts_as_tree and acts_as_named_set, at least for establishing the meaning of the tag. I would suggest that the * in acts_as_* describes the models as a collection. That is when I say:

    class Page < ActiveRecord::Base
    acts_as_tree
    end

    I can say that a collection of Pages is a tree and each Page is a node in that tree. I if I wanted to be pedantic about it (and Rails is opinionated, so why not) I could go further and require that acts_as_* applies to collection of ALL pages (that is there my be only one root node) and that if want all the pages to form a number of trees, I need to use acts_as_trees or acts_as_forrest.

    So that’s my test: if I can say that the collection of all my models is a Foo then acts_as_foo is the correct name.

    By this standard, the geokit acts_as_mappable is wrongly named; the collection of all my mappable models is not “a Mappable”

    *_fu — First of all, the actual tag name, might be better if it was something other than _fu, but I like the whimsy and I’m bad at picking helpful names. I’m not sure that this definition is in current use but the heading “chuck_norris_fu consists of one move: the roundhouse kick” illustrates how I would use it. Associating something’s _fu with a model is to impart that things properties upon the model. So (continuing with the whimsy) if I have

    class TexasRanger < ActiveRecord:Base
    chuck_norris_fu
    end

    Then each ranger (as an individual) is capable of delivering a Chuck Norris roundhouse. Note that they are not Chuck Norris, rather they are are merely channeling Chuck Norris. As a result if two of them fought and used the roundhouse kick at the same time, it would merely result in the immediate conversion of all matter within an infinite radius into energy (Chuck Norris fighting himself would actually cause the universe itself to cease to exist).

    With this description, GeoKit would have geolocation_fu.

    *_jitsu — Is like _fu but it applies at the class level just like acts_as_*. I’m having a harder time with examples but I think I have one. In Radiant, there is a class Radiant::Config < ActiveRecord:Base. Since config values are just name/value pairs it allows you to do things like puts Radiant::Config["my_key"] and Radiant::Config["my_key"] = “some new value”. I might decide that this would be a generally useful thing to do so I’m going to create a plugin to do this. I would call it something like configuration_jitsu.

    has_* — I don’t get the can_ part of can_has_*, would you also have must_has_*)? This is trivial. If there is something special about how a particular association works then it gets a unique has_* method. For example, attachment_fu works with my scheme above so you might create has_attachment to handle that particular polymorphic situation easily.

    I think these are reasonable “rules” for naming. Many things don’t fit into the scheme (like auto_validation) but that’s ok

  11. aaron on July 12th, 2008 10:47 pm

    @Thorn – That’s genius :) I think you’re onto something there. We have a lot to learn from next generation languages like LOLCode. Can I get an attachment_kthxbye?

    @Adam – That was both a hilarious and insightful comment (could be an article in of itself!). Where are my slashdot moderation points when I need them? I think you hit the naming scheme spot on… I couldn’t have said it better myself!

    I’ll be honest, I’m a little afraid of chuck_norris_fu right about now. I have to wonder though… chuck_norris_fu still seems impossible. The only thing powerful enough to describe Chuck Norris is the voice of Chuck Norris. Surely Ruby would fall to its knees, begging for mercy, if it ever attempted to describe that which is Chuck Norris.

    Unrelated to Chuck Norris, I think what finally made me go psycho were things like acts_as_commentable, acts_as_rateable, acts_as_emailable, etc… the list goes on and only seemed to get worse. It’s at that point I started migrating toward a has_* or just * naming scheme. For example, I moved to has_comments, has_ratings, has_emails, which actually matches the definition exactly as you provide. Instead of acts_as_state_machine, I have just state_machine.

    Someone should definitely create a plugin name generator script that’ll figure out what prefix/suffix to use based on a couple of input parameters :) That would be amazing. Any takers?

    I still don’t think I’m a fan of *_fu or *_jitsu, though. Why is it called attachment_fu and not just has_attachment? That’s probably a bad example of using the _fu suffix, but it feels like a stretch.

  12. Alex Gregianin on July 15th, 2008 9:43 pm

    it has become a joke so funny that people even created the “acts_as_dot_net”!

  13. Adam Salter on July 25th, 2008 8:36 pm

    As pointed out above, the ‘acts_as’ does actually have a purpose… it’s used for plugins that act on models, not other types of plugins…
    11% could be about right for plugins that act on models…

  14. aaron on July 25th, 2008 8:43 pm

    @Adam – I am in complete agreement that it has a purpose :) My point was directed more at plugins that force their name to follow the acts_as_* convention, which accounts for at least half of those listed in the AgileWebDevelopment repository.

  15. Bart on July 31st, 2008 10:02 am

    Hahaha, great post.
    I needed to write a statistics plugin. acts_as_statisticable? Nah, makes my fingers cry. statistics_fu? Nope.

    can_has_stats ftw!