Uncategorized — 1 comment
29
Oct 08
Why, oh why do classes, which have the purpose to remove something from documents, always have to be named “XYZStripper”? As a programmer faithful to the (often unwritten) coding conventions, I have to name instances of such classes of course – “stripper“. Unfortunately the names of those stripping methods do not quite match the juicyness of the class name. I would like to code things like stripper.renderNaked() or stripper.undoClips().
And with a swing of her hips
She started to strip
To tremendous applause
She took of her drawers
And with a lick of her lips
She undid all her clips
And threw it all in the air
And everybody stared
Chris de Burgh: Patricia the Stripper
Uncategorized — No comments
23
Oct 08
This must be either really new or – what seems more likely – I have slept over Google’s developments the last year. Google Code allows for a regular-expression-based search in publicly available source code. Nice one.
Uncategorized — 1 comment
08
Sep 08
Dear fellow Ruby developers, please kick the habit of catching and rethrowing exceptions, thus ridding your users of the expeptions’ stack traces. Recently I had to patch the source code of an ActiveRecord adapter as well as the underlying DBI implementation in order to find out where one particular exception was originating from. This makes debugging code really a hassle. I haven’t had this kind of problem in Java since nested exceptions.
Uncategorized — No comments
01
Aug 08
One of the very nice features of Mac OS X ist the ability of almost every reasonable application to receive AppleEvents, which makes the whole OS-app-bundle highly scriptable. Normally, Apple recommends that the scripting is done using a malevolent, programmer-unfirndly language named “AppleScript”. But there are alternatives, e.g. using Ruby together with the rb-appscript library.
As a first try, I wrote a small hack solving the following problem:
In Aperture, I normally sort photos in folders named YYYY_MM_DD, so when I sort them by alphabet (or Aperture sorts them and I cannot change the sort order), the oldest ones show up first. Unfortunately, iPhoto imported photos from my camera in the German format DD.MM.YYYY, so the alphabetical sorting is useless.
The ruby script goes like this:
require "rubygems"
require "appscript"
include Appscript
app = app(‘Aperture’)
puts app.projects
app.get(app.projects).each { |project|
name = app.get(project.name)
if name =~ /^\d\d\.\d\d.\d\d\d\d$/
day = name[0, 2]
month = name[3, 2]
year = name[6, 4]
app.projects[name].name.set(year+"_"+month+"_"+day)
end
}
Uncategorized — No comments
23
Jul 08
If you are documenting Java methods, try to fit everything really important (like constraints for the method) into the first sentence of the javadoc. This sentence is displayed along wiht the overview of the class method.
Everything after the first sentence vanishes in the distance where no-one will ever read it.
Uncategorized — No comments
12
Jun 08

Created by OnePlusYou
I named those codes, and boy, what a miracle – one hundred percent right. Try it yourself!
Uncategorized — 3 comments
10
Jun 08
I want a Firefox Plugin that recognizes that the page I’m looking at contains Java, does syntax highlighting and, most of all, inserts links to the classes and methods referenced in the code. The plugin (or a server it can ask) should know where the source code of a class like org.springframework.beans.factory.BeanFactory can be found.
First I thought that such a plugin would need (or could at least profit from) sem***ic web technologies (no dirty words on this blog, please), but it probably wouldn’t. All we need is a global registry that maps package names to the URLs of the web interfaces of the respective source repositories. (Maybe Google Code Search could be such a repository, but its results are often pretty bad.) The plugin would also have to include a reasonably good Java parser, and maybe a heuristic to distinguish betweeen Java and non-Java text.
Why would I want such a thing? Well, I often have to dig through the code of some open source library in order to understand a bug, or just to figure out what I can do with it, and how, because the documentation is incomplete or wrong. Usually I create an Eclipse project and import the code from the source repository, but that’s quite a lot of overhead if I just need to browse the code for ten minutes or so. On the other hand, digging through source code on web pages, without the help of links between the pages, is just a nuisance.
And wouldn’t it just be so cool to have one of the most important features of an IDE as a browser plugin, enhanced by the power of the world wide web?
P.S.: Or maybe I don’t want a browser plugin – maybe I just want Google to put some more effort into Code Search? Come on, guys, you’ve got all it takes – the global repository, the parsers, the heuristics…
Uncategorized — 1 comment
03
Apr 08
This is just a note to all who, like me, wonder why the heck ActiveRecord’s quote method in model classes doesn’t work anymore in Rails 2.x: quote seemingly has been replaced by quote_value, though this is not listed on the deprecation page. So if you get an error that says undefined method `quote’ for your model class, replace the calls to quote by quote_value.
Uncategorized — No comments
28
Jan 08
Maybe this is old news to some, but I recently discovered that there’s a complete recording (audio at iTunes, audio and video on the web) of an MIT lecture by Prof. Charles E. Leiserson using “The Big Book” Introduction to Algorithms (which he co-wrote) as textbook. I just listened to the first of 25 lectures and liked it as a refresher course on the stuff I learned at university years ago. Lecture notes are available online as well.
Uncategorized — No comments
25
Jan 08
Currently, I am in the nice situation to decide for myself with which framework I will build a demonstration portal. So, as I want to profit from the fast-paced development processes (at least the Ruby aficionados say so) and the lightweightiness of Rails, I decided to go the Rail(s)Way.
Problem is, that I have to use a legacy database in PostgreSQL where I am not allowed to tinker with the structure, but I am forced to insert data into the tables. The database was created using Hibernate, which means an overall database sequence is used to generate the unique IDs. Unfortunately my new pal ActiveRecord does not know anything about global Postgres sequences, so I had to figure out a way to use the hibernate sequence in a hack to get my unique IDs.
What I did was to use the hook before_validation_on_create in the ActiveRecord table model to create an ID. This looks like this:
[ruby]
class Term < ActiveRecord::Base
before_validation_on_create :generate_id
private
# use the hibernate sequence to generate the next id
def generate_id
self.id = Term.connection,execute(“select nextval(‘hibernate_sequence’)”).result[0][0]
end
end
[/ruby]