Live data from Hacker News

Things that Ruby on Rails people tell you

jameschambers.com

61–70 of 73 posts

Re: Things that Ruby on Rails people tell you

#61
post #57
post #55

Earlier quoted context omitted.

> Fowler's "Enterprise Application Architecture", and it seems most of the people _using_ AR never read it I wasn't aware Fowler is a required reading for anything(or I would say even beneficial) for _anything_, let alone AR. > I particularly dislike the way it tends to result in code that is littered with leaky database abstractions where schema details tends to find its way into peoples controllers and views Your w…

> I wasn't aware Fowler is a required reading for anything(or I would say even beneficial) for _anything_, let alone AR. Then I suggestion you read Enterprise Application Architecture. It's a great book for the way it formalises a number of very common patterns in a very concise way. It is also directly or indirectly the inspiration for a large number of recent ORM's and worth reading for that reason alone. Active Re…

> Unfortunately most picked off the easiest ORM pattern presented and stopped there, without alerting their users to all the caveats of the pattern.

I have a general dislike for Fowler church of patterns. That is not to say I haven't gone through what is listed on his site. I didn't find it intriguing enough. I derive 100 times more value reading K&R than GoF. There is limited time and large number of books - one has to be picky.

> No, I am suggesting that, e.g. Person.where("some random SQL") is horrible.

Person.where("last_name = ?", last_name) is the most concise way to issue that query. Abstracting last_name so that if the field name changes, the query still is relevant is overkill. If you are so insistent, it isn't really hard to do a base model class which inherits from ActiveRecord::Base and do the mapper yourself.

> exceedingly poor solution for anything but tiny projects

github, twitter, heroku et al would like to disagree. Person.where("last_name = ?", last_name) makes it unsuitable for large projects? Personally, I have seen 1% cases where a migration changes column names, and when it does, re-factoring the code base for column name changes will take less than 2 minutes.

> A large chunk of developers are terribly excited about AR because it's better than what they're used to, and settle for it because it's part of Rails instead of looking for alternatives.

I don't understand. You are quoting it as if AR is the new kid on the block. It has been long enough to call it time tested. If Person.where("last_name = ?", last_name) is not abstract enough and makes it unsuitable for your projects(still the only concrete complaint from you), look for alternatives. I am not a fan of InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonPainter and I would stick with Person.where("last_name = ?", last_name) and will fork AR if someone has a bright idea of adding layers of abstractions over a simple query.

Re: Things that Ruby on Rails people tell you

#62
post #58

Earlier quoted context omitted.

ERB ( one of a ton of view engines you plug into rails): Or: I don't even like Rails, but I fail to see how that is "really smelly". Or as I prefer Mustache, I'd probably rather pass Model.friends to the view as a variable and do: {{#friends}} {{name}} {{/friends}} But regardless what engine you do, you'd be hard pressed to find any big differences in terms of iterating over a collection. I find it very hard to belie…

You don't see how uncomfortable for the hands it is to type ` ` every single time you want to output something using code? How can you compare that, to a simple `@` symbol? ERB (or even Mustache for that matter, feel like a relic compares to Razor.

> You don't see how uncomfortable for the hands it is to type `` every single time you want to output something using code? How can you compare that, to a simple `@` symbol? ERB (or even Mustache for that matter, feel like a relic compares to Razor.

I don't think you are doing an objective evaluation.

1. All goddamn editors can be configured to do a short key for the expression(I have mapped \1 to `` and \2 to ``)

2. If that is too much of work, use Haml http://haml.info/tutorial.html or Slim http://slim-lang.com/

    # slim
    - persons.each do |person|
      p = person


   # haml
   - persons.each do |person|
     %p = person

Re: Things that Ruby on Rails people tell you

#63
post #59
post #54

Earlier quoted context omitted.

What else would you compare VS with then?

A solid Unix/Linux command line. I've yet to see an IDE that can beat the productivity of that, or even get close.

Take a Java or C# project and tell me what you can do with the CLI. Auto completion? Re-factoring(grep and replace doesn't cut it)? Code generation? I said Java and C#, because I don't know which IDE people use for dynamic languages, and if it is possible to offer accurate completion without executing the code(in some cases, it won't work even with code execution but there was an article from the VS python guys(I think) about offering completion without executing code) and reliable re-factoring(this isn't doable at all without confirming with the user).

Re: Things that Ruby on Rails people tell you

#64
post #54

Earlier quoted context omitted.

Running circles around Eclipse and Netbeans is not tricky really, they're both horrifying to use on a regular basis.

What else would you compare VS with then?

Unfortunately VS does so many things that Netbeans and Eclipse are it's only real rivals, but in terms of being an excellent IDE Qt Creator is fantastic to use, but it's very driven to just be excellent as a C++/Qt IDE.

Re: Things that Ruby on Rails people tell you

#65
post #62

Earlier quoted context omitted.

You don't see how uncomfortable for the hands it is to type ` ` every single time you want to output something using code? How can you compare that, to a simple `@` symbol? ERB (or even Mustache for that matter, feel like a relic compares to Razor.

> You don't see how uncomfortable for the hands it is to type ` ` every single time you want to output something using code? How can you compare that, to a simple `@` symbol? ERB (or even Mustache for that matter, feel like a relic compares to Razor. I don't think you are doing an objective evaluation. 1. All goddamn editors can be configured to do a short key for the expression(I have mapped \1 to ` ` and \2 to ` `)…

You're comparing something that comes out of the box (Razor) with something you can achieve comfort with after wiring up hotkeys and snippets. That's not a fair, clinical comparison.

Are you kidding me?

Slim looks like something much MUCH better than the crufty old ERB.

Re: Things that Ruby on Rails people tell you

#66
post #63
post #59

Earlier quoted context omitted.

A solid Unix/Linux command line. I've yet to see an IDE that can beat the productivity of that, or even get close.

Take a Java or C# project and tell me what you can do with the CLI. Auto completion? Re-factoring(grep and replace doesn't cut it)? Code generation? I said Java and C#, because I don't know which IDE people use for dynamic languages, and if it is possible to offer accurate completion without executing the code(in some cases, it won't work even with code execution but there was an article from the VS python guys(I thi…

> Auto completion? Re-factoring(grep and replace doesn't cut it)? Code generation?

Auto-completion is an editor feature, and support for auto-completion in text-mode editors is not a problem, though I don't use it as I hate auto-complete with a vengeance. If you need to type enough for auto-complete to matter, your language and/or your identifier names are messed up.

Re-factoring and code generation are features I expect of the editor and/or external command line based generators respectively, and there's no reason for a heavy IDE.

I can understand people grab onto IDE's if forced to deal with ridiculously verbose languages like Java or C#, possibly. Yet another reason to stay away from these languages.

Re: Things that Ruby on Rails people tell you

#67
post #62

Earlier quoted context omitted.

> You don't see how uncomfortable for the hands it is to type ` ` every single time you want to output something using code? How can you compare that, to a simple `@` symbol? ERB (or even Mustache for that matter, feel like a relic compares to Razor. I don't think you are doing an objective evaluation. 1. All goddamn editors can be configured to do a short key for the expression(I have mapped \1 to ` ` and \2 to ` `)…

You're comparing something that comes out of the box (Razor) with something you can achieve comfort with after wiring up hotkeys and snippets. That's not a fair, clinical comparison. Are you kidding me? Slim looks like something much MUCH better than the crufty old ERB.

> You're comparing something that comes out of the box (Razor) with something you can achieve comfort with after wiring up hotkeys and snippets.

And what difference it makes if it comes with Rails or I have to add an entry to Gemfile? Ruby has many different templates. What comes bundled with Rails is totally up to creators. DHH is opposed to haml https://twitter.com/dhh/status/58289541068492800 and hence, erb is the default which is unlikely to change.

They don't even have to accommodate alternate templates(which they do seamlessly). Do you cry a river every time you have to use a library which doesn't come bundled with .net?

> Slim looks like something much MUCH better than the crufty old ERB.

And it's better than Razor's crufty syntax as well.

But please keep tooting your horn about your Razor. I have wasted enough time here.

Re: Things that Ruby on Rails people tell you

#68
post #62

Earlier quoted context omitted.

> You don't see how uncomfortable for the hands it is to type ` ` every single time you want to output something using code? How can you compare that, to a simple `@` symbol? ERB (or even Mustache for that matter, feel like a relic compares to Razor. I don't think you are doing an objective evaluation. 1. All goddamn editors can be configured to do a short key for the expression(I have mapped \1 to ` ` and \2 to ` `)…

You're comparing something that comes out of the box (Razor) with something you can achieve comfort with after wiring up hotkeys and snippets. That's not a fair, clinical comparison. Are you kidding me? Slim looks like something much MUCH better than the crufty old ERB.

[deleted]

Re: Things that Ruby on Rails people tell you

#69
post #58

Earlier quoted context omitted.

ERB ( one of a ton of view engines you plug into rails): Or: I don't even like Rails, but I fail to see how that is "really smelly". Or as I prefer Mustache, I'd probably rather pass Model.friends to the view as a variable and do: {{#friends}} {{name}} {{/friends}} But regardless what engine you do, you'd be hard pressed to find any big differences in terms of iterating over a collection. I find it very hard to belie…

You don't see how uncomfortable for the hands it is to type ` ` every single time you want to output something using code? How can you compare that, to a simple `@` symbol? ERB (or even Mustache for that matter, feel like a relic compares to Razor.

If you don't like that, you can use haml for example, or any number of other engines. It didn't even occur to me that anyone would care enough about the that to be the point.

If it matters, it'd take about an hour to put together a wrapper to let you use the @foreach ... { } syntax with Rails. Nobody bothers because this is about item #1045 on the list of pain points in web development.

FWIW: For my part I consider it a massive smell to have what appears to be code in the templates, which is why I prefer Mustache and similar which explicitly force the logic to be kept separate, so to me the Razor example and ERB examples look equally hideous.

Re: Things that Ruby on Rails people tell you

#70
post #61
post #57

Earlier quoted context omitted.

> I wasn't aware Fowler is a required reading for anything(or I would say even beneficial) for _anything_, let alone AR. Then I suggestion you read Enterprise Application Architecture. It's a great book for the way it formalises a number of very common patterns in a very concise way. It is also directly or indirectly the inspiration for a large number of recent ORM's and worth reading for that reason alone. Active Re…

> Unfortunately most picked off the easiest ORM pattern presented and stopped there, without alerting their users to all the caveats of the pattern. I have a general dislike for Fowler church of patterns. That is not to say I haven't gone through what is listed on his site. I didn't find it intriguing enough. I derive 100 times more value reading K&R than GoF. There is limited time and large number of books - one has…

> K&R than GoF.

Very different comparison to the patterns Fowler presented. The patterns GoF presented were very basic, and were interesting then with languages like C++ when people were still fucking up many of the basic patterns. The number of horribly broken C++ Singleton implementations I've seen, for example, beggars belief. Today that's less of an issue.

The patterns Fowler presents are, as the title says, about architecture not low level implementation, and they are patterns you will tend to find in pretty much any large software project today yet that people still manage to fuck up royally, which is the reason the patterns matter.

Patters are nothing but recipes of best practice. They're not meant to be "intriguing" once you understand the tradeoffs. They're meant to become boring and bland and trivial once people are comfortable with them and their implementation is well understood. They're also meant to give people a shared vocabulary for talking about it. That's the entire point.

Most of the patterns in EAR are nowhere that for most people, judging by the code I see regularly and judging by how there's still this cargo cult around the AR pattern by people who in many cases have not even heard about the other ORM patterns presented by Fowler, much less other alternatives.

> There is limited time and large number of books - one has to be picky.

If I were to pick any book on software development from the last 10-15 years I'd like everyone to read, it'd be Enterprise Software Architecture, for a simple reason: I still see people using those patterns every day, yet screwing them up in horrible ways. Maybe you don't need it, but the developers I come across for the most part sure do.

> Person.where("last_name = ?", last_name) is the most concise way to issue that query. Abstracting last_name so that if the field name changes, the query still is relevant is overkill.

That is only true if you're dealing with a query that simple (even then, the "Rails way" of doing your example would be Person.find_by_lastname(lastname)). On the other hand, I've read the code of dozens of Rails apps that contains several lines long SQL queries littered just because they could.

The biggest problem in your example as why you are asking for persons with specific last names in the first place. 9/10 when I see code like that, it is the wrong (too low level) question, and leaks domain logic that should be confined to the model.

Also, what happens when you need to serve that query from a web API instead of your database? From a full text engine? From file? From a noSQL database? From on disk hash table? I've had to do all of these - often several from the same application. With a suitable architecture you just plug in your new storage and implement the finders you need supported, and won't have to play "hunt the raw SQL". Changing column names is the least of my concerns - that can be fixed with a simple search replace.

You also miss the point when you say you can do a base model class and do a mapper yourself: The point is the architecture of AR makes leaking SQL which often ends up in controllers and other places they don't belong all over the place the easy default, while implementing cleaner abstractions is more work.

The end result is that most places where AR is used end up with high degrees of coupling for no good reason.

If everyone used AR in a disciplined way and avoided littering their controllers and other code with query details that belongs in their models, there wouldn't be a problem.

Your argument reminds me of the old memory-protection vs. no memory-protection in the 80's, where the Amiga camp for example tended to be bitterly against memory protection because it was seen as expensive, slow and enabling lazy developers. Expecting developers to write clean code with ActiveRecord is a bit similar to expecting developers to write code free of bad memory accesses without memory protection - it makes it far too easy to do the wrong thing.

> github, twitter, heroku et al would like to disagree.

And Ebay at least used to be written using ISAPI modules, and large parts of Yahoo runs or used to run on a horrific mess of PHP and Perl (I used to work at Yahoo; there was a lot of dreadful code). Your point again?

(and Twitter is a particularly bad example given how much time they spend moaning about how they've needed to move most stuff off Ruby)

Besides, pointing to web startups as the pinnacle of engineering quality is ridiculous at best of times - while some of what happens in web startups is amazing, there are also plenty of areas where we're still lagging 20 years behind engineering practices in the enterprise space. Active Record was not by any means a new pattern, for example - none of the patterns in EAR were. They were Fowler's cataloguing of well established patterns with years of use in industry.

Rails, and AR, is still better than a lot of the alternatives. That does not mean there are not better ways for a lot of uses than resorting to AR.

> Person.where("last_name = ?", last_name) makes it unsuitable for large projects?

Strawman. If you think simple cases like that is what it is about, you've not seen much complicated Rails code, and it's a waste having this discussion with you.

> It has been long enough to call it time tested.

So is BASIC. That doesn't mean it's good. "Time tested" is not in itself an argument for anything.

> If Person.where("last_name = ?", last_name) is not abstract enough and makes it unsuitable for your projects(still the only concrete complaint from you), look for alternatives.

I don't use AR the library unless I absolutely have to, which means I only use it if I help out on Rails projects where I can't dictate policy. Otherwise I'll generally use Sequel, which though it suffers from many similar flaws drawn in large part to inspiration from AR, is cleaner in many ways. There's many things I'd love to change about it, but I already have at twice as much stuff to do as I should.

For small projects I might use the Sequel schema module which implements the AR pattern, and which allows for a lot of the same crap that people do with AR the library, but still makes it a lot easier to avoid raw SQL. The AR pattern has its place.

But for larger projects I'd generally be inclined to implement mappers, then often with Sequel (without the schema/model module) used internally by the mappers only.

Post reply on HN