Live data from Hacker News

Ask HN: Ruby on Rails why the hype?

news.ycombinator.com

11–20 of 29 posts

Re: Ask HN: Ruby on Rails why the hype?

#11
post #2

Do you have a specific example of something you feel Rails doesn't do? Maybe that way somebody can tell you where in the rails ecosystem that falls.

Here is an example: User uploads and image to be OCR'ed and the resulting text is to be displayed (in process). Say I have the OCR algorithim (the business) in a c library. In the .Net world I would create a dll from the library, reference it and call the ocr function and display the results. Does RoR have the ability to include external late binding libraries where the "business" can be implemented?

Re: Ask HN: Ruby on Rails why the hype?

#12
Makes it quick and easy to create working web applications without having to worry about all the extra necessities. Yes, you should learn about databases, working with SQL, html requests, routing, etc in depth, but Rails handles it for you so you don't have to waste the time setting up the cookie cutter parts and can get right to prototyping.

Re: Ask HN: Ruby on Rails why the hype?

#13
RoR has a lot of advantages for rapid development and prototyping early on. I think over the course of the development cycle, the advantages even out with other frameworks. In other words, for the first 10% of your development, you'll get much more accomplished than if you decided to use pure Ruby (or even Django or Symfony).

However, this "magic" comes at a price, and at some point you will hit a wall, and if you're a very attentive programmer, you'll have been paying attention to what the magic has been accomplishing without you behind the scenes, and you'll be able to figure out a way around it without scrapping your code base. If you haven't done that, then you're going to pull your hair out in frustration.

To be honest, I'm not a huge fan of rails or other magic frameworks for anything other than prototyping, but ymmv, I definitely understand why people like it.

Re: Ask HN: Ruby on Rails why the hype?

#14
Rails is based around the idea that the simple cases don't need a lot of explanation to the computer. So, let's say that you have an Article model.

  class Article 
There's no need to do things like 1) tell it which database table to use; 2) tell it the setters and getters you want. Those can be inferred. Well, it's called Article so it'll use the articles table and we're going to want a setter and getter for each column.

Now, that can be overridden. You can call set_table_name to explicitly tell it to use a table, you can add additional methods, you can override the default setters and getters, etc. That's the idea behind Rails. You need a programming language to describe the decisions you're making that affect how your application works, but for a lot of things you're doing the same thing over and over and there's no reason to keep doing the same thing over and over.

Let's say that you wanted to (by default) order the articles by their creation date:

  class Article  "created_at DESC"
  end
You've now defined some business logic so that when you call Article.all, you get them in that order. On the models, you can define any amount of logic you want by creating instance or class methods. In fact, all of those fancy keywords are just mix-ins - method calls that add methods to your class.

This is why it looks like Rails is lacking a bit of business. When you call belongs_to :apple, the belongs_to method gets executed as the class is interpreted and that belongs_to method is something like:

  def belongs_to(associated)
    define_method associated do
      associated.to_s.camelize.constantize.find(send("#{associated}_id"))
    end

    define_method "#{associated}=" do |val|
      send("#{associated}_id=", val.id)
    end
  end
Now, it's more complicated than that (since belongs_to adds some additional features), but that's the basic premise. You have this foreign key association and, most often, it's a simple association where you want to define a setter and a getter for that association. So, the belongs_to method takes the name and pops out two methods based on that name. The first is the getter and it makes the name you input into a camel-case and gets the constant with that name. It calls the find method on that constant and inputs the foreign key value to the find method. Likewise, the setter (setters in Ruby are methods that end with the equals sign) and sets the "name underscore id" attribute on the model to the id of the associated object.

But you could just as easily define the methods yourself in the Article class rather than using the helper mix-in. Likewise, if you have business logic that doesn't fit in with what's already made, you can define any methods you want on your model classes.

The same goes for controllers. Controllers can be pretty small. If you're just trying to get the latest 10 articles, there isn't a lot you have to do - you need to fetch them from the database and store them in a variable. This is another one of those areas where Rails doesn't ask you for things it can assume. Instance variables (which start with the "@" symbol) get passed to the template, local variables (which have no prefix) don't go to the template. The template that gets rendered is the one named "controller/action". Of course, you can override that and call render :template => "xyz/abc" if you like.

I'm sorry if this seems a little all over the place, but I'm not sure what kind of business logic you're looking to implement. If you give me an example, I can provide some insight. However, from what you've said, it looks like you've just seen the basics of what models can do - and that's because a lot of the intro code is "let's build a blog" where there isn't a ton of business logic. But you can make any methods (class or instance) you like to do things to your data. Rails creates the basic cases for you - because the basic cases are well-understood. However, you can make them more complex:

  class Article 

Re: Ask HN: Ruby on Rails why the hype?

#15
post #2

Do you have a specific example of something you feel Rails doesn't do? Maybe that way somebody can tell you where in the rails ecosystem that falls.

Here is an example: User uploads and image to be OCR'ed and the resulting text is to be displayed (in process). Say I have the OCR algorithim (the business) in a c library. In the .Net world I would create a dll from the library, reference it and call the ocr function and display the results. Does RoR have the ability to include external late binding libraries where the "business" can be implemented?

Ruby certainly has that ability, and there's nothing particular to Rails that prevents you from doing any Ruby things like that. In the Rails world, actually, you'll find lots of solutions (e.g. delayed_job) for offloading work like that from the web server process on to a dedicated worker queue. But there's no reason you can't just handle it synchronously either.

Re: Ask HN: Ruby on Rails why the hype?

#16
post #3

The "computationally interesting" stuff shouldn't be handled by your web framework. That's not its job. What Rails does well is let you get a baseline-nice web application with many common features up and running without much fuss.

Agreed, I was just probing the limitations if any.

Re: Ask HN: Ruby on Rails why the hype?

#17
It's fast, good for prototyping and it's built in testing frameworks are better than nearly any other framework I have used. Especially native to the framework.

There are a number of things I don't like about rails, and it's more important that in most languages to do lots of unit testing because of the extremely dynamic capabilities of ruby. You'll be happy when you do gem updates

Re: Ask HN: Ruby on Rails why the hype?

#19
post #2

Do you have a specific example of something you feel Rails doesn't do? Maybe that way somebody can tell you where in the rails ecosystem that falls.

Here is an example: User uploads and image to be OCR'ed and the resulting text is to be displayed (in process). Say I have the OCR algorithim (the business) in a c library. In the .Net world I would create a dll from the library, reference it and call the ocr function and display the results. Does RoR have the ability to include external late binding libraries where the "business" can be implemented?

dll -- RubyMono / RubyCLR -- not very ruby way to do it.

A better one is to build a gem with c bindings (RMagick has bindings for all the ImageMagick functions right away).

Re: Ask HN: Ruby on Rails why the hype?

#20

RoR has a lot of advantages for rapid development and prototyping early on. I think over the course of the development cycle, the advantages even out with other frameworks. In other words, for the first 10% of your development, you'll get much more accomplished than if you decided to use pure Ruby (or even Django or Symfony). However, this "magic" comes at a price, and at some point you will hit a wall, and if you're…

What is the difference between Rails and Django in the first 10% of development? I'm pretty into Django right now, but haven't yet given Rails a shot other than reading a short book about it.
Post reply on HN