May 27 2007

CommunityOne 2007: JRuby: Understanding the Fuss

Fellow Sun engineers Tor Norbye and Charles Nutter presented on the past, present, and future fuss of JRuby at CommunityOne 2007. To understand where JRuby is heading, the presenters painted a clear picture of the Ruby programming language. Ruby is a dynamically typed pure object-oriented language originally written by Yukihiro ‘Matz’ Matsumoto. The Ruby programming language is an expressive, powerful, and easy to learn, read, and write.

Tor and Charles gave a quick tour of the Ruby language features such as string substitution, modules and mixins, open classes, meta-programming, duck typing, literals for arrays and maps, and code blocks. Ruby is an incredible flexible and expressive language. The more expressive the language, the less code you’ll end up writing and maintaining.

Tor also demoed his work with NetBeans support for JRuby. NetBeans includes code highlighting, code completion, and documentation support for JRuby. While demoing NetBeans and thinking of JPA Tor Norbye said, “I wish they had annotations in this language.”

Technorati Tags: , , , , , , , ,


Apr 9 2007

Software Development Environment

I had to update our project wiki and detail our current software development environment. I found that we are lagging a bit behind the latest Java technologies and tools, but from a business perspective I think it is hard to up sell existing customers just so that developers can use the latest Java language features in their code. Large software clients usually invest a lot of time and money into the applications they use for their business processes and can’t upgrade based on the schedule of software tool vendors.

Thinking about the current state of tech tools, I wanted to jot down the tools of the trade that I use on a day to day basis.

Java Development/Work
Java 1.4.2
Maven 1.0
Eclipse 3.1.2 with Perforce plugin
TeamTrack

Java Development/Home
Java 1.5
Maven 2.0
Eclipse 3.2.1 with Subclipse, Groovy, JavaCC, and Aptana plugins
Subversion 1.3

Ruby on Rails
Ruby 1.8.4
Rails 1.2.2
RadRails 0.7.2

Database
SQL Server 2005 Express
Oracle 10g Express
Mysql 4.1.15

Firefox Plugins
Firebug 1.04
Web Developer 1.1.3
Selenium IDE 0.8.7

Miscellaneous Editors
SciTE 1.70
Komodo Edit 4.0
TextWrangler 2.2

Collaboration
Skype
Google Apps

Technorati Tags: , , , , , , , , , , , , , , ,


Apr 3 2007

Simply Helpful Rails Plugin

Before I begin let me just state that the Simply Helpful plugin requires Rails 1.2.2. If you already are using Rails 1.2.2 you can continue by downloading the plugin by executing the following command from the root directory of your Rails application using the terminal or command prompt.

script/plugin install simply_helpful

This plugin adds a few additional methods into the action view, action controller, and form helper that you will find more than helpful, if not essential.

In a very Rails like opinionated software fashion, Simply Helpful introduces the view helper method dom_id which will produce the right dom id for a given model instance. Since code is worth a thousands words, and since I can’t type a thousand words in one sitting let me get started with some sample code which can be placed in a rhtml view source file.

[source:ruby]
<%= dom_id @post %>
[/source]

If the @post variable was created through a model finder method and it represents a post identified with the primary key of 11, then the above line will print the following string, post_11. Notice that the recommended dom id is the model class name plus the record id. If you are using some cool Scriptaculous effects on the post title and the post body, you will need to uniquely identify each element. You can prefix an additional identifier to the dom id so as to uniquely identify different dom elements for the same post, say the title and the body. In this way, each element can have different effects. Here is an example that will produce the a id which can be used for the given title for the post.

[source:ruby]
<%= dom_id @post, ‘title’ %>
[/source]

The above snippet will produce a string that that reads title_post_11. Simply Helpful also provides a dom_class method that will return what it thinks should be the CSS class name for an element for a given model instance. As you can imagine, the dom_class recommends that the parameter’s class name be used as the dom name. Putting together a more complete example, you might have code like the following.

[source:ruby]
<H1 id=”<%= dom_id @post, ‘title’ %>” class=”<%= dom_class @post %>”>
<%= @post.title %>
</H1>
[/source]

The dom_id and dom_class methods are pretty helpful but as a co-worker stated, “I would not download a plugin just to concatenate the model class name and id together.” Luckily for my co-worker, Simply Helpful provides a lot more than that, such as form blocks. Here is an example of how I have been doing forms in Rails.

[source:ruby]
<%= start_form_tag :action => :update, :id => @post %>
<%= text_field ‘post’, ‘title’, :value => @post.title %>
<%= end_form_tag %>
[/source]

The new form_for method will create a put or post method for a form depending if the model instance is persisted in the database or if it represents a new model. In addition to automatically creating the correct action URL for the form, you have access to a form block variable which can be used to create form fields. Here is an example of a form block.

[source:ruby]
<% form_for @post do |f| %>
<%= f.text_field :title %>
<% end %>
[/source]

Compare Simply Helpful’s way of creating forms to the old school Rails ways. It might not be obvious at first, but f.text_field statement will create a text field for the title attribute of the post. If the @post model instance represents and existing record then the current title will be the default value in the text field.

As the name states, Simply Helpful provides a helpful set of methods. Simply Helpful is also required by other Rails plugins such as ResourceFeeder.

Technorati Tags: , , , , , , , , , ,


Apr 1 2007

SV RoR March Meetup

The February meetup of the Silicon Valley Ruby on Rails (SV RoR) group had speakers present on their experience with bringing a Rails application from concept to production. For the March meetup, Brian Moore from feder8 presented on his experience with bringing his social site to production.

Since most Railers are adherents of the Don’t Repeat Yourself (DRY) principle, Brian discussed how he found it convenient to share methods amongst different helpers. Brian reminded the audience of the Ruby mixin capabilities and suggested that you mixin helpers via the Ruby include method. I have written a Ruby mixins tutorial which describes this in detail.

Brian also warned that Rails logs everything, this includes login names, passwords, email addresses, credit card numbers, and any other value submitted via a form. Fortunately you can tell Rails to filter out certain form elements from being logged. For example, in your ApplicationController (application.rb) you can add the following code if you want the value of any text field named ‘password’ to not be logged.

[source:ruby]
filter_parameter_logging :password
[/source]

Brian also advised not to expose your default database id in the application’s URLs. By default database ids are mostly sequential and therefore can be used by competitors to decipher how many users you have, how many users sign up per day, how much User Generator Content is submitted to the site on a daily basis. In general Brian suggested that it is a bad idea to leak ids in your URLs.

As a general rule of thumb, Brian recommended that a given page should never take longer than half a second to load and render. To achieve this half a second rendering you might have to do a substantial amount of caching. Also to try to achieve this half second rendering time, Brian recommends to never ever calculate a value twice. For example, if your site contains images and you concatenate the image filename with the server URL. This type of calculation can be done once and the resulting value can be stored in the database so as to achieve a better overall performance.

In the question and answer discussion, he was asked how long it took him to go from idea to something real. Brian said six weeks and added, “You guys all know that it is pretty easy to ship something barely functional in rails.”

Technorati Tags: , , , , , , , , ,


Mar 2 2007

SV RoR February Meetup

Recently I attended that February 2007 Silicon Valley Ruby on Rails meetup at the offices of Insider Pages. At this month’s meeting, Scott Persinger gave a presentation of vod:pod and Matt Whittaker talked about his solo efforts with My Free Copyright.

According to Scott of vod:pod, vod:pod is another video space social network user generated content based web application. Think of vod;pod as a hyper-aggregation social recommendation site for video powered by good ol’ Rails and Ajax. Scott also informed those railers in attendance that a team of 2 software engineers went from conception to deployment in about 6 months. According to Scott, vod:pod uses the best Rails bits such as migrations, active record, plugins, Ajax + Prototype. Scott listed RJS, Hpricot + Mechanize, and IO.popen_timeout. As for Rails annoyances he lists the lack of better page component support, poor IDE debugging options, that classes never close, and poor library support.

As for the business model for vod:pod, Scott said that they could be running ads and they be making $3/month but at this point they don’t want to hamper the users experience. It seems that to the team at vod:pod they aren’t to concern about a business model until they start to scale up.

The second speaker of the night was Matt of My Free Copyright, a copyright registry for digital content. Matt’s talk just listed the ingredients for a typical Ruby on Rails web application. Matt recommended Acts as Authenticated as the first Rails plugin to get your app up and running. Matt also described some of the pros and cons of using the file, database, and memcache session manager. From what I gather, he recommends you start off with SQLSessionStore since memcache has “more moving parts.” Matt closed his discussion of with some background on BackgrounDRb (pun intended). Think of BackgrounDRb as a cron server that allows you to schedule tasks.

Technorati Tags: , , , , , , , , , , , , , , , , , , , , ,


Feb 28 2007

Rails Performance Link Fest

I have read most of the articles out there regarding Rails performance. Performance-minded railers list fragment caching, normalize database design, proper use of indices, and the exclusion of unnecessary columns from large tables in active record models as providing a beneficial performance boost for any Rails application. These railers also warn against excessive use of route url recognition and generation, eager loading, and slow application helpers.

The following list is a collection of the best articles, blog posts, presentations and discussions on Rails performance. Feel free to add any site that I might have missed in the comments!

Rails Performance Tips
Common Performance Problems in Rails – Pros and con between SQLSessionStore and MemChacheStore session containers, tips on optimizing queries, and general information regarding how to avoid slow helpers.
The Adventures of Scaling: Stage 1, Stage 2, Stage 3, Stage 4 – A detailed explanation a Rails production architecture.
Optimizing Rails Resource Usage – A short list of top Rails optimization tips, which include the proper use of caching.
Sustainable Performance with Ruby on Rails – A 58 page PDF presentation describing railsbench, caching, session performance, and efficient Ruby code.
Rails performance tips – A discussion on eager loading, excluding unnecessary columns, indexing database columns, and caching.
Top 10 Ruby on Rails performance tips – Provides great tips to optimize your ruby code and how to handle finders.
Performance related changes in Rails 1.1 – Discussion of performance enhancements in rails 1.1.
Rails performance and caching, Part 2 – A discussing of Rails performance using caching.
Stefan Kaes – Rails Performance – RubyConf 2006 conference notes on the Rails Performance presentation given by Stefan Kaes.
Stefen Kaes – Optimizing Rails – Another post on the Rails 2006 presentation by Stefan Kaes on Rails Performance.
Rails performance with FastCGI and Apache – A blog post on performance with Apache.
Rails Performance Tool Box – A list of tools that come in handy when optimizing a Ruby on Rails application, which include query analyzer, query trace, and mtop.
Rails Caching Documentation – Documentation for action, page, and fragment caching.
The effect of using Rails fragment caching – Goes over the performance boost of using fragment caching.

Rails Performance Tools
Query Builder Plugin – Bypass the overhead of construct_finder_sql.
QueryTrace Plugin – Helps to identify the location/caller of bad queries.
MySQL Query Analyzer Rails Plugin – Helpful to analyze SQL queries.
Rails Log Analyzer – Reads the Rails log files and exposes potential points of optimization.
Railsbench – “A small collection of ruby and shell scripts which make measuring raw performance of rails apps a snap.”

Technorati Tags: , , , , , , , , , , , , , , ,