Snowblink
OCT 05
19

RubyConf 2005: Part Six

RubyConf 2005

There were two final day workshops featured at RubyConf. Naturally, I wanted to attend both.

  1. Hands-on Rails with DHH
  2. Continuations Demystified with Jim Weirich and Chad Fowler

Although I had originally decided to go to the Continuations workshop, DHH announced that he would be showing the new features in Rails 1.0.

Ruby on Rails

Rails 1.0 addresses several problems with previous releases. We shall have to see how well these actually work when put into practice.

db/schema.rb

Finally, we can specify the DB schema in ruby. No more messing about with DB interfaces. Note it does not cater for foreign keys, only indexes. It does allow constraints to be specified.

ActiveRecord::Schema.define() do
  create_table "comments", :force => true do |t|
    t.column "body", :text
    t.column "heading", :string, :limit => 45, :default => "Moo", :null => false
    t.column "post_id", :integer
    t.column "author_id", :integer
  end

  create_table "posts", :force => true do |t|
    t.column "name", :string, :size => 45, :null => false
  end

  create_table "authors", :force => true do |t|
    t.column "name", :string, :null => false
  end

  create_table, :id => false do |t|
    t.column "post_id", :integer
    t.column "comment_id", :integer
  end

  add_index "posts", "name"
end

There are a couple of rake tasks which allow you to fetch and dump your DB schema from the DB. These are highly destructive.

rake db_schema_dump will fetch the DB schema from the DB and overwrite your db/schema.rb with no warning

rake db_schema_import will overwrite your DB with db/schema.rb and drop all your existing tables and data. This will wipe out your existing data without warning. There is also no transaction support. If your import task fails for any reason, then your DB is in an unknown state. Most likely you no longer have any tables.

Migrations

script/generate migration add_comment_author will create db/migrate/1_add_comment_author.rb

This allows you to set up a series of events to alter your DB (either just data or schema, or both). It is possible to migrate up and down.

class AddCommentAuthor < ActiveRecord::Migration
  def self.up
    add_column :posts, :author_name, :string
    Post.find(:all).each { |post| post.author_name = "X" }
  end

  def self.down
    remove_column :posts, :author_name
  end
end

Rails::Initializer

Whenever a new version of Rails was released, our scripts, environment.rb, etc. of existing applications were not updated. This is being addressed by Rails::Initializer. Now most files which are generated by Rails are stubs pointing into the gems.

script/* are now calling the gems eg.

script/server

#!/usr/bin/ruby1.8
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/server'

environment.rb has been reconfigured: (after removing the comments, it looks like this)

require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
end

boot.rb is a bootstrapper to set load paths.

Session storage in the DB is now improved. Intended to be used with first setting up the rails project. Add a configuration option to environment.rb:

  # Use the database for sessions instead of the file system
  # (create the session table with 'rake create_sessions_table')
  config.action_controller.session_store = :active_record_store

then run rake create_sessions_table

DHH points out that all this is, is a nicer interface to older calls. So all existing environment.rbs should still work. We'll see how abackwardly compatible it actually is.

Rake

The Rakefile has been cut down and modularized. You can add new tasks to lib/tasks

Improved FCGI support

Inside script/process there are three hopefully useful files.

  • spawner - this will spawn your FCGI processes
  • reaper - this will reload, restart, kill you FCGI processes
  • spinner - this will continually call spawner. Not intended for use unless necessary.

haproxy can be used to trick Apache into thinking there is only one fcgi process.

SwitchTower

switchtower --apply-to myrails_app will create the files:

  • config/deploy.rb
  • lib/tasks/switchtower.rake

This allows you to write any release things into switchtower.rake eg. hooks into reaper or migration. See manuals.rubyonrails.com for more details

Plugins

Plugins allow you to extend Rails. For example, to add acts_as_something to your AR objects, you would create the directory: /vendor/plugins/acts_as_something/lib

  • init.rb - is called in environment.rb
  • acts_as_taggable.rb - contains your class

Prototype 1.4 and Scriptaculous 1.5

Ajax has been improved to allow you to access Ruby objects in Javascript.

Binding Gems and Edge

In previous versions of Rails, we could use any set of gems by explicitly requiring them. Now that the scripts are stubs pointing at the gems, there is a new mechanism to set the rails version you want to use.

rake freeze_gems This will copy the current rails gems into vendor/

rake unfreeze_rails This will remove the gems from vendor/

rake freeze_edge This will pull the latest SVN Edge Rails in to vendor/.

Per-action Session Management

Sessions are accessed whenever someone access the site, whether or not it is necessary. If you are using DB sessions, then there is additional unnecessary overhead. Now we can specify actions which do not need to access sessions information.

class WeblogController < ApplicationController
  session :off # no sessions added for any actions
  session :off, :only => :feed # sessions off for feed

end

DHH announced that Rails Core would be releasing the release candidate on Sunday afternoon. I believe it is now available as 0.14.0.

Tagged As

OCT 05
17

RubyConf 2005: Part Five

RubyConf 2005

The final day of a great conference was full of Rails for me.

State of Rails

DHH gave an update of what happened since he presented Rails at RubyConf 2004. Most of us know about this already, especially since some of us are actually doing it for a living now.

Rails 1.0 is close, and DHH was going to release an RC this afternoon. He also spoke about new tools:

SwitchTower - this is already out and allows you to manage deployment of your application to multiple machines.

Gauge - monitor in real-time a distributed Rails application.

Conductor - tools to make development easier. The example DHH gave was to have a web interface with a CocoaMySQL-like interface for dealing with fixtures in Active Record. Naked Objects was mentioned in relation to making scaffolding more permanent.

DHH also spoke of creating an industry around Rails. Textdrive and Robot Co-op were cited as leading examples. Also talk of a RailsConf in future.

Rails: Serving the Long Tail in 1883 and 2005

Nathaniel Talbott gave a motivating talk about where most of us are in the industry. Chris Anderson's Long Tail featured prominently. Most of us are working in the Long Tail.

What this means is that our field is small on sales, but highly specialised. Our work comes from small companies, businesses, or individuals who want some web applications built for them. Using Rails we can produce these applications faster and for less money.

Nathaniel predicted that we will see some form of Rails for producing desktop applications.

I think that Rails may well be suited for such a situation now. Starting an application could easily just start up webrick, and kick off the default browser to hit it.

Continuous Integration with Damage Control

Aslak Hellesoy's presentation was sadly hindered by lack of preparation and just bad luck.

I believe the system he was attempting to demonstrate was actually quite useful. Damage Control will run an application fully within RAM. This allows safe testing of applications.

DC is capable of integrating with SVN and CVS repositories as well as tracking systems such as Jira and Trac. It follows the principles of CI and will feature any commits performed whilst it is running.

Tagged As

OCT 05
16

RubyConf 2005: Part Four

RubyConf 2005

The second day (it seems like I've been here longer) of the conference was very busy.

Refactoring No Clergy

Two to five musicians play music given by a score on a web browser. The audience also has web browsers and can suggest what they would like to hear in the piece. Using Markovian Transformations, the next page is generated for the musicians to play.

Kevin Baird sadly did not have any samples of the music generated from this, but will hopefully put some up soon.

Embedding Ruby into a Robotic Marine Laboratory

MBARI is using Ruby to control their marine laboratory (a 5' cylinder). The original aim of the project was to identify harmful algae blooms. They do this by analysing chemical reactions against samples of water. The lab has to stay in position for 6 months at a time, so power is a concern too.

Brent Roman talked about how they were originally using a language they created themselves, but switched over to ruby as more probes (analysis of specific organisms) were needed. Ruby was chosen as non-programmers (scientists) would be the ones writing probes.

As the hardware is unique, Brent wrote a system similar to mocks to allow him to continue to develop the system without the laboratory being there. Ruby 1.6.8 stripped of many standard libraries was put on to a 16MB flash card, which controls everything from servos to the probes. 2MB Linux kernel, 500kB Ruby Core, 1.6MB Native code libraries.

Apparently NASA are also interested in this technology too.

PDF::Writer

Austin Ziegler presented PDF::Writer. Basically it allows you to generate PDF documents specified in Ruby. It can already import bitmapped graphics, and vector graphics are being put into version 1.2.

Austin was showing us where he wanted the project to go. The tidying up of how you specify what goes into your PDF. Perhaps he will be influenced by Jim's DSL talk.

Polishing Ruby: Power Tools and Toys

Ryan Davis gave a very slick presentation of various tools which came out of MetaRuby.

ZenTest looks like something most people would want to use. It generates missing tests from existing classes. It also includes a diff tool which makes it easier to locate problem code.

RubyInLine allows you to write C functions directly in your Ruby code. Thre is no need to compile anything, and technically you are not limited to C.

ParseTree extracts the Ruby AST and returns a sexp (s-expression). It also allows visualization of your AST which can give you better understanding of your code.

Ruby2C transforms your Ruby into C. This can be used to help optimize, or to obfuscate.

Zen Hacks is a miscellaneous collection of tools. Most make the author wince. These include ruby2ruby, auto refactoring, ruby obfuscator, zenprofile, and zenoptimize.

Creating Domain Specific Languages in Ruby

Jim Weirich started off showing siteswap notation, followed by Rubik's cude solving notation, and finally guitar TABlature. All these were examples of DSLs (Domain Specific Languages). He then proceeded to show that DSL are designed for non-programmers who understand their domain space.

There are various types of DSL: External: Awk, Sed, Yacc Work Bench: PowerTools Embedded: A subset of an existing language to create the DSL

Jim's experience is from creating Rake. He started out by scribbling down how he saw the DSL working. James Britt's method was mentioned: Write by exception - write it how you want to, then hack it until it is Ruby.

Using methodmissing, constmissing, hooks into method_added it is possible to create your DSL. A key part is using BlankState which will remove all unnecessary Object methods. Perhaps this will become part of RubyCore.

I am quite keen on getting a list together of DSLs specified in Ruby.

System Testing in Ruby with Systir

Karlin Fox started off showing a test which went through and filled out web forms using Watir. Systir suggests story driven development. Your user will write their own tests in a DSL you specify with them.

I like the look of this, but am skeptical about the likelihood of a client writing their own tests. I can see them writing specification type tests which allow you to see if your application gives them what they requested, but I don't see clients writing tests for failing conditions.

Other things on the Radar

Mike Clark's learning tests - I found this interesting and actually did it with ActiveRecord without realising it. One colleague wondered why I had written tests which just confirmed ActiveRecord was working. Part of writing the tests showed me how certain things worked, so I think was worth it.

Selenium is similiar to Watir, except that it doesn't rely on IE. It will run on Linux and MacOSX.

Komodo is an ActiveState product which is now has alpha Ruby support. I happened to sit next to Eric Promislow who showed me how it worked. The Ruby debugger is built in, and allows you to set breakpoints. I liked it and will be giving it a more thorough test. One thing I forgot to ask was whether it has vim keybindings.

Tagged As

OCT 05
15

RubyConf 2005: Part Three

RubyConf 2005

Last night, Matz answered many Roundtable questions with his trademark deadpan wit. It is easy to see how Ruby has the elegance of its creator. Here are some of the questions I found interesting or amusing.

  • What languages would you look at now?
  • io and Haskell.
  • What language would your children learn first?
  • Japanese.
  • Have you looked at Rails and what did you think?
  • I have watched the video... and I liked it!
  • What editor do you use?
  • Emacs.

After that I went out for dinner with some Rubyists. Dinner talk was about the virtues of peer programming, ping pong development, and explanations continuations.

I think I saw a why last night. He was covered in foxes and much taller than I had imagined. Obviously he denied being himself when I asked him.

Tagged As

OCT 05
15

RubyConf 2005: Part Two

RubyConf 2005

The first day's panels are over. It was very cosy. The wireless network had some problems dealing with the 200 people trying to connect with laptops. There was a dangerous number of gang plugs daisy chained to power them all too.

Top-to-bottom Testing in Ruby

Francis Hwang presented Top-to-bottom Testing in Ruby to replace Lucas Carlson's talk. The talk centered around mocking. For example, databases or mail services. This allows you to run tests against mock systems all running in memory. The benefits are speed, no side effects, and no cleanup. The downsides are possible bugs in the mock objects, time spent building mocks, and indirection (eg. not using SQL where it may be obvious to).

DHH suggested changing the LOAD_PATH to load the mock objects first. Someone else suggested that perhaps the Library writers are best placed to also write mock objects.

  • Lafcadio is used to simulate a MySQL DB.
  • MockFS allows you to simulate a file system. Although there are systems which allow you to run applications sandboxed, there are things like what happens when you run out of inodes which MockFS may be more suited for.
  • Examples from the talk

open-uri

Akira Tanaka presented his library, comparing it Net::HTTP. open-uri certainly compared favourably to Net::HTTP, especially in it's simplicity. Akira went on to explain what he saw as key features of good APIs. Huffman coding applied to method names was quite interesting: The more frequently used methods should have shorter names, and rarer methods should have longer names.

JRuby

After lunch, Charles Nutter told us about JRuby - a Ruby VM written in Java. It allows you access to all the Java libraries, whilst still writing Ruby. The new JRuby is aiming at being stackless, by using continuation passing style. Also an iterative, as opposed to recursive, interpreter.

YARV

Yet Another RubyVM was presented by Koichi Sasada. YARV is hoping to be the VM in Ruby 2.0, but that's up to Matz to decide. Why do we need a VM? The Ruby interpreter does not currently use VM techniques, so is slower. We were shown performances against various algorithms. Particularly impressive was the performance gain when running the Ackermann function.

MetaRuby

Eric Hodel presented MetaRuby. That's Ruby written in Ruby. Or at least as much as possible that can be written in Ruby. Everything else that's left is called a primitive and may have to be implemented in C. The aim of the project is to eliminate as much C as possible.

All the projects showed interest in each other. Each project building on one another. This is certainly a good sign for the community.

Tonight is the roundtable with Matz. I'm going to have a nap now as I'd like to be a little fresher for that.

Tagged As

OCT 05
14

RubyConf 2005: Part One

RubyConf 2005

After a gruelling 20 hour journey I made it to the hotel in San Diego for RubyConf 2005.

The fun started with the Northern Line being completely shut down. Hilarity ensued with vegetarian meals being not specified by the travel agent. Of course the extra hour sitting like veal at the gate at Newark waiting for ice to be loaded was just what I needed.

However, I eventually arrived and checked in. From the trio sat on the sofa (iBook, Powerbook, Powerbook) I figured I was in the right place.

Nearby was a group standing and chatting. I spotted Jim Weirich quite easily. I think James Britt was there too, but I was somewhat star struck as Matz introduced himself. He is much younger than I thought. The conference agenda is full of goodies.

Panels I'm keen on:

Of course, Matz's roundtable and keynote speech, along with DHH's Rails workshop will be of great interest too.

Seeing as it's 4am now and I think it's lunchtime, I think I'll go download Ruby Classifier in preparation for Lucas Carlson's Advanced Classification in Ruby and Rails.

Tagged As

OCT 05
07

Serenity

Serenity

Venue: UGC Shaftesbury Avenue

The show began with River's escape, and an introduction to the Mal's nemesis: The Operative. Then we have a long take (at least a 5 minute continuous shot), introducing us to the crew and all around Serenity herself. I was impressed.

River is the central focus, as you may have guessed from all the adverts showing how bendy she is. She leads the group into a very revealing journey, which I won't go into here. Just remember how she took out those guards that time without looking.

I wonder if those TV execs are kicking themselves right now. Hopefully, they don't work in the industry again. Firefly was a fantastic show with very real characters and inventive plot. Then it got cancelled by FOX. Idiots.

Hopefully, a more sensible company will help Wheadon bring it back to the small screen. After seeing Serenity, I have no doubt that they will be tripping over themselves to get it.

Tagged As

OCT 05
04

Howl's Moving Castle

Howl's Moving Castle

Venue: Curzon Soho (Japanese version)

Miyazaki is back with a new offering. Thank goodness Disney hasn't soured his talent.

Sophie is a hat maker who is drawn into the world of wizards and witches after encountering Howl. You see, he has this moving castle, and that always gets the girls. Anyway, the Witch of the Waste pays her a visit and turns her into an old woman. So Sophie sets out to try and break the spell. On the way she meets a scarecrow...

Wizards? The Witch of the Waste? A Scarecrow? Isn't this just the Wizard of Oz? Although there are echoes of Dorothy's adventures, this is very much a Miyazaki style story. The animation is of course gorgeous, with no sign of a computer generated image - hooray!

There is much more to this story and many more characters, but I don't want to spoil it. This is another gem from Studio Ghibli. Don't miss it!

BTW Who doesn't want a magic door after seeing this?

Tagged As