Sep 29

Ruby append (<<) versus concat (+)

Ruby, Tech 12 Comments »

A lot of developers know the dangers of concatenation with Strings and objects. In Java we had the StringBuffer.append vs. + (and now StringBuilder) knowledge transfer.

Ruby has the same issue, and people have talked about it before.

We ran into this issue in one of our projects, and I remember Dave Thomas talk about a problem that was fixed by moving from string concatenation to putting the contents on an array.

I think this benchmark says it all:

require 'benchmark' do |x| do
a = 'foo'
100000.times { a += ' foo' }
end do
a = 'foo'
100000.times { a << ' foo' }


dion@stewart [~]$ ruby t.rb
user     system      total        real
13.790000  25.180000  38.970000 ( 40.102451)
0.060000   0.000000   0.060000 (  0.064342)

So, favour << unless you really want to copy strings around.

Sep 28

-1 on +1

Tech 6 Comments »

Ah the good old “+1″ that started in the world of open source.

If someone asks for a vote and you reply with +1, fair enough.

These days I see random emails with people replying JUST SAYING “+1″.

Ah, what great value add.

Do you think that you are so important that just knowing that you like/dislike something is important in itself?

Conclusion: -1 +1

Sep 28

False Sense of Security: Car Sensors

Personal 2 Comments »

Progress. You back up the car and it beeps if anything is close. It can sound annoying, but hopefully it stops people running over people behind them.

The problem is that it gives you a false sense of security. I now know a handful of people who have all done the same thing:

Whenever I reverse out of my garage, the car beeps as it is close to the side of the garage. Yesterday, when I reversed out, it beeped, and then I hit a car that was parked behind me.

I need to keep reminding myself to not assume what the beeping is in reference too, else I will get into trouble too :)

Sep 28

Planning for size in your web application

Tech 3 Comments »

In the fun application that I have been talking about, we keep running into issues like the slow tree. They all come down to one thing. Noone thought about success, and how it would handle size.

When you are running on a dev machine and have 3 test users, it may make sense to have one “Users” tab that has on it:

  • list all users
  • list all special users
  • add user form at the bottom

However, when you get popular and have a million registered users or so, this page becomes REAL slow, and what if you just wanted to add a damn user!!!

Obviously, we went in on the new system and have ‘add user’ as a separate action, and instead of listing all of the users admins go in and search for what they need.

Sep 22

Being Small Enough To Care

Tech 1 Comment »

I am having a great time in startup-ville (that’s french). One of the reasons that I like it is that I have always found that when you are small you get to do the personal things, and make users think that they care.

We are small enough that we actually do things like:

  • Answer emails speedily, and personally
  • Listen to each email, normally fix the problem, and reply promptly
  • Even watch bounces from our email system and try to work out the problem. If a spam filter got in the way, we send another email saying “Hey, the contents that you asked for got filtered, so here is the URL”

This all really connects you to your users, and then you can *gasp* actually learn from them. Imagine that.

This is kind of strange in a way, since larger companies could afford to have an entire division to help users, but they just do not seem too.

I am not looking forward to getting so big that individuals suddenly migrate from being “core important users” to “just one of a billion, so we can’t go with them. You know. 80/20″.

Here’s to the little guy :)

Sep 22

Ferret diverges from Lucene

Java, Ruby, Tech 5 Comments »

I am a long time Lucene fan, and was excited about being able to use Ferret in Ruby land to work on the same files.

That dream just died as David Balmain (Mr. Ferret) has jumped away from the Lucene file format:

This is the first Ferret announcement I’ve put up for a while, the reason being, the most recent releases of Ferret have been alpha releases. I completely rewrote Ferret from the ground up so that it no-longer uses Lucene’s file format and I was able to gain so great performance improvements in the process.

Do I need Ferret to use the same file format? Often-time no, as the app is in pure Rubyland, however, I know of a few projects in which being able to access the index from both worlds is a definite plus….. and not through a web service ;)

I guess we will have to use one of the other lucene ports for that.

Sep 19

Recursion gone wrong OR Too Much SQL

Tech 2 Comments »

One action on the admin side of an application that I am working on was really slow. It would take up to 20 seconds to load.

This action is part of existing legacy software, so again I had to dig in and found the bad performer instantly.

The bad code was building a tree of categories, and worked just fine for tens of categories, or maybe even hundreds, but now the system had THOUSANDS of categories.

As I looked into the code that generated the tree, it didn’t take a genius to work out the issue. The function was recursively calling itself as it got to each node in the tree (now build the subtree, now build its subtree, etc etc).

Recursion itself was not the problem, but each time the function was called it was running a new SQL query against the DB to get subtree information. This meant that many, many queries were running against the DB when one could be used.

By changing the action so that it:

  1. gets all of the category info first
  2. write out the tree using this info
  3. It went subsecond.

    Then we migrated from having it ask for the categories from the DB, to grabbing them from cache, and it became insignificant.

Sep 12

Separate generating content from printing it out

Tech 4 Comments »

I am currently working on a legacy application that has a lot of the following:


show_article() goes out, grabs the article (based on some evil global variables ;) and prints it out as it goes.

This makes it bloody hard to test, and *really* hard to cache. To handle scalability I may want to get that article and save the HTML to disk for use later, or grab the article object and put it in a distributed cache, or ….

The fact that most of the methods in this application do not return strings, but rather just go ahead and print to STDOUT makes life a real nightmare.

This is one of the pros of Velocity vs. JSP. Why can’t we create a JSP engine, setup bindings, execute, and get back a string? Then we could even use JSP outside of the web scope (e.g. to generate emails).

Sep 09

Tennis needs fan shirts

Personal, Sport 3 Comments »

I have been enjoying the US Open, especially Andre’s farewell. His first round match was a lot more enjoyable than the women’s final today!

While talking about the popularity of the sport, I got thinking about how there is no way for people to know that you are a tennis fan.

If someone walked past you wearing a Lacoste t-shirt you probably aren’t thinking “I bet that is an andy roddick / tennis fan!”.

Roger Federer is wearing the bizarre jackets, but I doubt people will start wearing those. Some of the players have unique style, but again, the public are as likely to pick this up as they are to wear clothes from the runway.

What can tennis do to change this? Cricket had the same problem. At one time we all had boring white outfits (at least we had the crests of teams!). Then the marketing machine got in action and with shorter cricket, we started to see countries and counties having their own brands, and players names were put on the back. Then you could get an England outfit with ALMAER on the back to show your pride.

Is there anyway that tennis could do the same? Hmm.

Also, the players could become more NASCAR-esque:



… just think of the money they are leaving on the table.

Sep 08

Nursery rhythms are all diferent in the US compared to the UK

Personal 5 Comments »

This is a friday post :) I had the pleasure of taking my son to swim lessons for the first time today.

At the event I was surrounded by Mom’s and kids, and since this is a baby lesson, we had to sing and play in the water.

Not only do I not know all of the songs used, those that I did find inthe back of my mind had different lyrics.


Hokey Pokey vs. Hokey Cokey (and we shake it around a lot more in england!)

Noble Duke of York vs. Grand Old Duke of York (come on, surely we are right on this one).

It was so fun to swim around with Sam though. I used to think “ah those poor parents having to do X when they want to go out partying”. Now I know that most of the time you would RATHER be playing with you kids than anything else!