News for hackers. Stuff that matters.
Re:Rails has won: The Elephant in the Room by bascule on Tuesday May 24, 2016 @01:36AM (#11759186)
I've been using Rails for a decade now, across many jobs, and one thing I've experienced fairly consistently is the worst Ruby web apps I have ever dealt with are the ones that weren't written in Rails.

I've both seen and spent a lot of time rewriting overgrown Sinatra monstrosities with assorted non-AR ORMs. These apps were generally riddled with XSS since they didn't handle escaping correctly, often had unmaintainable code that sometimes was thousands of lines long crammed into a single file, and lacking any sort of basic structuring principles mixed parameter handling with business logic all over the place.

I've seen several attempts to "build a better Rails" that's "more OO", but even frameworks that solve the problems I've just described in the previous paragraph have one huge drawback: Rails is a lingua franca for web development in Ruby, and whatever incremental gains you get from having a better framework are heavily outweighed by the costs of making people learn a new framework-per-project, the lack of features and documentation, and the lack of the library ecosystem that surrounds Rails.

At points I've tried to keep three ORMs/DB libraries in my head at a time: AR, DataMapper, and Sequel, which just left me wishing I was dealing with AR (the devil you know...)

ORMs need massive feature sets to jam the proverbial square peg of relational databases through the round hole of objects, and AR is the only one I've used that's both expressive enough to cover all the cases I'm interested in and mature enough to even have a story around database concurrency, even if most Rails developers are getting database concurrency wrong with AR (e.g. http://www.bailis.org/papers/feral-sigmod2015.pdf ) At least AR has any story around things like optimistic and pessimistic locking and lets you build apps where you can read an object and persist your changes without silently clobbering another requests's database writes with your locally cached copy of stale data.

tl;dr: if you want to do web development but dislike Rails, your best bet is probably to switch to a different programming language than Ruby.

Re:Rails has won: The Elephant in the Room by Freaky on Tuesday May 24, 2016 @10:51AM (#11762051)
> At points I've tried to keep three ORMs/DB libraries in my head at a time: AR, DataMapper, and Sequel ... At least AR has any story around things like optimistic and pessimistic locking

That's rather dating your "at points". DataMapper hasn't seen an update since 2011, and Sequel's shipped with optimistic and pessimistic locking since early 2010.

Re:Rails has won: The Elephant in the Room by justinwr on Tuesday May 24, 2016 @12:28PM (#11762908)
"tl;dr: if you want to do web development but dislike Rails, your best bet is probably to switch to a different programming language than Ruby."

But... wasn't this the underlying point of Solnic's opinion piece?

Due to Rails "well deserved" domination in the web framework space, POROs never had a chance of contributing to friendly and just competition across the Ruby community. We simply ended up with shitty alternatives because no one was given the proper chance to be BETTER Rubyists.

They just kept eating the gluten and feeling the allergy pains, so to speak.

Ah well...

EDIT: shrug quoting...

Re:Rails has won: The Elephant in the Room by eropple on Tuesday May 24, 2016 @01:54AM (#11759238)
> AR is the only one I've used that's both expressive enough to cover all the cases I'm interested in

Have you never worked on a system big enough to need a service layer?

Re:Rails has won: The Elephant in the Room by bascule on Tuesday May 24, 2016 @02:05AM (#11759277)
I've been using service objects / operations in my apps pretty consistently for half a decade, but that's a red herring. That statement is about using AR to query and manipulate data, which is orthogonal to a service layer. Service objects aren't going to fix the lack of optimistic/pessimistic locking in DataMapper.
Re:Rails has won: The Elephant in the Room by eropple on Tuesday May 24, 2016 @08:58AM (#11761150)
I don't know what you mean by "service objects", but my point is that ActiveRecord requires you to have a line to the database in order to actually populate a database. This is really shit for a SOA; you should not require a connection to the user database to be able to make heads or tails of an object from your authn/authz service. It is so completely unacceptable that I consider it completely disqualifying (to say nothing of AR's other problems; if I had to use an ORM, which I don't because DALs are fairly trivial in Ruby, I would use Sequel).

This is why I use Virtus and ROM.

Re:Rails has won: The Elephant in the Room by bascule on Tuesday May 24, 2016 @10:24AM (#11761737)
Oh, so you're talking about SOA / "microservices" and Claims-Based Identity (or rather, Claims-Based Identity is what you should be using). Well, an ORM is totally the wrong way to go about expressing user identities in a distributed system.

As it were I wrote the AuthN/AuthZ library Square uses to solve this problem:

https://github.com/square/rails-auth

The objects we build for representing user identities are POROs. No need for every app to have a database connection to a shared user service, or to go through an ORM.

I'm somewhat confused what alternative you're even proposing here: are you doing something weird like Marshalling ORM objects between services?

Re:Rails has won: The Elephant in the Room by eropple on Tuesday May 24, 2016 @11:06AM (#11762180)
You're right in that claims-based identity is the better approach; users was not the best example, but I wrote that post more hastily than I should have. =) But any distributed service with single-source-of-truth ownership of a domain object is going to be totally hosed by ActiveRecord; to handle it without every service having a database connection to every other service's datastore you end up with something like a conversion step from Magic Model Object to a PORO, and that sucks wind.

(In my own case, I have a service architecture because I literally have to; I need to run services in multiple AWS regions. It would be nice to be able to not care and fart everything into a single monolithic application, but them's the breaks. I tend to think that almost every sufficiently complex or sufficiently scaled application ends up in this state, too.)

With Virtus/rom-model (or I guess the newer dry-types, though I haven't used it), I don't, because my--versioned, because my APIs already require compatibility--model objects are aware of their own contents, and I can trivially marshal objects over the wire. (I also don't have to go look at the database schema to know what my object is. Big plus.)

Re:Rails has won: The Elephant in the Room by bascule on Tuesday May 24, 2016 @11:34AM (#11762392)
to handle it without every service having a database connection to every other service's datastore you end up with something like a conversion step from Magic Model Object to a PORO, and that sucks wind.

I actually prefer the distinction: serialized domain objects do not have access to the full richness of the ORM API, so having a separate class representing the specific behavior of an API-wrapper makes a lot more sense to me.

Something like ActiveModel::Serializers wraps up a lot of the boilerplate while also letting you retrieve nested object graphs in a single request:

https://github.com/rails-api/active_model_serializers

That said at Square we generally use protobuf-based RPC for our service-to-service requests, because we have a polyglot SOA so it's important for our services to produce and consume protos to support more languages than just Ruby.

Re:Rails has won: The Elephant in the Room by xtian on Tuesday May 24, 2016 @10:31AM (#11761825)
For the vast majority of apps, SOA is detrimental to productivity and maintainability. For some cases it is the right choice but I don't think anyone is arguing that these are the cases for which AR was designed.

Can't you recognize the usefulness of a hammer even if you need a screwdriver for your task?

Re:Rails has won: The Elephant in the Room by eropple on Tuesday May 24, 2016 @11:10AM (#11762204)
When that hammer inevitably is used on screw-related tasks, I get a bit touchy. ActiveRecord in particular is one of the bigger offenders (well, Rails full-stop is one), being applied in all sorts of ways that somebody (hi) ends up having to fix, which is why I mention it.

I don't agree with regards to SOAs and either productivity or maintainability, but I also tend to work on systems that have concrete needs for scale and I also divorce it from the microservice craze (which I regard as a rather pathological case). But that's kind of off-topic.

Re:Rails has won: The Elephant in the Room by aantix on Tuesday May 24, 2016 @01:27PM (#11763544)
Any specific code examples you'd like to share where you thought ActiveRecord was inferior to the alternative you provided?
Re:Rails has won: The Elephant in the Room by eropple on Tuesday May 24, 2016 @05:31PM (#11765662)
Plenty I'd like to, but I don't see any for which I have clear copyrights to share.
Re:Rails has won: The Elephant in the Room by neon_electro on Tuesday May 24, 2016 @10:17AM (#11761672)
Could you point to any resources for someone who has been learning stock Rails/ActiveRecord to learn more about the approach you prefer?
Re:Rails has won: The Elephant in the Room by busterarm on Tuesday May 24, 2016 @03:31AM (#11759594)
I used Sequel once on a major project and as nice as it was, there was major pain. Pain I wouldn't have had with ActiveRecord.

I seriously would have gotten the job done in half the time, with less problems had I just used Rails...and I've written my own ORMs before - I have somewhat of a clue.

Re:Rails has won: The Elephant in the Room by bdcravens on Tuesday May 24, 2016 @04:03AM (#11759704)
I'm having the opposite experience, but I think that's because I'm working on a legacy database that really doesn't follow conventions. Even when overriding defaults in AR, I still found myself trying to hammer what I was doing into a AR-shaped block, whereas Sequel feels like it lets me craft a resultset as I desire regardless of what I'm starting with. But like I said, it's a legacy database and it was originally driving an app where writing raw SQL was the SOP, some of which really leans of higher-level SQL engine features for function and performance.
Re:Rails has won: The Elephant in the Room by vidarh on Tuesday May 24, 2016 @04:45AM (#11759854)
I'm curious what pain you experienced with Sequel, as I have the exact opposite experience.
Re:Rails has won: The Elephant in the Room by forkerenok on Tuesday May 24, 2016 @05:13AM (#11759969)
Your nickname rings the bell. Aren't you https://github.com/tarcieri ?

If so the "tl; dr:" sounds strange considering your celluloid-based eco-system.

Edit: which I consider, at least to date, a bit orthogonal to the Rails ways.