Archive for the ‘Ruby’ Category

Introducing Railscheck - A Q/A verification tool for Ruby On Rails

April 15, 2008

The problem

It is a law of software development that the earlier one identifies a problem the cheaper (and less embarrassing) it is to fix. Hence, we developers strive to identify errors early on our own development machines aided by sound development methodologies, tools, and tests (at best automated).

A particular quality assurance challenge with dynamic technologies like Ruby/Rails, Javascript or view templates like ERB is that you have no compiler that checks for syntax errors in advance. So you have to have 100% test coverage (which is often too expensive to be realistic) in order to be assured that even simple syntax errors does not occur.

Furthermore in the case of Ruby On Rails, which is of heavily opinionated nature, there are many conventions that can be broken by mistakes, which may introduce errors that do no show up initially. This introduces additional testing/debugging work for the programmers (in particular for newcomers to RoR).

Happily Ruby On Rails is so productive a web technology that it more then compensates for these difficulties but even though would it not be nice with some automated tool to help out a bit?

Unfortunately, your typical Ruby development tools does not provide any kind of static verification checks since the problem appears to be just about unsolvable in the general case (because of the dynamic nature of Ruby).

But what about the smaller problem of static verification checks for Ruby On Rails projects only? The RoR domain is much smaller and highly standardized so what is impossible for the entire domain of Ruby programs should be partly possible in Ruby On Rails!

Railcheck

So inspired by LINT , the power of Ruby meta-programming and various RoR testing snippets on the web, I wrote this initial beta release of Railcheck which is a semi-static verifier for your Ruby on Rails projects.

Delivered as a free Ruby gem the Railscheck project provides a shell command task “railscheck” that you can run against your Rails projects to test for a number of typical bugs and inconsistencies. See the project site and linked readme file at railscheck.rubyforge.org for details about how to install and run the tool and much more.

Railscheck is a working beta. The gem works and is useful but has a limited feature set. Much more to come. Use the rubyforge tracker function on the Railscheck website to suggest features that you would like to be added (or bugs to fix). You are also very welcome to add code/tests to the project, which is open source. Indeed the project is now open to new contributing members.

Update:

Updated the gem with improved contributor documentation, an explicit gem dependency and a fix for a typing error in railscheck.rb file. Try again if you had problems.

Rails and file uploads

April 10, 2008

While there certainly are several good file upload plugins for Ruby on Rails. It is actually somewhat hard to find any good tutorials on how to do it yourself. I just wanted to post to great links that helped me figure the whole thing out :)

http://blog.vixiom.com/2006/07/26/rails-stringio-file-upload/

http://manuals.rubyonrails.com/read/chapter/78

(Now I also know where to look when I have to work with file uploads in the future)

Ruby Fools conference in Copenhagen

April 3, 2008

So we went to the Ruby Fools conference here in Copenhagen and this post kind of sums up my experience of the different speakers. The conference went over two days and had three tracks. I primarily focused on the Advanced Rails stuff. I’ll probably update this post once you can download the presentation slides (and video).

Tuesday:

Dave Thomas explained in his opening keynote why he is a Ruby Fool :). He’s gave a great performance about his passion for Ruby and went on to compare the sudden rush of developers coming to the platform with Rails to “golddiggers and prostitutes” (before Ruby was this nice little settlement, and suddenly everyone wanted to join). That of course hit pretty much 80% of the people sitting in on the keynote. Great stuff :D.

REST: A pragmatic introduction to the Web’s architecture by Stefan Tilkov. While REST is not that new to us, and the speak therefore didn’t provide much to us, Stefan was great to talk with and I threw a few ideas on him about some of our challenges with REST (like, what do you do when you’re implementing a dashboard with some functionality also found in other places of the system - expect a new blog post on this).

Tuning the Rails stack by James Cox. Since tuning involves turning alot of knobs al over, this is not an exact science, but he did give som nice pointers on e.g. MySQL tuning and also told a few scary stories on applications that didn’t scale. On a side note, he had the coolest presentation slides (well, not really slides, I think he said it was a flash movie :))

Advanced Ruby on Rails security by Heiko Webers. I’m having my doubts on what to write here. Let me first say that the content of the presentation was great and very “german”. It was “Do this/Don’t do this”. Great stuff. No room for interpretation and once the slides are downloadable I’ll probably run through every slide while looking on our own TBA application :). Unfortunately Heiko wasn’t the great presenter and while the slides was clear, he pretty much just read them out loud, but was in trouble whenever he had to explain something that wasn’t on them.

Meta-meta programming by Nic Williams - man I love this guy.

1) The presentation was close to useless when looking at the use cases where this can be applied.
2) The subject was VERY technical

And yet… This was perhaps one of the greatest presentations due to the amount of humor and general relaxed style of Nic. Basically everyone knows meta programming, so meta-meta programming was the meta programming of meta programming. The easiest explained example in rails terms is a generator that generates generators (as I said… Not the most common use case :))

Party keynote by Evan Phoenix. A couple of sponsors had provided food and beverages so of course there was a “party keynote” (Dave Thomas wanted to swap keynote with Evan :)). While I have a great respect for Evan, the keynote was close to “not relevant at all” to me. He basically explained how he does project management on the open source project Rubinius. I’ve haven’t been in a open source project before, but what he presented was pretty much “be nice and positive to people”. There was some debate about the policy on the project that once you committed your first patch you get full commit access to the project. While it certainly works for him, I’m still having my doubts.

Wednesday

Keynote: Ruby: Past, Present and Future by Yukihiro “Matz” Matsumoto. This whas great to here it from the creator himself. There weren’t many surprises about Ruby it self, but it was great to hear about what his thoughts was on other languages and why he then went on to create Ruby. The future part was a bit cutted off because he spent a little too long bitching about character encoding (UTF-8,16,32). It was clearly something that he’s spent a lot of time on with the 1.9 release.

Versioning your data model by Ole Friis Østergaard. The presentation explained 4-5 different plugins that had something to do with versioning (also an undo redo plugin that actually looks rather nice) - including his own new plugin Subversive. I kind of noted that this was actually one of the first presentations that actually showed “real live code”.

Adding full text search to your Rails application by Jørgen Erichsen. We’re currently also implementing the search enginge Solr into our own application so this presentation was a must see. While Jørgen went through the basics of the search engine and the acts_as_solr plugin (as well as Ferret and also briefly mentioned a couple of other solutions), he didn’t seem that knowledgeable about the subject when getting to stuff outside the basic behavior of the product.

The dark art of developing plugins by James Adam. This was great. James presentation was very pedagogical buildig a plugin step by step explaining every bit of the way. While plugin development aren’t that difficult to grap, it certainly put one or two thing in place for me. I’m looking forwards to his slides so I can wrap our authorization for our application up in a plugin.

After this I unfortunely had to leave because of another engangement. So I missed one speaker as well as the ending panel discussion.

Overall the conference was well planned and executed. You could perhaps argue that it is limited what you will learn in one hour presentations, but I could just have attended the workshops leading up to the conference. As a last note… The track introductions seemed a bit off = 30 minutes break - 15 minutes track introduction - 15 minutes break (though Glenn Vanderburg was quite good.

Using ExtJS tree on rails with the prototype adapter

February 22, 2008

So I’m doing a folder tree using the ExtJS javascript with the prototype library adapter. I’m pretty much doing this.

This was somewhat working. Every third or forth browser refresh the tree didn’t load any nodes. Very odd indeed. I debugged my way through using Firebug, but when this was on, it worked everytime. Since Firebug slows down the entire javascript environment I concluded that the error occured when something (or loading) happened too fast.

In the ext-all-debug.js (version 2.0.1) I tracked the error down to line  23754. The json result being evaluated is undefined (notice that this only happens some of the time). So… after hours of head scratching and putting alerts in both the prototype library and ExtJS library to see what was wrong, it hit me…

The version ExtJS I have, come bundled with prototype 1.5.0 while rails 2.0.2 comes with prototype 1.6.0.1. In my layout I simply included <%= javascript_include_tag :defaults %>, but after I changed this to:

<%= javascript_include_tag “application.js” %>
<%= javascript_include_tag “ext/adapter/prototype/prototype.js” %>
<%= javascript_include_tag “ext/adapter/prototype/effects.js” %>

Everything seemed to work. Now my only problem is that I now use Rails 2.0.2 with an old version of prototype. So can I use all the rails helpers?!?

Installing Mephisto (multi site) on DreamHost

January 7, 2008

The title might be a bit off, since I’m not providing you with a step by step guide. This post do however sum up my notes during the install.

I started by following excellent guide:
Mephisto and Dreamhost

After looking at several guides, this one was really the easiest to follow.

Now Mephisto was installed and I wanted to add multiple sites support and I followed the guide:
Setting up Mephisto for multiple sites

I did everything but couldn’t figure out why the site still used the site root (/public) as cache location. Well silly me. As it turned out I had to restart the fcgi process (something that I really thought I’ve already done). So… Remember to do a:

touch public/dispatch*

from the application root folder.

Installing RadRails and getting error “Requested operation cannot be performed because it would invalidate the current configuration. See details for more information.”

January 2, 2008

Up until now, I’ve been using TextMate to create my Ruby on Rails code, but I’ve been missing stuff like autocompletion (I know, a bit more difficult when using dynamic languages, but I really miss it because I also do alot of C# development in Visual Studio).

So.. I decided to try out RadRails that is now named Aptana Studio and the Rails development package installed as a plugin.

After the download and the installation I then tried to install the Rails plugin, but got this strange error:

“Requested operation cannot be performed because it would invalidate the current configuration. See details for more information.” and “ Subclipse Mylar Integration (1.0.1) requires plug-in org.eclipse.mylar.tasks.core (0.9.2)”, or later version.”

After some searching I found the answer here. All you have to do is to un-select the Mylar integration. Although this might be a simple operation for experienced users of Aptana Studio, I was a bit puzzled about this. As someone who just wanted to try out the Rails environment (and I guess I’m not the only one), this seemed like an unnecessary complex installation (at the time I didn’t even now what Mylar was - now Mylyn)

Best of Ruby/Rails in 2007

January 1, 2008

Thanks to the great work of the Ruby & Rails communities, the year of 2007 saw many exciting new software releases. I have listed a few releases that I would like to point out in particular and expressively thank the developers for:

* Rails 2.0 - A great open-source framework got better in December 2007 with the v2.0 release. In particular I like the improvements in security, test fixtures, http support, performance, debugger and the non-beta addition of ActiveResource by default.

* JRuby 1.0 - By mid 2007 the first proper open-source release of JRuby arrived and it was able to run (most) Rails applications. Very impressive but a bit beta-like (many key API’s are still changing and there is little documentation in the download). Look out for an even better and faster JRuby 1.1 with JIT support in early 2008.

* Ruby 1.9 ( development release) - The proper development release of the next ruby programming language and implementation, version, 1.9, was released in open-source form on 25th December. Not suited for production but gives the community a chance to experiment with, and provide feedback for, many new Ruby features and implementation changes before Ruby 2.0 arrives. My favorite changes are string encodings (for f.x. unicode) and the new YARV virtual machine included in the Ruby 1.9 release.

* RubyGems 1.0.0 - First proper release of RubyGems in December 2007 as open-source. With RubyGems Ruby developers neatly avoids Java’s classpath-hell (*). Basic but cool stuff!

* Active Scaffold 1.1 (almost) - I was not sure if I was going to include this plugin on the list because it is not quite ready (it’s a release candidate last updated in December) and because the old version 1.0 had a bit too many limitations for my taste. However, this open-source Rails plugin is simply too great to leave out. It’s is basically a parallel to “ActiveRecord” but for the front end allowing the developer to implement visual, model-driven CRUD operations quite neatly. You should check it out.

* Commerical IDEs with real Ruby+Rails support arrives in plenty. Proper IDE releases in 2007 includes Netbeans, Aptana (RadRails), IntelliJ, 3rdRail, Ruby In Steel, Komodo IDE etc… At last some real competition to plain old emacs or textmate !

Nb) I use this term for a lack of a more neutral yet common description of the issues with installing jars and configuring classpaths in Java. Java is a great development platform - which I have used proficiently and happily for 10+ years - but classpath/package/module/jar/version management is not it’s strong point

Ruby on Rails’ footprint on Microsoft

December 21, 2007

This post could also be called how David (DHH) inspired Goliath (MS).

Lately Microsoft has release a number of products and new technologies on the .NET platform. Of course this could just be seen as the way of .NET framework. I mean.. 3.0 and 3.5 are just what comes after 2.0, right?!

Anyway… We’ve had this WebForms framework for doing websites for years now, and MS never really strafed from this strategy even though the Model View Controller pattern has had alot of followers and proven itself on the Java platform. Why should we have an MVC stack when working with .NET?!? Well.. I for one find it really easy to understand. No more advanced event cycles and s… viewstate. No more postback and advanced control design… Well that’s just me. When that is said, I’ve worked almost exclusivly with WebForms since the .NET 1.0 beta was out… Of course there has been some alternatives. In the last post I linked to the MonoRails project. On the frontpage it even says that it is inspired by Ruby on Rails (just see the .rails file extension for the httphandler in all their examples).

As I wrote in the last post, Microsoft are now launching their own MVC stack… Hmmm… Why the sudden change? As with everything Microsoft goes into, they pretty much market it as something completely new and innovative. Just look at the MVC frenzy going on over at: ScottGu and Haacked.com (ok.. also alot of great examples… ).

So is this another MS MVC post… Well not really, I just wanted to sum up some recent stuff out of MS and then leave it up to you to decide if they are not (heavily) inspired by RoR:

MVC

As already discussed, the heart of RoR and a sudden shift from MS.

REST

While not invented by DHH, he spoke (and) … and the world listened. This completely suprised MS. “Does people actually need this silly rest thingy?!”. Well apparently MS is now REST’ing a but with the Astoria Project.

NRuby?

We currently have JRuby and MS recently launched their first dynamic language (IronPython) on the .NET platform. Furthermore there are job ads like this. There is also this open source project however.

O/R Mapping

While RoR uses Martin Fowler’s Active Record pattern for its o/r mapper, Microsoft finally has something they almost can call an o/r mapper. While MS has brought the dynamic expression i c# to the table with the LINQ technology, LINQ for Entities (and SQL) is really too little too late.. I’ve been using NHibernate for years now and with the LINQ for NHibernate I might just stay there :). And also remember that this is not the first o/r mapper MS tries to bring to the market. Who doesn’t remember ObjectSpaces.

While I don’t claim that MS has picked up on o/r mappers after RoR, they certainly comes in handy with their brand new lightweight MVC package.

So…

What do you think?! Is MS inspired by RoR?! I believe they are at least keeping a very big eye on it (Sauron style) but that’s just my to cents?

Shooting yourself in the leg with a bazooka

July 13, 2007

The colorful title reflects that this posting is about common mistakes done by good but relatively inexperienced software developers. Big mistakes that a developer actually need quite some skills to make. Mistakes that we unfortunately see all too often and we would rather not see much of again (hopefully this blog entry can aid a bit towards that goal):

  1. Overly complicated design – Instead of a simple design for a simple project some developers insist on using a impracticable mix of all the newest, fanciest abstractions, design patterns, techniques and advanced language constructs that can possibly be combined in one software solution. All design elements have benefits and drawbacks. Great (experienced) developers know when a particular benefit of an abstraction, pattern, technique or feature outweighs the drawbacks. There is no silver bullet. No design element works well in all situations (just as no rules that you learned in “programming school” are in fact absolute). Developers that get way too eager ends up with one big unmaintainable design mess with the combined drawbacks of all decisions but few if any real benefits remaining…. Remember, a simple design is a beautiful design!
  2. Writing too much code – Writing lengthily code with a high maintenance cost by hand when writing such code can be avoided. Much code can be avoided by choosing a more suitable design/architecture, using standard framework/library features (xml serialization is a common example), using techniques such as dynamic reflection or specialized code generation and aspect oriented tools (be careful though).
  3. Reinventing the wheel - Some developers think they can write their own code much faster than learning to understand the underlying framework and available libraries. This might in some cases even be true, but when considering overall quality and maintainability (which developers seldom do) reinventing the wheel is almost always a bad idea.
  4. Incorrect use of advanced concepts such as multithreading – Some developers use multithreading without the discipline and deep understanding that writing correct, safe multi-threaded code requires. Multithreading can improve the user experience immensely. It is also the answer to scalability nowadays. However, before even considering to use multithreading in your design, make sure to know the theory and features in your environment well. A vague recollection of mutexes and semaphores from school is not good enough. You should also realize that by deciding to use multithreading, you generally need to upgrade on testing, documentation, reviews and quality insurance.