Rails Is Not For Beginners

DHH says it best, Rails was never primarily about being friendly to beginners. And he’s right, it’s not.

DHH Quote Twitter

Rails evolution is making the lives of current developers better but neglecting new developers.

The gap between starting knowledge and required knowledge is getting larger. As it increases it becomes harder to learn Rails:

Knowledge Gap

The size of Rails makes it intimidating to grok. Here’s the number of lines of code compared to a lighter weight framework, Sinatra:

Sinatra Lines Of Code(This image is taken from a Confreaks talk on Sinatra)

Rails weighs in at 87,990. Sinatra, only 1,576.

That’s a significant difference!

Enter, Sinatra

According to Sinatra’s ReadMe:

“Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort”

Hello World in Sinatra looks like this:


get '/' do
  "Hello, world"
end

That’s it. An HTTP method paired with a URL-matching pattern. The HTTP method being ‘get’, and the URL, in this case, being root.

When you visit the homepage, you’ll see the Hello World message.

Here’s another example:


get '/oscar' do
  "Hello Oscar"
end

Rendering:

You can see it’s running on localhost port 9393, and then it’s just “/oscar”. The “/oscar” being the URL-matching pattern.

Also, you can embed Ruby right in there:


get '/time' do
  erb 'The time is <%= Time.now.strftime("%I:%M %p") %>.'
end

The Ruby is specified between <%= and %>.

From here it’s easy; everything else builds on top logically.

So, if you’re looking for a Ruby framework, why not give Sinatra a try?

  • http://blog.absurd.li Kaspar Schiess

    I would disagree. Sinatra is smaller, granted, but that also means it does less for you. And the rails community is much more prepared for catering to beginners…

    I guess I would just like to keep the noise down in my favorite web framework (ducks).

    • http://twitter.com/Twisol Jonathan Castello

      Padrino, then, might be a good beginner framework to experiment with. It’s built directly on top of Sinatra, but it provides more full-featured functionality in the form of modules.

    • Fernando Irías Escher

      I think that’s exactly the point. Since Sinatra is so basic, you’re required to learn how to do a lot of things by yourself forcing you to learn. On the other hand, Rails is made to make development fast and clean doing a lot of things behind the scenes for you (like CSRF). When you run into trouble, if you don’t have the knowledge of what may be happening in the background, then you’re gonna have a hard time solving it.

  • Tapori

    Try node.js + express. Faster, cleaner and a great community.

    • pistacchio

      i’d argue that something written in javascript is cleaner than something written in ruby. and yes, i work both in rails, sinatra and node.

      • enough-of-node.js-ffs

        Apart from Node.js being a bit out of context, if you’re seriously arguing that functional programming is easier to read for a new developer, then I think it’s time to leave your bubble behind.

      • Anonymous

        i’d agree if you were talking about coffee script; plain javascript is a bit of a pain once you have thousands of lines of application code

  • http://samsoff.es samsoffes

    I agree with @kschiess:disqus  Rails is definitely harder, but it will talk to a database, handle migrations, do view inheritance, and tons of other stuff that requires tons of work or external libraries. There are lots of books, screencasts, blog posts, etc on Rails. The number of stuff on how to cobble together a bunch of gems and Sinatra is way less.

    Don’t get me wrong, Sinatra is great for simple stuff. I definitely think Rails has it’s place, even for a beginner.

  • pistacchio

    the fact that rails is not for beginners is true (and main developers say so), but suggesting for beginners a smaller framework that gives you less and hence requires you to do more, know more and make choices that rails has done for you is simply nonsense.

    • Vishnu Menon

      Yes, because everyone knows having more knowledge and making conscious design choices can bring nothing but evil!

  • http://twitter.com/eik3 Eike Herzbach

    you don’t even need ERB for that:
    get '/time' do
      "The time is #{Time.now.strftime('%I:%M %p')}"
    end

  • Thorsten Müller

    The question how long or complicated “Hello world” is, is absolutely irrelevant and says nothing at all. (Especially since your example wouldn’t be much more complicated in Rails)

    That said, I agree that Rails isn’t easy to beginners. But web development in general isn’t. You have to accept a steep learning curve if you want to do professional development in that area.
    And there is a lot of tutorials and references available and a very helpful community.

  • Anonymous

    I agree with others that with Sinatra, if you need a database (most real world apps), it’s going to be a pain to setup everything, even if you include ActiveRecord. I’d suggest Padrino.

  • http://twitter.com/henrrrik Henrik Sjökvist

    I’ve started dabbling in Ruby in recent months coming from PHP background (mostly Drupal, which coincidentally also has a much discussed learning curve) and my experience is that Sinatra isn’t all that easy once you start to pile things on. Most documentation focuses on Rails and many gems require a bit of massaging to get working since they’re built with Rails in mind (e.g. delayed_job). There’s also a lot of outdated/bad code out there so there’s a fair bit of sifting necessary to find best practice examples of how to do stuff.

  • http://twitter.com/rogerbraun Roger Braun

    Anecdote here: I tried to learn Ruby web dev with Rails about 3 years ago, and just could not go further than the basic scaffolded CRUD app that Rails gives you for free. It was just all too much: Migrations, routes, controllers, models, views… Also, I had not worked with an ORM before, so ActiveRecord was a bit hard too. I had no idea how it all worked together and everything seemed like magic.

    I then tried Sinatra and DataMapper and was pretty much productive from day one. For me as a beginner, the directness of the Sinatra approach meant that I could actually understand what was going on. I was able to learn what I actually needed and wanted in a web framework.

    About a year after that, I tried to use Rails again, and it all started to come together. I now use Rails almost exclusively. I probably could have learned Rails without knowing a simpler framework first, but it would have been much more work, and probably a lot less fun.

  • felipebrnd

    I think the problem with rails and beginners is all about that Rails do too much stuff for you, then probably young developers will be stuck on it and will be learning tricks and details for Rails and not Ruby.

  • Mladen Jablanović

    Introducing database to Sinatra is barely two lines of code:


    require 'sequel'
    DB = Sequel.connect('url://of:your@database/here')

    BTW, one should define a beginner. Is it someone who is learning programming, or someone learning Ruby, or someone learning web development etc? Sinatra is definitely less intimidating, especially to those who haven’t been exposed to MVC paradigm.

  • http://wojt.eu Wojtek Kruszewski

    I’m a 

  • http://davidsantoro.net David Santoro

    Rails LOC vs Sinatra LOC is like comparing Apples and Oranges.
    Remember that rails is a combination of various modules, and not all of them are mandatory. E.g. ActiveRecord. Sinatra gives you just what a rails controller + routing gives you.

  • Richard

    “not for beginners” is mostly true but meaningless. The noobs have adopted it instead of VB. However, I think that it’s a little more complicated than that and is much a psychological mystery as trying to understand the stock market.

    There is something to be said about “full stack awareness” and sinatra’s LOC makes that easier. Sinatra also allows you to get some real work done. My intuition tells me that sinatra does not do as much fancy META magic under the covers as Rails does; which is more of a property of the language than the framework.

    My issue with noobs, rails and ruby… is that while the “UNIX way” suggests building projects on top of each other like layers of a cake. Many of the useful GEMS have such deep dependencies that FSA is extremely unlikely… If the MBAs that ran our companies fully appreciated the complexity and risk then Rails would still be in the drawing room.

  • http://chipotle.tumblr.com/ Watts

    I’m more of a Python guy, and have started warming up to Flask in preference to Django, roughly akin to warming up to Sinatra in preference to Rails. But is Sinatra really that difficult to extend? I know I’d definitely recommend Flask to beginners, but I wouldn’t have significant worries that it “gives you less and hence requires you to do more”; integrating it with SQLAlchemy, for instance, is pretty trivial, and while Flask doesn’t have a huge library of extensions, the ones that exist cover a fair amount of standard tasks out of the box (auth/auth, session management, data store, debugging, etc.).

    A little bit of Googling just now suggests it isn’t that difficult to extend Sinatra. Sure, this requires you to “make choices that Rails has done for you,” but the chances are anyone writing a web framework in the first place can figure out how to type “sinatra database” into their favorite search engine, right? I think what the original post is suggesting is, in part, that the more batteries your framework includes, the harder it is for newcomers to get up to speed because there’s just So Much There. It may seem counter-intuitive, but sometimes it really is faster to learn a tiny framework and a few modestly-sized components that collectively add up to what you need.

  • Radu

    If Rails is not for beginners what then makes ASP. NET or other such ‘stuff’ ?

  • Alfonso J. Ramos

    X for beginners, X not for beginners, push, pull, argue, kick, punch… 

    A comment section is not good fit for what I have to say, ergo
    https://plus.google.com/u/0/107204648776497073254/posts/YECLbx7ay4A

  • Scott

    I use both Rails and Sinatra. Sinatra has 2 issues in my view:
    1) when you get stuck and need to google something, 99% of the ruby content online pertains to Rails. Good luck finding help with plain old Rack (non-Rails apps)

    2) you need to watch that you don’t reimplement Rails yourself. What starts life as a small, simple app can quickly grow in size and complexity. As you start building out your own implementations of features that are already part of Rails, there comes a point where you need to consider switching up from Sinatra to Rails, otherwise you end up reinventing the wheel.

Previous post:

Next post: