
Sinatra - Hyper Fast Mini Webapp Development in Ruby - jmonegro
http://sinatrarb.com/
======
cschneid
I've been using Sinatra for more than a year now. It's the perfect mini
framework in Ruby. It helps you get web dev done, without ever getting in your
way.

I've written a blog with lots of documentation at <http://www.gittr.com>.

In addition, coworkers of mine at Citrusbyte have taken Sinatra and built a
minimal, yet more full featured web-stack called Monk
(<http://www.monkrb.com>). Basically it takes the Sinatra library and wraps it
up with convenient conventions, libraries for testing, settings files.

I've used Sinatra for small projects like Irclogger
(<http://www.irclogger.com>) (<http://www.github.com/cschneid/irclogger>). You
can take a look at the code and see how simple it is underneath. I've also
used Sinatra for larger projects involving many files, user login and
authentication, database access, and more.

What you'll find when you're writing Sinatra is that almost nothing is
provided in the way of helpers, but also that you won't miss them. You write
your own helpers where you want, and use normal rubygems to provide other
functionality. It's not really a web framework's role to render JSON when
there's a perfectly normal JSON gem that does it well. On the other hand,
various people have recreated the small helpful stuff in reusable forms,
including fairly simple things like partial rendering, up to reverse URL
lookup (like Rails provides person_edit_path(), etc).

I'm not sure what the other commenter is talking about with bloated memory
footprint for Sinatra, it's a fairly minimal piece of Ruby code, and any
memory bloat will be the fault of your code, and not the framework itself. A
hello world app in Sinatra takes about 10 megs of ram to get up and running
(under Thin in my case). Rails takes about 40 last time I checked. Everything
from there is related to your app (be careful with ActiveRecord, it'll chew
through ram).

To sum up: Sinatra is a do it yourself framework toolkit. It doesn't provide
much beyond making it easy to build your own helpers and your own application
specific code. If you need help or advice, swing by #sinatra on freenode.org.
People are always around to help.

~~~
1gor

       be careful with ActiveRecord
    

What alternative ORM would you recommend that is mature enough?

~~~
trevorturk
I've heard good things about sequel, but have never used it personally:
<http://sequel.rubyforge.org/>

~~~
chasingsparks
I use Sequel when I am doing projects in Sinatra. It's elegant.

------
tannerburson
Sinatra is great. I've been working with it for the last eight or nine months
on various projects and I'm extremely glad about that choice. But I wouldn't
call it "hyper fast" in any sense.

From a raw performance perspective, it's faster than Rails, but it has some
issues with it's design that can cause extremely bloated memory footprints.

From a developer sense, it doesn't come with a lot (hardly any) of helpers,
generators, or other fancy tools. So depending on your use case you could end
up re-inventing some wheels.

It's biggest advantage is that it's small, lacks a lot of magic code, and
doesn't force you into a specific structure. This makes it great for web
services, small apps, or even small components of larger apps. But like
anything else it's definitely not a silver-bullet.

By design it doesn't have a lot of helpers, generators, or other tools.
Depending on your usage this could mean a lot of re-inventing the wheel.

~~~
cschneid
I'm curious what issues you've run into with regards to memory footprint. I've
not seen anything like that myself.

~~~
tannerburson
The issue is with subclass style applications. If you use multiple sublcass
apps mounted at different URLs via Rack you incur the full overhead of the
framework for each subclass instance. It's not a bug, it's just the way it's
designed.

~~~
ichverstehe
I heard this one before, and for all I can tell it's simply not true. What's
your setup?

I have tried some simple benchmarks against two apps. One with a single
subclass, and another with 3 subclasses. The one with a single subclass used
22M (RSS), the one with 3 subclasses used 23M (RSS).

This was running it with thin. The code is here:
<http://gist.github.com/187475>

~~~
tannerburson
I don't have such a simple example handy, but it's not drastically different
from your setup except I subclass an Application class, which subclasses
Sinatra::Base. I'm loading about 10 subclasses, not 3. I don't have the
numbers handy but when I last tested it, adding subclasses did add several MB
of memory per instance.

------
tptacek
Our product is built on Rails, but I do almost all my development in Sinatra
now. The biggest win for me is that Sinatra strips away everything that would
allow you to procrastinate in Rails (such as figuring out whether your actions
are RESTful enough, or making sure you're serving all the content types, or
making sure you've balanced code properly between controllers and models).

There is nothing to do in Sinatra except to get to work on your application,
which is a good thing.

I highly recommend Datamapper over ActiveRecord, too; between Sinatra and
Datamapper, you can literally pop open a single file and have a complete
working application when you exit the editor, with no external setup steps.

~~~
jamesbritt
"There is nothing to do in Sinatra except to get to work on your application,
which is a good thing."

What does Sinatra use for layouts and views and partials by default? Last I
looked it appeared to be .... nothing.

It seems then that for anything non-trivial you're either inventing a view
system or tacking one on. Am I missing something about this?

Among the things I like about Ramaze is that, like Sinatra, I can do the all-
in-one-file web app if I like, but if I decide to refactor to layouts and
views and such there's an obvious, ready path. Ramaze lets me evolve smoothly
from dead-simple to high sophistication, and I don't see that with Sinatra.

~~~
cschneid
Sinatra has built in handlers to render erb, haml, builder, and sass. Layouts
are handled by automatically grabbing the file layout.erb (or layout.haml,
etc). Partials are a bit of a pain, since you have to write your own helper,
but at it's core, you're just calling the same erb helper, but with :layout =>
false.

It's downright trivial to add your own rendering helper for any templating
language.

And for organization purposes, it's really freeform. Act like you're writing
any other ruby app, and organize how you like. If it's small, a single file
makes sense, if it's medium sized, maybe a file for controller and one for
models, for big, do the split into an app/{routes,models,views}. All of that
is easily supported.

Check out Monk as a good example of how Sinatra can be adapted to a more
complex directory structure.

(also, Hi James!).

~~~
jamesbritt
Interesting.

So far I see nothing that makes Sinatra more appealing or useful than Ramaze,
and some thing that make it less so.

The curious thing is that on the one hand Sinatra gets described as a
"framework", and on other other hand there's a great deal of BYOC (bring your
own code).

That's fine, and something I tedn to prefer, but if I really want lightweight
microstuff I'd start with a plain Rack app, and if I need more I'd convert it
into a Ramaze app.

I do like how Sinatra auto-maps the REST verbs, but basically it comes off
more as Rack middleware with a cheering section than an actual Web framework,
micro or otherwise.

(also, Hey Chris!)

~~~
tptacek
I have no horse in this race, I'm just using and liking Sinatra as a "sandbox
framework" to go along with our Rails deployment. So, with that said:

Sell me on Ramaze. I love that I can whip out a 2-file application in Sinatra
--- one file for the Ruby and templates, and another for the jQ js that'll run
on the client. What does Ramaze do better than Sinatra for me?

~~~
jamesbritt
". I love that I can whip out a 2-file application in Sinatra --- one file for
the Ruby and templates, and another for the jQ js that'll run on the client."

Yeah, I love that about Ramaze as well. :)

"What does Ramaze do better than Sinatra for me?"

Appears to be faster (at least in some simple benchmarks I ran). Choice of
templating language may be key.

Has a better-sized set of robust standard helpers, should you want to load
them.

More built-in adapters for a wide variety of template engines (Haml, Ezamar,
Liquid, Markaby, others)

Unbeatable community on irc (#ramaze on freenode)

Way cooler shirts and coffee cups:
<http://www.cafepress.com/rubystuff/4904578> ;)

Whether or not any of this works out as "better" for anyone is hard to say. I
like that Sinatra doesn't dump a ton of must-load crap on you just to get
started, but neither does rolling a plain Rack app. Or Ramaze, for that
matter.

It's also nice to have a reliable set of built-in libs to pull from, and as
best I can see there's a stronger choice in Ramaze.

But, to be honest, Sinatra just never showed enough value to me to dig into
all it's possibilities, so I may be wrong in my observations.

~~~
tptacek
Thanks. Helpful! Appreciated.

------
tibbon
I used Sinatra as my learning tool for getting into Ruby instead of Rails.
Rails was frankly daunting. I had never done web programming, only some C in
high school. I didn't like that typing 'script/generate' threw up 46 files,
each with their own purpose and use. Even with books and tutorials I didn't
quite know where to start, or how to do what I wanted to do instead of what
the tutorial wanted me to do.

Sinatra was great however. Everything (by default, I realize you can move
beyond this) was in a single file that I could glance at, find my errors and
correct. The downside mainly was that when looking for help I kept finding
Rails-specific stuff, which wasn't useful (trying looking up Ruby stuff
without encountering Rails, or accidentally filtering every decent page out of
search). The documentation for Sinatra could certainly be improved and I'd
love to see a book on it.

One of the first Sinatra tutorials you used to run across on Google (was on
<http://www.xnot.org/> but is now removed) didn't work with current versions
of Sinatra and produced very odd errors. Slightly frustrating to a noob when
the documentation isn't marked with a date or the fact that it was only to the
alpha versions.

Overall Sinatra is amazing for bashing out really quick and simple web
interfaces in about 10 minutes. Rails is just too heavy oftentimes. I might
just need to make a page that allows someone to see something that Ruby is
pulling from a database- and that's it!

------
idm
This reminds me of the Perl Catalyst approach, which states that everything
important already exists in CPAN, so the web framework just needs to provide a
little glue to stick it together.

In other words, there's massive reuse of CPAN components with Catalyst, as the
framework itself doesn't provide much for free.

The sinatra "hello world" is insanely compact, and really says something...
Here is one point where Catalyst is different, to put it politely.

On a side note, I got so frustrated with Catalyst that I now use Django.

------
lzell
Weird, I get redirected to <http://www.sinatrarb.com> on safari but not FF.
Why would that be?

~~~
tome
Because safari automatically tries www.domain.ext if domain.ext fails?

~~~
lzell
Oh I wrote that backwards by accident. But I'm sure you are right. That
shouldn't be the browser's responsibility (although it is nice that FF does it
for you). I thought it was a dead link.

------
tvon
I get a 404 on the submitted link.

sinatrarb.com points to 208.67.217.132 which does not seem to have http
running (at least not on 80).

www.sinatrarb.com points to 65.74.177.129 (which is the sinatra website)

That, and sinatra has been around for years, but I guess by the discussion
nobody cares if it's not new...

~~~
bittersweet
It seems only www.sinatrarb.com has a cname to sinatra.github.com

