I did a quick assessment of our applications at work to look at the Ruby and Rails versions that we have running in production.
Number of applications running under Ruby … :
1.8.7: 1
1.9.2: 0
1.9.3: 13
All versions of Ruby are MRI.
Number of applications running under Rails … :
2.x: 1
3.0.x: 10
3.1.x: 3
Overall I think that’s pretty good. Our applications serve millions of gamers every day and so we need to stay current with our technology stack.
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”?
The first Ruby I ever wrote was in December 2005. It was akismet.rb, a small class for interacting with the Akismet service. My post to the spam-stopper mailing list can be found here. I personally never did anything with the class and I didn’t touch Ruby again for another 3 years until I started working at Agora Games. However, if you google for akismet.rb, you’ll see it took on a life of its own by providing a seed for other Ruby libraries and Rails plugins.
One of those libraries is rakismet, written by Josh French, which provides Akismet integration for Rails. By whatever happenstance, I started following Josh on Twitter at some point. We also met up at RailsConf 2011. However, it wasn’t until today that I found rakismet and caught up with the first Ruby I had ever written, in a much different form then when it was originally written nearly 6 years ago. I can’t take any credit for its current form and function.
Open source is interesting. You write a bit of code, release it and it takes on a life of its own. “Life moves pretty fast. If you don’t stop and look around once in a while, you could miss it.”
UPDATE: 2011-09-02
I found what I believe to be the original Akismet.rb. Here’s the gist.
Let us count the ways of the n00b:
- Using require statements INSIDE the class
- Naming the file capital A kismet.rb
- Declaring instance variables
- Using the return keyword
- () for methods without parameters
- hasVerifiedKey for a boolean return
- protected :callAkismet
:)