CrudVision - Lisa Seelye

September 28, 2007

Some “Other Blog” hilarity

Filed under: critique, php, rails, replies to posts, ruby — Lisa Seelye @ 1:47 am

It seems that a blog post was made by a guy named Jeremy Sivers to pimp his E-comerce site (Sorry, no google juice for you).

In the thinly veiled blog entry-come-advertisement Jeremy uses Rails and Ruby as a punching bag (up against PHP) to drive people to his site. (I nearly said “poorly designed” but my sites aren’t works of art either. Hey man, I’m no artist either!)

The many dozens of pages of comments are filled with many people backing up Rails and PHP while completely missing the point: Jeremy wants to use O’Reilly’s blogs as a means to advertise his poor coding and (his company’s) project management skills as well as to advertise.

His post can be summed up as follows:

Visit my site! Two years ago I decided to try and rewrite my site’s codebase with Rails while not bothering to leverage migrations (or to otherwise change the legacy schema to a rails-friendly schema). I suck at programming and project management and exadurate a lot so after wasting two years of time and money I decided to spend two months to code the site from scratch in PHP!

What I want to know is why didn’t he just use the existing codebase from the start? Was it broken? Was there some other Ruby/Rails standardisation in progress that required the E-commerce side to change then?

In any event: Don’t rewrite anything unless it doesn’t work. Use Rails’s conventions - they’re better than yours. Don’t worry about scaling, yet.

Incidentally my personal site is still backed with PHP because there’s no compelling reason to waste time rewriting it.

September 23, 2007

Random Snippet: Soundex

Filed under: C, ruby, snippet — Lisa Seelye @ 4:17 pm

This bit of code is the Soundex algorithm based on some C written by a friend of mine (Hi Jen!). She writes really compact C (read: hard to read) and it took me a long time to understand what the code she wrote did.

So here is the annotated version of the code (correlates to the Rule numbers on Wikipedia).

RUBY:
  1. class String
  2.   @@sem = [ 0,1,2,3,0,1,2,0,0,2,2,4,5,5,0,1,2,6,2,3,0,1,0,2,0,2 ] # Letter codes, Rule 3
  3.  
  4.   def to_soundex
  5.     s = self.upcase
  6.     chars = s[1 .. s.size - 1].split(//) # Split the word into characters to encode
  7.     ret = s[0,1] # Rule 1
  8.     chars.each_index do |i|
  9.       c = chars[i]
  10.       next if ( c <'A' or c> 'Z' ) # Not a letter
  11.       next if i>0 and c == chars[i - 1] # Rule 4
  12.       d = @@sem[ c[0] - 'A'[0] ] # Encode it
  13.       ret += d.to_s unless d == 0 # Rule 2
  14.     end
  15.     ret += "0000" # Rule 5
  16.     ret[0..3] # Rule 5
  17.   end
  18. end

It was fun to write and it works well.

September 19, 2007

The Final Day of RailsConfEurope07

Filed under: RailsConfEurope, RailsConfEurope07, germany, railsconf, selenium, testing, watir — Lisa Seelye @ 10:32 pm

This was the final day.

Cyndi Mitchell's talk about "Bringing Ruby to the Enterprise" was innovative (Wish I could get a copy of her slides!) and really good. I reckon she could have talked for longer.

The "best practices" lecture afterwards (Michael "Koz" Koziarski and Marcel Molina Jr.) was less impressive. It seemed to advocate refactoring an entire application into a completely bottom-up approach. Most of the (contrived) examples were bad ones and readability was not helped at all by the code changes. It's in everyone's best interests to develop their own sense of "best practice" and stick to it. Be ready to re-evaluate and update code if a new technique comes along.

The pair advocated controllers with no more than 7 actions of 7 lines each. It is not a bad thing to have many lines of code in your controller if it's relevant to the action. Having a switch statement to handle various cases of input (especially for polymorphic models) is good. It doesn't help to have a Car controller, a FourWheeledCar controller, a ThreeWheelCar controller, a DiselFourWheelCar controller and so on. They all subclass Car and they should all be in the common controller. When lines should be trimmed is when the same programmatic steps are being repeated: special formatting of return data, emptying a shopping cart (when there is more than one way to empty the cart!) and so on.

I also abstract controller code into libraries when there's a task that I need to do over and over in the console to help other guys on my devteam do their job. This also helps with creating modular application code for multiple clients.

The bottom line is: Who cares as long as everything is tested to meaning, you can understand your code and it won't take someone else who has to maintain the code a month to figure out what it does.

Okay lecture guys, but most if it seemed to be creating work for work's sake, especially the proxy class...

Unfortunately the Ruby on Rails Security lecture by Heiko Webers was...dull. The material Heiko covered seemed to be basic web security. Perhaps it was meant for newcomers?

After that things got interesting. Selenium and Watir!

Selenium was up first in Browser-based Testing by Till Vollmer. This is a REALLY cool utility and I'm sure we'll (at work) take a good hard look at it and see if it meets our needs. In any event it's cool technology nontheless. Kind of like integration testing on steroids. Very cool.

Afterwards Continuous Validation by Dane Avilla was up. His lecture touched on the same topic as Till's but it was from another approach angle: validating HTML, CSS, JavaScript and using a distributed technique to remote control browsers (with Watir) to click through a form. I imagine this could be as complex as Till's demo with a little work. How cool is it to have a farm of all browsers set up to be run after every commit through rake test and report any failures in tests across browsers!

After the Watir one I called it a day.

Railsconf has been very interesting this year. It's been my first time and I may come back, perhaps for the American version, though since Germany is a little intimidating for someone who speaks no German! But we'll see what next September has in store.

September 18, 2007

Scaling Multilingual Cached Ferrets

Filed under: RailsConfEurope, RailsConfEurope07, capistrano, ruby, work — Lisa Seelye @ 11:06 pm

Clever title, eh?

Anywho... today was DHH's Keynote and a few other lectures that I was interested in. They included the Caching in a Multilanguage Environment by Benjamin Krause (of omdb.org), Rails Full Text Search with Ferret by Jens Kräuse and Really Scaling Rails by the Twitter guy(s).

Benjamin's multilanguage lecture consisted of introducing a couple plugins that altered Rails behaviour to enable (wait for it) multilanguage caching. The plugins (whose names I cleverly have forgotten but can likely be found somewhere on OMDB's trac, perhaps mlr.) were basic things. Change ActionController to handle ACCEPT_LANGUAGE and Routes to tack on a :lang fragment as in :id.:format.:lang (/people/1.html.en) to match Apache's mod_negotiation.

The plugins also provide test methods. All in all the lecture wasn't real revolutionary (to echo DHH's sentiment about how Rails should now move). Caching content based on a language. Of course! It makes perfect sense and is something many developers (especially in Europe?) would be interested in.

The next lecture was the Ferret lecture. At work we're really interested in using something like Ferret to offload some work from the database. One of our client's sites has already been bitten by DB load (see the Beast SQL Speedup) and have expressed an interest in having fulltext search with boolean operations. I'm very glad I sat in on this as it's something I've been wanting to do with evedb.info.

Jens's lecture was really cool. I admit to being naive when it comes to Ferret (really I mean acts_as_ferret): I know it can be used for searching but how to leverage its full power is (or was?) beyond me. Today was the first real taste of how to use it and it was like getting my head around REST and realising how useful it WILL be.

Finally the last lecture I attended today was the Really Scaling Rails by one of the Twitter guys. This was a cool lecture since Twitter is really what everyone using Rails hopes to achieve. And on an extremely limited way we (at work) have had to deal with these rapid scaling problems. We've had a client on the phone wondering why the forums took 12 seconds to load (if it did load) and why one browsing part of the site took 5 seconds per page. Quick fixes (For those two instances less than a day's work) and it keeps the client happy (and me! I like finding these solutions even if I end up cursing MySQL in the process).

The scaling lecture could be best summed up by: Don't optimise prematurely with a corollary stating "But be ready to optimise on a moment's notice." I agree.

The Keynote

Filed under: REST, RailsConfEurope, RailsConfEurope07 — Lisa Seelye @ 12:47 pm

Last night I missed Dave Thomas's keynote but I did catch DHH's keynote this morning. It was interesting. He spent most of the talk going over Rails 2.0 new things, encouraging people to use REST (tacitly, as the demo was all RESTful).

DHH contrasted the differences from Rails of three years ago with Rails 2.0 and the differences were amazing. I don't think I could have stuck it out if I had joined the game at that point. Unpacking a tarball, no migrations... yeesh! Glad I got into Rails 18 months ago when Rails was more mature.

DHH's talk may not have been as informative as the 2006 one (about REST) but it was interesting anyways. Rails 2.0 tech preview will be either soon or next week! I'm excited for it.

September 17, 2007

Flex Tutorial

Filed under: RailsConfEurope, RailsConfEurope07, flex — Lisa Seelye @ 7:00 pm

First thing: The tutorial was certainly geared for people with an interest in Flash or Flex.

The Rails side was minimal at best: "Here's some rails source, get it running then open Flex Builder". Okay, no problem. Managed to get the project converted to Postgres (the DBRMS I have on my Mac) and played with the scaffolded HTML interface.

I kept getting NullPointerExceptions when I attempted the most basic tasks within the Flex Builder IDE. After a while I gave up and realised that it was only Flex markup (I hesitate to call Flex code since it appears to be mostly XML markup!) being written. I have no interest in Flex or being a Flex developer. I'm happy with Ruby and Rails. I came to the tutorial hoping to get some inight into integration problems we've had at work. Unfortunately that didn't happen except for at the very end (and our project is far beyond the point where we could have implemented it).

I suppose the lecture wasn't bad for people who came into it with different expectations. I just expected something other than what it was.

Refactoring Rails

Filed under: RailsConfEurope, RailsConfEurope07, rails, testing — Lisa Seelye @ 11:44 am

I must say that Trotter Cashion's presentation on refactoring wasn't totally new material. At work we have at least one project that desperately needs some refactor/rewrite love. I'm hoping to convince bossmen that it's a good idea to rework its source. ;)

One of the things he mentioned is that not refactoring is like accruing debt. It made sense immediately. I've said before that it's easier and more fun to work with a codebase that is well written and easy to read. Not refactoring (or rewriting when necessary) is the way to not give yourself a good codebase. No one can, from the start, architect the perfect application, code, or methods. Cruft begins to collect when the coder is under time constraints and begins to hinder work because cruft on top of cruft means a lot of searching to find out what the code is doing before anything can be done!

The next session is the "Flex on Rails" tutorial and that should be painful and evil.

September 16, 2007

In Berlin

Filed under: RailsConfEurope, RailsConfEurope07, travel — Lisa Seelye @ 10:37 pm

I made it to Berlin. The trip was mostly uneventful except the train from LHR to TXL was delayed. The information desk at the Berlin-Tegel airport directed me to the desk next to him ("How do I get to Friedrichstrasse?") and that desk directed me outside to bus stand 2. The directions on O'Reilly's website for the hotel said:

From Tegel Airport (10 km): Take the shuttle bus to Friedrichstrasse Station, located across the street from the hotel.

The stop I got off at, Friedrichstrasse, was not across the street. Doh! A kind German man directed me away from the hotel until we got to a street sign that indicated the hotel was in the other direction. He was nice and I found the hotel!

The hotel is nice but the internet connection in the rooms is madness! €10/day!

I met a Gentoo colleague for dinner (He's also attending railsconf) to see a friendly face. I was paniccing earlier since I don't speak German and was homesick and, and, and... I'm okay now. ;-)

When I met him in the hotel lobby there was a group of congoers having a nice chat and they were still there when we got back past 23:00. We/I didn't join in since I'm tired, I've had a long day travelling and I want to settle in for a good night's sleep before the giant frenzy that's coming.

Registration begins at 07:00 and the first tutorial session begins a 08:30. As I type this the time is currently 23:35 - I seem to still be on UK time as I'm not very sleepy. I'll have a lay down and see if I fall asleep.

September 13, 2007

Getting ready for RailsConf Europe 2007

Filed under: RailsConfEurope, RailsConfEurope07 — Lisa Seelye @ 9:17 pm

Excuse the obnoxious tags (what's wrong with my 'railsconf' tag?) but in the nice newsletter I got they said to use these ones. Oh well. I do as I'm told.

Railsconf is just around the corner. I'm just getting myself ready to go. Tomorrow is my last day at work until October 1 so I'll have next week to take in Railsconf and a visit to friend in Canada (and recover from jet lag) before having to be back at work.

I've got my macbook all ready for my holiday: It's got rails project on it, postgresql installed, textmate, data for my project, source for Reve and other useful things.

Saturday will be last minute shopping and packing of suitcase and Sunday will be transit day!

I'm planning to attend all three days of Railsconf (giving Bratwurst on Rails a miss due to scheduling and the fact that I don't drink alcohol). I will attend the refactoring tutorial session as well as the Flex and Rails session.

It'll be interesting to see how they (Aslak Hellesøy and Børre Wessel) accomplish Flex integration. I can't wait to see how they deal with HTTPService's inherent stupidity and failure to comprehend HTTP Status codes. WebORB integration should be interesting.

September 9, 2007

Yielding to Subversion

Filed under: subversion — Lisa Seelye @ 9:22 am

I failed in my svn migration. I kept getting checksum mismatches. Oh well.

I've admitted defeat and decided to just create a fresh blank repository and svn import my code.

Let this be a lesson: Use a proper SVN repository from the start and headaches will be avoided!

Older Posts »

Powered by WordPress