Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror
×

What's the Secret Sauce in Ruby on Rails? 414

An anonymous reader writes "Ruby on Rails seems to be a lightning rod for controversy. At the heart of most of the controversy lies amazing productivity claims. Rails isn't a better hammer; it's a different kind of tool. This article explores the compromises and design decisions that went into making Rails so productive within its niche."
This discussion has been archived. No new comments can be posted.

What's the Secret Sauce in Ruby on Rails?

Comments Filter:
  • Re:A question... (Score:5, Informative)

    by masklinn ( 823351 ) <.slashdot.org. .at. .masklinn.net.> on Sunday May 14, 2006 @11:42AM (#15329640)

    Fact is that Rails template (rhtml files, the views) are scripted directly using Ruby (there is no specific view/template language). This means that they can be abused, not that they should.

    When used well, Rails views are actually quite clean due to the high readability of Ruby itself and the ability to rapidly create so-called Helpers (Ruby methods that you can call from your views, to build specific HTML structures from generic datum, since you come from JSP land think Taglibs, but much simpler to define & use)

    Seems like DHH found Ruby simple enough to just use it as a templating language (and it works quite well), that's his choice, other frameworks in other languages picked a different one (Python's Django has a template-specific language for example, much simpler and less powerful than full blown Ruby but much less prone to abuse either)

  • It's multiparadigm. (Score:2, Informative)

    by Anonymous Coward on Sunday May 14, 2006 @11:46AM (#15329652)
    The big benefit is that it's multiparadigm. It draws the best from the OO world of Smalltalk, while also offering very solid functional features. These are the traits of languages that are suitable for high-quality, fast-turnaround software development.

    We can see Ruby applications that are comparable functionality-wise (and portability-wise) to C++ programs, but written in a 1/10 of the time with 1/20 the number of lines of code. That's why Ruby-based solutions are effective and popular.

  • by Scarblac ( 122480 ) <slashdot@gerlich.nl> on Sunday May 14, 2006 @11:48AM (#15329661) Homepage

    As far as I've seen, there isn't that much actually new in RoR. But it's obvious that someone has had a great idea how a whole bunch of known stuff should fit together, in a way that encourages best practices (like a lot of testing, and code reuse). It has near perfect design.


    The language Ruby wasn't new; Active Record wasn't new, nor was the idea, but it fits with Ruby really well. MVC was old, but the tiny bits of boilerplate needed makes it look like magic now and then. Everybody knows testing is essential, but I hadn't seen it integrated into a web framework so well before. The idea of "sensible defaults" can't have been new, but the switch from reams of XML (in Java web programming) to near invisible config is great. The object-oriented Javascript libraries it uses weren't new, nor are template languages, but the way in which they're added together is pretty seamless. Et cetera.


    No wonder every web programming language community out there is rushing to put together it's own version of Rails... but the libraries don't always fit together as seamlessly. I think that Hansson's main achievements are recognizing that all the known best practices can be put together really well, and that Ruby and its libraries were a great fit for that.

  • Django, anyone? (Score:2, Informative)

    by Bazman ( 4849 ) on Sunday May 14, 2006 @11:49AM (#15329662) Journal
    Python programmers can get the same kind of experience without learning a new languge with Django [djangoproject.com]. Yes there are differences to RoR but the productivity gains are there. Django gives you database/object linkage, templates, views and all that, and a free and very very usable database interface generated from your model spec.

      Oh, of course there's a big backlash against web frameworks these days isn't there?
  • Re:A question... (Score:2, Informative)

    by FuzzzyLogik ( 592766 ) on Sunday May 14, 2006 @12:13PM (#15329728) Homepage
    You can use a lot of different templating languages here. A few off hand... Liquid [leetsoft.com] Markaby [hobix.com] You can write your own in fact. There's actually two that come in Rails, Builder for creating xml files (rxml) and the other you normally see for building html pages (rhtml suffix)
  • Re:Nice Summary. (Score:2, Informative)

    by CableModemSniper ( 556285 ) <.moc.liamg. .ta. .odlapacnagol.> on Sunday May 14, 2006 @12:16PM (#15329737) Homepage Journal
    Then it's been a sad world for a very long time.
  • by Krimszon ( 815968 ) on Sunday May 14, 2006 @12:32PM (#15329778)
    To enable some of the RAD Ruby will infer much information from simple syntax and naming schemes. So if you start a class naming it Person, Ruby will look at a table called People to try to figure out the different fields/properties for that class. That's why it comes with some knowledge about plurals built-in.

    It's probably not that disturbing if you are used to it, and it is exactly what makes Ruby so fast for development. It's convention over configuration. In a different toolset, you might have to make a mapping from class to table using XML for instance.
  • 1. It's easy to build hash tables in Ruby- At any level of a hierarchical structure like HTML you can have an arbitrary number of child elements or attributes, all identified by a type tag. This happens to map perfectly onto ruby's hash tables, so to create an HTML link you can say:


    link_to :id => 'add user', :class => 'shiny button', :action => 'add_user'

    2. Lack of superfluous syntax It is very elegant how every programming idea in ruby seems to require only a single syntax concept at a single location to put it into practice- For instance, if you need a class member variable, you just create a name starting with "@" (like @firstname) without having to declare the variable in a separate location in the file. This is taken advantage of very cleanly by the ROR system, so that programming web pages has a very "WYSIWYG-ish" feel- Every concept in you web site has a clear, understandable equivalent embodiment in the Ruby code

    3. Dynamically detects missing methods- I don't know exactly how it works, but ruby classes are able to know when a method on an object is called at runtime that doesn't exist- So you can essentially enhance the functions an object supports at runtime... this allows Ruby toolkits, such as Rails, to essentially shoehorn their own custom language ideas into ruby (not quite at the level of Lisp's "defmacro", of course)

    4. It was scalable from day one- Right from the start, ROR was designed to scale- In fact, it was already part of a commercial app before it even existed as a stand-alone product. This means it already overcame the greatest hurdle of any web-development framework from day one- Most Scheme/Lisp frameworks, for instance, still haven't achieved the level of scalabilty that ROR had right from the start.

    5. It has a whiff of that mystical Scandinavian software guru-ism in it that make for seriously powerful software Creating a comprehensive web development system is a messy undertaking- ROR is the product of an obsessive Northern European fanaticism that somehow manages to combine an incredible pragmaticism and also manages to handle all of the many ways that web frameworks fail with the utmost of effectiveness. It isn't brilliant because it makes it easier to do complex things, as other frameworks try to- It's brilliant because it makes things that are already easy so much easier that all the complexity, though still complex, floats to the surface of your code and isn't obscured by the many "easy" parts.

    6. No pre-processor Many of the more advanced web-frameworks, as in JAVA, require pre-processing of HTML templates with embedded JAVA- The dynamicity of Ruby makes this step hidden- Explicit preprocessors are practically and cognitively difficult for programmers to deal with.

    These, I think, are some of the non-obvious reasons that give ROR the edge over other web frameworks.
  • Still no Unicode (Score:5, Informative)

    by shutdown -p now ( 807394 ) on Sunday May 14, 2006 @12:58PM (#15329882) Journal
    The biggest problem with Ruby - and, by extension, Rails - in my book is almost complete lack of Unicode support. See for yourself [rubyonrails.com]:
    Please note that right now Rails basically knows nothing about Unicode and pretends everything is just bytes. It means that validates_length_of for multibyte characters will trigger errors at the wrong places, various kinds of Unicode whitespaces are not going to get trimmed and sometimes Rails will cut right into your characters. Absolute most of Rails internals makes no notion that multibyte text even exists, Rails just delegates all to the Ruby string handling code (which in current Ruby is all single-byte).

    This is being looked at, but in the meantime you use UTF8 encoded strings at your own risk and you can expect (and wil get) bugs and problems.

    It might not look like a big deal to English-speaking people, maybe also for Western Europe (they can usually get away with Latin-1). But the rest of us do need it... that, or going back to multiple charset/encoding hell.

    So, for now, it's Java or Python, and associated frameworks for me. But not RoR.

  • by rudedog ( 7339 ) <{dave} {at} {rudedog.org}> on Sunday May 14, 2006 @01:08PM (#15329932) Homepage
    A reasonably up-to-date version of Rails (1.1.0) is directly installable in Debian testing and unstable; just use "apt-get install rails".

    If you're using Debian stable or prefer to use Rubygems to get the most up-to-date stuff, add this to your sources.list:

    deb http://www.sgtpepper.net/hyspro/deb [sgtpepper.net] unstable/
    deb-src http://www.sgtpepper.net/hyspro/deb [sgtpepper.net] unstable/

    Then "apt-get install rubygems".

    Then "gem install rails".

    Then set GEM_HOME to "/var/lib/gems/1.8" and add "/var/lib/gems/1.8/bin" to your path.

    Then do "rails my_new_project" and have fun.
  • by Anonymous Brave Guy ( 457657 ) on Sunday May 14, 2006 @01:11PM (#15329947)

    Reading TFA, I wouldn't use words like zealotry or fanaticism to describe either the article or the attitude of the Java programmers it seems to be aimed at. What I do see, though, is a terribly narrow-minded view of programming, and an obvious lack of broader experience. Let's take a few choice quotes.

    From the About this series box, before we even get to the article itself:

    In the Crossing borders series, author Bruce Tate advances the notion that today's Java programmers are well served by learning other approaches and languages. The programming landscape has changed since Java technology was the obvious best choice for all development projects.

    Surely most of us would agree that any programmer is well-served by familiarity with a variety of languages, programming styles and tools, and by choosing the most appropriate for any given job. Which, despite the absurd claim above, has never been Java in all, or even most, cases.

    From the "Hype and skepticism" section:

    Rails proponents boast of incredible productivity, with some claims of 10 to 1 over Java development. As a Java programmer, your knee-jerk response is to dismiss any wild productivity claims because you've likely heard them before and been disappointed.

    No-one who's looked into a wide range of programming languages (and I don't mean Java, C++, C# and Visual Basic.Net) would find those claims particularly surprising or implausible. The functional programming world has been outclassing workhorse industrial languages like C++, Delphi, Java and co. in productivity by an order of magnitude for a long time, at least for the kind of application that lends itself to a functional style. So-called scripting languages, which cut away much of the boilerplate baggage required by the workhorses, have proven to be a much more efficient tool for many kinds of project as well, often due to relatively simple features like supporting common data structures as first-class entities.

    Moving on to the Rails philosophies, we see things like "Don't Repeat Yourself" being highlighted as "core opinions pervasive within Rails". Surely abstracting common code and data structures into reusable units is a basic principle of sound programming in pretty much any language?

    Then we get to the "niche" for Rails:

    I'd guess that as many as half of the applications built today are database-backed, Web-enabled applications.

    I'd guess that's wildly optimistic, though it's certainly a common conceit among Java programmers IME. Not everything in the programming world is web-enabled, and much of it has no interest in becoming so either. Why would a high-performance scientific application, a CAD/CAM/CAE package, a FPS or the firmware in your washing machine care about database-backing and Web-enabling?

    All-in-all, this seems to be an article aimed at die-hard Java programmers with little experience of the wider programming world. Its arguments support wider exposure to programming and good general programming principles, though it forgets to mention that Ruby on Rails is far from the only way of achieving those ends.

  • by Discordantus ( 654486 ) on Sunday May 14, 2006 @01:25PM (#15330023)
    Insightful? Good grief; someone misunderstands a word, turns it into a politics discussion, and gets modded insightful. Amazing. I especially like how he thinks the founding fathers were conservative. Haven't heard one like *that* in a while.

    First point: "liberal" has more meanings than just "Democrat". It's use in the grandparent post was to refer to the fairly liberal (generous, ample, unlimited (see http://answers.com/liberal [answers.com]) qualities of the MIT license. A conservative license is more like a corporate license; "conservative" means "restrained; cautious, moderate; favoring traditional values; preservative" (see http://answers.com/conservative [answers.com]). A restrained license? doesn't sound very like liberty to me.

    Second point: The founding fathers were conservative? Please describe for me how they were cautious? Or restrained? They certainly didn't favor traditional values; no, they were revolutionaries, who rebelled strongly and bravely against the traditional governments of Kings and Lords. They favored ":maximizing each individuals rights and minimizing the role of the state" in their lives. They "believed in free will", and the fundamental right of a person to have the opportunity to create their own place in history. This, by definition (see http://answers.com/libertarian [answers.com]) makes them libertarian, not conservative or liberal.

    Sorry for the off-topic second point, but not replying to things like that are impossible.
  • by otomo_1001 ( 22925 ) on Sunday May 14, 2006 @01:30PM (#15330044)
    Well with your weird example, here is what I would use (not really because it violates lots of say what you mean rules).

    ruby -e 'puts 0 ? 0 : "not zero"'

    Have to take out the warnings because you are doing something weird. You do know that ONLY false, 1, and nil derive to a failing condition right?

    I like perl too, but your example isn't hard to come up with an equivalent. If you mean ruby can't do as many one liners from the command line, you are wrong there too.

    Anyway I need food.
  • by Anonymous Coward on Sunday May 14, 2006 @01:32PM (#15330051)
    There was no need to add that special case because in Perl, "0.0" does the exact same thing as "0 but true". Perl has a lot of such useless special cases - for instance the string "ignore" will not generate a warning in void context.

    But Ruby, unlike Perl, has real booleans. So 0 is true. And "" is true. Thereby avoiding a very common source of Perl bugs. (Really, how many people religiously check defined in Perl? Not enough, else the need for "err" and "//" would have been apparent a long time ago.)
  • by James Kilton ( 714163 ) on Sunday May 14, 2006 @01:40PM (#15330100)
    Wow, frankly I'm glad people like you aren't joining the Ruby community. If you even spent 1 minute looking through the Rails code, you would have found the Inflector class that does this "magic". Ruby itself doesn't do that! and you're either naive, ignorant, or both to think that it would.
  • Re:Liberal license (Score:2, Informative)

    by GigsVT ( 208848 ) on Sunday May 14, 2006 @01:58PM (#15330171) Journal
    Until Sun gets bought by some "we sue people for a living" company, like SCO did. Then they'll be a big scramble to make a third party JVM (and libraries) that doesn't suck and is clean of Sun IP.

    Will they pull it off in time? Who knows. It's still a huge risk to have invested years into an application that can have the rug pulled out from under it at any time.
  • by Fweeky ( 41046 ) on Sunday May 14, 2006 @02:03PM (#15330188) Homepage
    If a method doesn't exist, Ruby calls method_missing:
    irb(main):001:0> class Foo
    irb(main):002:1> def method_missing(method, *args)
    irb(main):003:2> puts "Called #{method.inspect}(#{args.inspect})"
    irb(main):004 :2> end
    irb(main):005:1> end
    => nil
    irb(main):006:0> Foo.new.bla(1,2,:moo => 'bla')
    Called :bla([1, 2, {:moo=>"bla"}])
    => nil
  • Posted on IBM (Score:2, Informative)

    by zlogic ( 892404 ) on Sunday May 14, 2006 @02:29PM (#15330303)
    This article is hosted at IBM, and IBM invests heavily in Java (SWT, Eclipse, etc.) So this article should be taken with a grain of salt. It's like Microsoft comparing .NET with Java (remember Microsoft's ".NET is X times faster than Java" statements?)
    However it's nice to see that IBM knows that Ruby exists and knows its strong points - so that they may borrow the good stuff into Java.
  • Re:It's Ruby (Score:3, Informative)

    by x2A ( 858210 ) on Sunday May 14, 2006 @04:37PM (#15330745)
    I think you need to read the post you replied to again, especially how the second sentence (beginning "Everything") changes the meaning of the first sentence, which you replied to as if the second one wasn't even there.

  • by DavidNWelton ( 142216 ) on Sunday May 14, 2006 @06:05PM (#15331096) Homepage
    Perhaps you should look at Lisp/Smalltalk/Your favorite academic language not being able to market their way out of a wet paper back:-) If they've had since the 70ies to build something that'll take off, and they haven't, they're doing something wrong, and it sure isn't the languages themselves, because they are very nice indeed.

    Changing subjects, one of *my* favorite "cheap Lisp imitations" (it's Lisp, not LISP) is Tcl:

    http://antirez.com/articoli/tclmisunderstood.html [antirez.com]

    which is in some ways more flexible than Ruby - you can redefine existing control structures like if and while, or create new ones of your own (such as do ... while, which is not part of the core language).
  • by Santana ( 103744 ) on Sunday May 14, 2006 @07:08PM (#15331340)

    The heavy use of sigils is not Ruby's fault, it's yours. I've written a lot of Ruby code and have rarely used sigils.

    Sigils in Perl are mandatory and define whether a variable is a $scalar, a %hash, an @array or a &block of code. Ruby's sigils define scope: local (no sigil), @instance, @@class or $global variable, which is a good approach since it let's you know instantly whether a variable is local to the block of code or comes from another scope, which is far more important than its type.

    So, unless you're using a lot of global variables, you shouldn't be heavily using sigils.

    Finally, I don't see anything wrong with having regular expressions as part of the language. But if you don't like that, nothing stops you from using Regexp and Match objects.

  • by Nataku564 ( 668188 ) on Monday May 15, 2006 @12:29AM (#15332502)
    Indeed. Despite the touted benefits of .Net, and how it would rid us of all the system dependencies problems had with previous Microsoft technologies. Just a week ago or so I had the pleasure of running into a C# app that operated differently on 2 boxes. It was run from the same clean network directory, same version of the .Net runtime, same OS, all patched, and fetching data from an application server. There was absolutely no reason for it to behave differently, yet it did ...

    People wonder why I like Perl so much ...
  • by Jondo ( 693238 ) on Monday May 15, 2006 @04:37AM (#15333031)
    I've used rails for only a few months, but already have quite a good understanding of how everything works, and have even done some hacking/patching on the backend. I've also used ActiveRecord with some applications that are not web-based, all with good success. I love every convention in Rails, except for one, which I dearly hate.

    ActiveRecord was designed quite obviously from the perspective of a MySQL user. The train of thought that a DB should only be a place to dump your data and nothing more is extremely prevalent with ActiveRecord. Things like referential constraints on foreign keys are completely ignored/not used, instead being defined in entirety in the model code. Perhaps my biggest aggrivation with ActiveRecord however is that it assumes I implement enumerations as varchar datatypes. I find this just plain wrong. Here's an example:

    ActiveRecord way:
    CREATE TABLE Users (
        id integer primary key,
        username varchar,
        usertype varchar
    );

    ActiveRecord will then use its single-table inheritance logic and each subclass of User eg "Administrator" will have that name in the usertype field, stored as a string. From a data-modelling perspective, I find this so wrong. I naturally implement this using an extra table of usertypes and a foreign key in Users:

    CREATE TABLE UserTypes ( id integer primary key, type varchar);
    CREATE TABLE Users (
    id integer primary key,
    usertype integer references UserTypes(id)
    );

    I have managed to get ActiveRecord to play somewhat nicely with these types of constructions by redefining some class methods in ActiveRecord::Base, but I'm definately violating DRY.

    This all said, and including the time I needed to spend hacking around in the ActiveRecord code, I am still more productive with Rails. Highly recommended, just with a hint of caution towards ActiveRecord paradigms and database integrity.

The rule on staying alive as a program manager is to give 'em a number or give 'em a date, but never give 'em both at once.

Working...