Archive for September, 2008

find_or_create_by_<nnn>: think twice. before you race
The usually recommended way to create an item if it doesn’t exist already is by using
find_or_create_by… This, however, comes with a race condition built in. Which doesn’t always race,
so think twice when and how you use it.
This code, for example, *might* deploy the race condition:
class Model < ActiveRecord::Base
def [...]


Strangely RoR doesn’t come with support for Advisory Locking. However, a typical
rails application usually not only needs to synchronize access to the data in
the database but needs to synchronize external data as well. Given that a typical rails application has more than one parallel thread of execution, a programmer might need some tools to synchronize [...]


When something’s rotten in the State of Denmark – I prefer to know! If you feel the same, and you have some C/C++-background: chances are that you know about assertions.
For everybody else: C/C++ programs can usually be compiled in two different modi, debug and release: in debug mode the following C source code line
[...]


…well, sometimes you just have to know how much time your application spends in a certain area.
We don’t speak profiling here, profiling is an applied art and there are certainly enough tools around that do a wonderful job. But sometimes, you just want to know if one implementation variant is much faster than the other. [...]