Lurker News

Comments (438) 69 threads

Earlier comments
Locke5 replies#
Nostalgia warning: I also grew frustrated with Rails / ActiveRecord and jumped to Merb / DataMapper with excitement. Perhaps it will sound like a small thing, but I remember feeling especially frustrated that every ActiveRecord model became such via inheritance. This drove me crazy:

    class User < ActiveRecord::Base
Why should my `User` extend from `ActiveRecord::Base`? Is a User of my app also an ActiveRecord::Base? What is an ActiveRecord::Base anyway?

So, when DataMapper came along and favored composition over inheritance I was sold.
However, my experience with DataMapper was that it didn't have the stability of ActiveRecord, nor did it reach feature parity.
And, then Rails killed Merb. At the time I thought it was a tragedy. The competition Merb provided did improve Rails, it would have been nice if that competition had been longer term, though. On the flipside, I wonder if there would have been enough community to support two large Ruby web frameworks.
In the end I made peace with Rails and ActiveRecord (and, believe it or not, even ActiveSupport!). I don't have great love for Rails, but it is a powerful tool, so I accept it for what it is.
That said, I think the author's criticisms are well stated and hopefully there will be some influence on the future direction of Rails, etc, and the way devs approach Rails.

jsnk2 replies#
I don't get your complaint about "class User < ActiveRecord::Base".

If you don't want to use ActiveRecord::Base methods, why don't you just declare a class without it? You can just do "class User" you know.

Goopplesoft1 reply#
I don't ruby but I'm guessing OP prefers the "include" that DataMapper uses since inheritance 'feels' weird ... a weak point nevertheless.
solnic#
`include` is also inheritance, multiple inheritance. I try to avoid inheritance and prefer composition. It is very simple in ruby and very powerful.
Locke#
As a thought exercise, suppose I have my User class and now I would like to write it as json. Do you think it would be strange if the established solution were this?

    class User < JSON::Base
Where by extending JSON::Base, I now have access to helpful methods like to_json?

Instead we have JSON.dump(user). And, if I need to customize the way the User json is written, I can opt in by defining a method. Thanks to Ruby's open classes, I can make the definition of such methods optional, suppose a separate file includes something like:

    class User
      def as_json
      end
    end
Requiring this file will bring in the extra json behavior without littering my actual user.rb with the details of how a User is written to json. Whether this is worthwhile or a bad idea is debatable, but I like that it is possible.

Now imagine if persisting a model to the database were similarly flexible? What if we could do this?

    ActiveRecord.save(user)
Maybe it would be a good thing, maybe not.

As it is, I've come to accept the ActiveRecord approach, but when I create a model that extends ActiveRecord::Base, I think of it, not as a User, but an ActiveRecordPersistedUser. Where it makes sense, I separate my BusinessModel's from my ActiveRecordPersistedBusinessModel's for clarity.

bgentry1 reply#
Have you tried Sequel? Sequel has, for me, filled the void left by DataMapper. Most folks I know that have used both ActiveRecord and Sequel vastly prefer Sequel.

http://sequel.jeremyevans.net/

Siyo2 replies#
Something to consider for people interested in Sequel. Sequel is great and all, but it still follows the Active Record pattern (Sequel::Model), not Data Mapper. Also expect to run into some problems with gems that interact with ActiveModel (Devise, CarrierWave, etc.). It's all solvable of course but it might require some hacking. Most popular gems have sequel versions or ship with sequel support, but it's not as well tested and maintained, we had to contribute several patches. Also, if you plan on using Sequel with Rails, don't use any of it's plugins that make it behave closer to ActiveRecord. Stuff like nested_attributes, delay_add_association, association_proxies, instance_hooks. They seem really nice at first, but I guarantee they will cause all sorts of unpredictable problems down the road. I would recommend looking into something like Reform which decouples form logic from your models because working with complex forms is going to be harder without all of the AR magic.
andrei_says_1 reply#
Is there an authentication gem which works well with Sequel?

Continue this thread — 1 reply

Freaky1 reply#
Sequel::Model's quite optional - it doesn't force you to use the AR pattern. It's built on top of Sequel::Dataset, which is entirely usable all on its own.

ROM also uses it as its SQL backend: http://rom-rb.org/

Continue this thread — 1 reply

erikpukinskis#
It's kind of amazing that an open source project was able to aqui-hire another open source project. I'm not sure I've seen that before.

I guess if anything it speaks to the level of centralization in Merb development at that time?

barrkel2 replies#
Having used many different ORMs that let you think that your business models could just gain persistence with a little sprinking of automagic, I far prefer the non-object-orientation of ActiveRecord.

Databases aren't object-oriented. Thinking of them with an is-a, LSP etc. mindset is a recipe for pain down the road. Databases are containers for facts: a means of storing, finding, synthesizing and manipulating facts. Your User class isn't a user of your application; IMO it's wrong to think of it as an object, because it could just be a slice of the User's facts (e.g. a subset of the columns).
I'm not a big fan of object orientation any more, and I like my databases to be stores of facts. The data in the database is primary; code in the application is secondary. Persistence isn't something I add to my benighted objects to let them be reanimated by query; persistence is what lets me briefly get a handy representation of a tuple locally.
To my mind, ActiveRecord models are little more than hashes with a nicer syntax. I don't need them to be much more; I don't want them to be much more. You can try and add methods and make them smaller, but coordinating the manipulation of facts is problematic in a transactional world, and the responsibilities aren't clear either. Object orientation is predicated on the idea of message sends and hidden state; tables have explicit state and no behaviour. Not a good match.

pm24601#
Especially true if there are more than 2 codebases interacting with the same database table.
spacemanmatt#
Honestly, I feel like OO has been a net harm to the practice. It is a useful code reuse pattern but I feel like it has gotten far too much play.
sanderjd#
The inheritance approach, used in both ActiveRecord and ActionController is sort of like the original sin of Rails. It affects everything from semantics, to performance, to testability. It is often the reason things eventually seem hard, but also the reason many things initially seem easy.
jon-wood1 reply#
I'm somewhat split on the author's opinion here. I also picked up Rails back in the day (I think the first version I installed was 0.8), and I have a bit of a love/hate relationship with it.

As a framework for building comventional HTML templated database backed websites I still think it's near unbeatable, especially with the addition of a few common gems. However it so often gets shoehorned into other places - API backends, rich client apps, and massive systems. Places where the Rails conventions rapidly go from everything falling into place to getting in the way and needing to be worked around, or heavily tuned.
I completely agree that ActiveRecord is the core of why big Rails applications are complex to work with and often exhibit disproportionally poor performance. It doesn't lend itself well to composition, and results in data persistence being intertwined with business logic. That's fine for early prototypes, and in all honesty will get you to market quickly, but it makes extracting the concepts you discover during development into a coherant API much more complex than I'd like.
These days I still use Rails for the aforementioned HTML generating web applications, but it's often acting as an API client to systems built on top of a Grape based backend, with an API built around service objects and a simple data access later.

keithwhor1 reply#
Interesting you bring up the point about API backends. I'm the author of Nodal [1], with the goal of bringing the best design patterns and practices from Rails and Django to the world of Node, focused completely on building a decoupled API layer. There is no view / template logic at all.

The project is very lightweight right now (benefits of being a young project with a sole full-time contributor), but I'd be interested to hear your feedback as to what you think is or isn't necessary for continued development. :)
[1] http://github.com/keithwhor/nodal

jon-wood1 reply#
Interesting, I think I came across Nodal while evaluating options for a side project a while back. Having just taken another look the big thing that seemed to be missing was something to serialize objects to JSON, although that may be because serializing objects is so trivial on JavaScript anyway. There also didn't seem to be much documentation about the operational side of things, most glaring was nothing being said about how the scheduler actually schedules jobs and ensures they get run.
keithwhor2 replies#
Scheduler is actually still a WIP. I've changed the core around significantly in the last few releases, which has changed how the scheduler operates. That's why there's not much around it. ;)

We serialize models to JSON automatically in the response layer, and all models have a `.toObject()` method that takes an optional interface (which keys to actually serialize).
There is full API documentation but I still have a lot of work to do creating more fleshed-out tutorials. :)

Continue this thread — 2 replies

Doctor_Fegg3 replies#
I read this with a lot of head-nodding but also a great sense of sadness.

I agree with pretty much every brickbat hurled at Rails in this article, except for one thing:
> Both projects were ultimately killed by Rails as Merb was “merged” into Rails, what turned out to be a major Rails refactor for its 3.0 version. DataMapper lost its community attention and without much support, it never evolved as it could if Merb was not “merged” into Rails.
DataMapper wasn't killed by Rails absorbing Merb. DataMapper was killed by "Things You Should Never Do, Part I":
> "They did it by making the single worst strategic mistake that any software company can make: They decided to rewrite the code from scratch."
(http://www.joelonsoftware.com/articles/fog0000000069.html)
DataMapper 2 was insanely ambitious, and true enough, it was never finished. A core subset was salvaged as ROM (Ruby Object Mapper), which has a certain artisan purity but is a long way from hitting the readable/understandable sweet spot that DataMapper originally had. But DataMapper 1 was abandoned by its developers. Pull requests languished and there weren't even any maintenance releases. I idled in the DataMapper IRC channel for a while and pretty much every query was answered with "don't bother, wait for DM 2". Unsurprisingly, people switched to ActiveRecord instead.
I still use DataMapper. I use it in my own framework, which is plaintively simple compared to Rails and no doubt makes a load of mistakes, but they're the mistakes I've chosen to make (which, as per DHH, is "opinionated" software). I would love DataMapper to be, if not revived, at least slightly maintained. There is life outside Rails, but you have to want it.

twic1 reply#
It astounds me that people are still citing that Spolsky article when its central example of what not to do is the writing of Firefox, which turned out to be a huge success.

Not that rewriting from scratch is always a good move. Evidently, DataMapper proves that!

WillPostForFood#
The Spolsky article is about Netscape 6. That rewrite took 3 years, during which time (1997-2000) they lost ~80% of their users to competing browsers? It may have been amazing software, but not a success. Firefox/Netscape 8 was 2005ish.
solnic1 reply#
I dare to disagree. My point about DM being killed by Merb/Rails merge was about what happened back in 2008 with its consequences through all the years. I'm talking about DM1 specifically, if Merb survived and DM could grow with it we would be in a different place now already.

As far as our DM2 efforts go, this really didn't end so bad. rom-rb is growing very fast and we're already in the process of making it easy to use for typical CRUD stuff. Hanami integration will help here a lot too.

Doctor_Fegg#
Thanks: Hanami looks really promising, and could well provide the human-friendly syntax that ROM lacks.
ssmoot2 replies#
You nailed it. HABTM just never worked, and there was little interest in making it work. Since I handed out commit-access like candy, the majority of contributions were to endlessly refactor. Or do things like letting you treat a CSV file as a database. And HABTM still didn't work.

I didn't know how to put the genie back in the bottle. I didn't have the same problems that prompted me to create DM in the first place anymore (and by that point, I wasn't sure that porting a large Java Pattern to Ruby was even a good idea considering what I'd learned in the process about method dispatch performance in Ruby) and I was burned out on maintenance. So I handed over the keys and the rest is history.
I messed up. :-)
Today I'm happily writing apps with akka-http and think O/R Mappers are a fundamentally flawed idea. It's like trying to build a truck to move a few yards of dirt 100 feet. It'll never pay off. And I think even "users" would probably find that the hours they put into learning and using the tool will never get ahead of the performance, simplicity and linear scaling of effort they'd have had with a simpler solution.
So these days I'm much more likely to write this in Scala:

  val limit = 10.0

  sql"SELECT name FROM coffees WHERE price < $limit".as[String]
Than anything else. You will never find an O/RM that's faster, simpler or easier to write and maintain than that.

Plus Contextual Validations in the O/RM is just a bad idea. Even if they do appear in the PoEAA. First-class-Form objects and deserialization/validation at the app boundaries may not be a new idea, but it's the right one. (IMO)

solnic1 reply#
Hey Sam, great to see you commenting on this :) I started contributing to DM when Dan was already in charge but I was a DM user when you were still working on it.

Anyhow, you made really good points here. I've worked on ORMs for a couple of years before I concluded the same - NOT WORTH THE EFFORT.
My approach with rom-rb is functional, as in this project works more like persistence libs in functional languages, rather than an O/R mapper. I removed the whole idea of mutable objects and managing their state using UoW etc. This simplified the stack a lot, and despite a complete lack of any performance-related tweaks rom-rb is already faster than ActiveRecord.
I also agree with your opinion re validations. I removed this concept from rom-rb as well and built a standalone validation library instead. This works very well.
Cheers!

ssmoot#
I think I'd blocked out the pain of dealing with mutable strings. :-)

We were a pretty enthusiastic bunch back in the day. Glad to hear you're still pushing things forward.

vinceguidry#
That sounds like the pain I went through when I tried to write my own ORM. You want to go nuts with refactoring, chasing an ideal design that just doesn't exist.

> So these days I'm much more likely to write this in Scala:
I do this sort of thing a lot in ActiveRecord. I'll write a class method with ".where('price is null or price < ?', argument)". I use ActiveRecord a lot like I use Sequel, drilling into the underlying database layer. It occasionally bites me, but when it does, it's a good reminder to simplify my database architecture while nothing else is relying on it.
This way I can get the benefits of an object that behaves the way I want it to behave, but also respects the data layer. I don't want to give up either.
I do feel like Rails, in an effort to make things easy, encourages devs to overcomplicate their apps.

brightball1 reply#
The thing that has blown my mind about Elixir and Phoenix is how it gets everything right. It's the clear migration path from Rails.
pmontra1 reply#
Phoenix is very Rails like in the way it makes developers work and very un-Erlang. I mean: Phoenix apps are monoliths and not loose collectives of processes with an explicit http process.

Check "Phoenix is not Your Application" at http://www.elixirconf.eu/
It starts with the right claim but it ends with workers inside Phoenix. Instead the router and the http server should be at the same level of the other workers. Actually, they shoul be much less important, an implementation detail.

chrismccord2 replies#
A new phoenix application is not a monolith. The `phoenix.new` generator generates a regular Elixir application for you that sets up a default Endpoint worker in your supervision tree, as well as a web directory to put phoenix related files (routers, controllers, etc). wrt to collective process, we add `worker(MyApp.Endpoint, [])` into your supervision tree, so we do exactly what you are wanting. Building a Phoenix application is building an Elixir application, not the other way around. Your phoenix dependency and related workers are just one component to your larger Elixir/OTP infrastructure. Note: Lance Halvorsen, who gave the "Phoenix is not your App" talk, is on the Phoenix core team. We have been pushing these ideas since the beginning and as Lance I and laid out in our ElixirConfEU talks, we're taking a stronger stance on isolation with upcoming changes to guides and phoenix resource generators.
askyourmother3 replies#
I said this before: phoenix is the new Rails, and that is not a good thing. Phoenix will end up bogged down with the same great "ideas", hex will end up chock full of crap like gems. Elixir ok, phoenix not so much.

Continue this thread — 3 replies

pmontra2 replies#
Understood but to make me clear: I'd like to see Phoenix as part of an umbrella application and not it starting other applications as its workers. It should be a peer among peers and not the boss. However, as Rails demonstrated, the current approach is very convenient so I can hardly criticize it too much at this stage of Phoenix adoption. I think it helps the onboarding to the platform.

Continue this thread — 2 replies

Load more comments