Archive for December, 2007

The Art of Self-deprecation

In which Reg, with a single quote, deprecates himself quite soundly despite a massive opus of fascinating blog posts as evidence to the contrary.

In the past year I’ve managed to formulate some ad-hoc rules through which I determine the programming-related blogs I read:

  1. Anything Rails-related. (I’ve only been using Ruby and Rails for a year so anyone with something to say on the subject is interesting to me, at least until I start to formulate my own opinions… well, my own postable opinions)
  2. Posts by Reg. ’nuff said
  3. Blogs by people who comment on Reg’s posts to whom Reg extends thanks for their comments indicating that they gave him food for thought

Oh, and of course Joel on Software, if for no other reason that I can say I do when at the industry parties with everyone else (seriously though, love him or hate him he really is mandatory reading). And Stevey because, well, everyone else is a bit stupid by comparison (not that he actually said I could call him Stevey or anything but as he did put it in the title of his blog….)

Comments Off

chris on December 30th 2007 in /dev/random

Ruby 1.9: Not For Rails

Do NOT install or upgrade to Ruby 1.9 if you’re using Ruby for Rails development.

There, that warning ought to suffice.

On Dec. 25 Matz announced that a development release of Ruby 1.9 was available in which the Ruby 1.9 spec has been frozen:

We are happy to announce of the release of the 1.9.0 the development
release.

We hope this helps you to enjoy hacking. Happy Holidays.

matz.

However, Ruby 1.9.0 is not a drop-in replacement for Ruby 1.8.* with more good stuff inside, many fundamentals have changed, often in incompatible ways. As Dave “PickAxe” Thomas notes:

This is a development release, not a production release. It has known bugs, and there’ll be more to come.

It contains several incompatible changes (block parameters are now block-local, String is no longer Enumerable, “cat”[1] now returns “a”, rather than 65)

It is more rigorous that 1.8 when it comes to detecting invalid code. For example, 1.8 accepts /[^\x00-\xa0]/u, while 1.9 complains of invalid multibyte escape

the likes of which are guaranteed to break either Rails, some critical gem, a required plugin or your own code. Honestly, it’s guaranteed.

As example from the Rails list:

just now i installed ruby 1.9 and rails 2.0.2 on it. when i create new rails application

username@ubuntu7.04:~/project$ rails app
can’t convert Enumerable::Enumerator into Array

and

Agreed. I just upgraded to 1.9 and found all my applications totally
hosed. I had to delete 1.9 and reinstall 1.8.6, along with Ruby Gems (on
Leopard).

I’ll be waiting for the official announcement of compatibility on the
Rails blog.

and from Rick DeNatale:

I just answered a post from someone on the TextMate forum who
installed Ruby1.9 as ruby. Now he gets a syntax error inside textmate
when he tries to run a ruby program, since Textmate uses ruby
internally, and some of that code ran into one of the syntax
incompatibilities.

Anyway, you get the idea.

If you really want to play around with Ruby 1.9, perhaps to help with the testing or just to get an idea of what cool stuff will be landing in Ruby 2.0, Dave Thomas’ post, cited above, provides great details in just how to do that.

Congrats to Matz and all the ruby-core team on 1.9.

Update: Should you need even more proof of the current “dev” state of Ruby 1.9.0, a fairly significant string encoding bug was bound found, isolated and fixed just four days after release.

Comments Off

chris on December 30th 2007 in /dev/rails, /dev/ruby

IE8 on Acid

It’s always been easy in the past to blast Internet Explorer for being, quite honestly, the least standards-compliant browser in popular use. But perhaps today that all changes. The IE8 team have announced that their browser now passes the Acid2 test (see here for test details).

Congrats to the folks who’ve worked to get IE to this point! It is no small feat and praise-worthy indeed.

Comments Off

chris on December 20th 2007 in /dev/random

Flog Your Code

Just came across Flog, a fun profiling tool that weighs your functions and assigns scores. The higher the score the (likely) more complex the function is.

Or, as the Ruby Sadist puts it:

Flog shows you the most torturous code you wrote. The more painful the code, the higher the score.

I’m amused and somewhat pleased to see that on my newest Rails project this distinction still falls to an external library, namely acts_as_authenticated, the sort of result I’d expect to see on most Rails projects.

AuthenticatedSystem#get_auth_data: (25.9)
6.4: []
4.8: branch
3.8: assignment
3.8: request
3.4: env
2.8: split
1.7: decode64
1.5: to_s
1.3: ==
1.3: has_key?
1.2: blank?
1.2: detect
0.5: lit_fixnum
AuthenticatedSystem#login_from_cookie: (21.1)
5.4: assignment
4.8: branch
4.5: cookies
3.2: current_user
2.7: []
1.4: remember_me
1.4: remember_token
1.4: remember_token_expires_at
1.4: flash
1.3: remember_token?
1.3: logged_in?
1.2: find_by_remember_token
AuthenticatedTestHelper#authorize_as: (14.5)
3.0: content_type
3.0: accept
3.0: assignment
3.0: env
1.9: users
1.7: login
1.5: encode64
1.3: branch

I suspect it’d be more interesting and enlightening to run this against a stand-alone Ruby app instead. Alas I do not yet have any that are more than a couple classes and a few functions in length, not worth the effort.

Comments Off

chris on December 17th 2007 in /dev/random

Jump-start on Rails 2.0: Rails2 PeepCode

Ruby on Rails 2.0 was released on Dec 6, 2007 and fortunately for me I had the luck of starting a brand new Rails project on Dec 9. A brand new slate on which to try out all the new Rails toys.

Invaluable in this has been Ryan Daigle’s Rails2 PDF, a well-written compendium of what’s new, what’s changed and examples thereof. It also contains the complete Rails changelog, which seemed silly to me at first glance but has since been surprisingly useful as a desktop, keyboard-side reference in its own right.

Admittedly all the information contained within can probably be found on the web and piece-meal if you manage to read all the major Rails blogs each day but for $9 having it summarized like this has made it well worth the price as a bridging document until the Rails 2.0 books start to appear.

Comments Off

chris on December 13th 2007 in /dev/rails

Google Chart API Wrappers

Google released their Google Chart API and spawned a flurry of activity culminating in wrappers for these languages:

Please note: as the day grows long chances are more and more of these will spring up like beautiful flowers after a desert rainstorm (I expect at least half a dozen for PHP by Jan 1). This list is just the first one’s I’ve found for each language, not necessarily the best implementation. As always when dealing with a new technology, pace yourself and exercise abundant google-fu.

Update: And a tutorial on how to use the Google Chart API from within Cocoa: Google Chart API Fun with Cocoa and F-Script. I assume this is an academic exercise since sane OS X developers would probably use something like GraphX and skip the HTTP round-trips.

Speaking of which, hey Apple: whatever happened to opening up the GraphKit/Graphite framework?

2 Comments »

chris on December 11th 2007 in /dev/random

Rails Functionality Into Plugins

With the release of Rails 2.0 quite a bit of core functionality has been pushed out into plugins, presumably to lighten the core and allow for these plugins to take development paths and release schedules independent of that of Rails itself.

I just ran head-first into this while trying to use in_place_edit_for which generated this error:

undefined method `in_place_edit_for’ for FaqQuestionController:Class

The docs don’t make it immediately obvious (or rather, they’re completely obtuse) about which plugin the functionality has been moved to. Fortunately one can figure this out for one’s self via the Svn repository:

· CHANGELOG
· account_location/
· acts_as_list/
· acts_as_nested_set/
· acts_as_tree/
· atom_feed_helper/
· auto_complete/
· continuous_builder/
· deadlock_retry/
· exception_notification/
· http_authentication/
· in_place_editing/
· javascript_test/
· legacy/
· localization/
· open_id_authentication/
· scaffolding/
· scriptaculous_slider/
· ssl_requirement/
· token_generator/
· tzinfo_timezone/
· tztime/
· upload_progress/

(Thanks to Ryan Bigg via the rubyonrails-talk list.)

1 Comment »

chris on December 10th 2007 in /dev/rails

Don’t Preface Partials With Numbers

I just learned today that it’s a bad idea to name your Rails partials starting with a number, ie: _4_happy_places.html.erb. Turns out Rails throws the following error if you do:

`@4_happy_places’ is not allowed as an instance variable name

This has been tested against Rails 2.0.1.

Comments Off

chris on December 9th 2007 in /dev/rails