Internal Consistency

I recently started using Sinatra again for a few projects and found that my approach to developing these projects had changed significantly in such a short period of time (a couple of days). Looking at the difference between 2 significant projects, I wanted to enumerate what I found to be my “best practices”.

  • Use a “self-documenting” application name. I see a lot of Sinatra projects that use app.rb. Your application is a unique and beautiful snowflake and you give it such a boring name like app.rb?
  • Develop using Sinatra’s modular style. The changes are minimal and you don’t pollute the Object namespace.
  • Organize your overall Sinatra application. I’ve gone with the approach of configure block(s), registration of extensions, followed by registration of helpers.
  • In testing, take the approach of making the Rack::Test::Methods available in all test contexts.
  • Sinatra::Contrib has many useful Sinatra extensions, especially Sinatra::Reloader. There are also useful extensions that can give you some of those handy Rails-isms like initializers (see sinatra-initializers).

I feel compelled now to go back and update past Sinatra projects to have internal consistency and that’s a good thing.

Do you have any Sinatra “best practices”?

Tags: sinatra ruby