What are good reasons to write a web application in Sinatra over Rails, particularly for someone who's spent a lot of time learning Rails?
I've been doing Rails for 2 years and I do like Rails. But it hurts not knowing if I'm missing out on something that could be really useful for my upcoming project.
Good reasons may include but are not limited to:
- Cost of development
- Situational scenarios
- Performance
- Features
- Flavor
Generally speaking, Sinatra is a lot simpler and "to the metal" than Rails. Most of the things Rails gives you out of the box are missing from Sinatra, which, depending on the project, can be a good (or a bad) thing.
A big part of those things can then be re-added to Sinatra through Rack middleware or Sinatra plugins. There's literally heaps of this stuff, in varying quality. If you do things right, your application has a good chance of being a whole lot more flexible and light-weight than its Rails counterpart, but you will be dealing with more upfront boilerplate effort (well, once again depending on the type of project.)
Then there's the Padrino framework, which is essentially Sinatra plus a default set of extensions/middleware/etc. to make development a bit more Rails-like. It's fun to work with, but I feel it sort of makes you miss out on the respective advantages of both Rails or Sinatra.
If you often end up in situations where the Rails defaults (or "the Rails way" of doing things) are not what you'd like to do in your project, or are simply too much or heavy-weight, then Sinatra is definitely worth a look.
(On a side note, I am currently preparing a series of Ruby/Rails development workshops, and will delve into Sinatra with my students before starting with Rails, since its to-the-metal nature makes learning about and understanding the design decisions made in Rails a whole lot easier.)
Edit: I sort of forgot to answer your actual question. Ha!
You may be better off with Sinatra if:
- you want higher performance (due to the simple reason Sinatra does less than Rails)
- you want to be more flexible about your technology choices
- you're looking at evented/concurrent/asynchronous execution (async_sinatra, nom!)
- you're really, really serious about making modular applications (for example, you can mount a complete Sinatra app on top of your Rails app, and other stunts)
- your application is first and foremost an API
- you have some pretty exotic requirements for your routing (even though Rails 3 is now a lot more flexible and forgiving in that regard)
- you want to learn how Rails, Rack etc. work
Don't use Sinatra if:
- you absolutely require heaps of good literature (working with Sinatra and specifically Rack will require you to browse vendor source code every now and then)
- you have a team that works better with the kind of constraints and conventions Rails gives you
- you're perfectly happy with Rails (or at least you feel the Rails defaults, performance, paradigms etc. are a good fit for your project)
HTH.