FwdStuff.com -- My first Merb App

I've launched my first Merb app today.  It's at FwdStuff.com.  The idea is to help people better keep track of their Craigslist postings and correspondences.  Since Craigslist routinely blocks services that hit the main site, FwdStuff.com collects all of the data it needs through forwarded emails.  It's not especially fast right now due to another app hogging all the memory on my very low end VPS.

Merb

One thing I've found about Merb since I've started using it is that when I look at the source, I can understand it, for the most part.

I haven't looked at Rails code for a while, but I certainly don't remember being able to understand it very easily.  I definitely haven't seen any page-long methods yet.

Interview Question

I was recently asked the following question for an interview at a company here in the SF Bay area.  If my boss came to me on Friday afternoon and told me that he needed something done by Monday, and I absolutely knew it could not be done, what would my response be.

I think I gave an incorrect answer which was that I would explain why I thought it couldn't be done and propose an alternative.

I think the correct answer should be: "How could I know that it is impossible if I hadn't tried to do it?"

Implementing removeIf in Objective-C

Objective-C is so much better than C++ and C that it's not even funny. However, I still feel like it is missing some basic capabilities, especially in comparison with other dynamic languages such as Ruby and Python. The capability to pass in code blocks in Ruby to various list processing map-like methods is sorely missed. This morning I ran into a case where I needed one of those methods in particular: removeIf. I needed to remove some items from a list based some criteria. This is a pretty common occurrence, and in fact I'd needed it before but just kludged it.

So, how is it done? It turns out to be pretty simple. First design a selector:

(NSMutableArray *)removeIf:(SEL)selector target:(id)target args:(id)args;

This method (implemented as a category on NSMutableArray) needed to call selector on target for each object in its collection and remove the item from its collection if the selector returned true.

Here is an implementation:

- (NSMutableArray *)removeIf:(SEL)selector target:(id)target args:(id)args{  NSMutableArray* itemsToRemove = [NSMutableArray new];  BOOL (*fn)(id, SEL, id) =      (BOOL (*)(id, SEL, id)) objc_msgSend;  for(id item in self) {      NSMutableDictionary* newArgs = [NSMutableDictionary new];      [newArgs setDictionary:args];      [newArgs setValue:item forKey:@"item"];      BOOL shouldRemove = fn(target, selector, newArgs);      if(shouldRemove) {          [itemsToRemove addObject:item];      }      [newArgs release];  }  [self removeObjectsInArray:itemsToRemove];  [itemsToRemove release];  return self;}
The only tricky part about this implementation is that in order to handle a return type that is not an object, it is necessary to declare a custom function pointer that casts the return value appropriately. This is explained very well here.

This method could be improved by rewriting it to return a copy rather than modifying its own data.

Reddit is a Tabloid

Watching a 1970's era French movie called "Love at the Top" yesterday, in which a man becomes a millionaire partly by acquiring a failing newspaper and turning it into a tabloid that prints only what its readers want to read thereby increasing circulation exponentially, I came to the realization that Reddit is the internet equivalent of a tabloid newspaper.

The similarity is most evident when comparing the often sensationalist and misleading titles of tabloid articles to the often misleading and sensationalist user generated titles submitted to Reddit.

Tabloids: "WOMAN DELIVERS OWN BABY WHILE SKYDIVING!"

Reddit: "Giving birth was an orgasmic experience for one woman"

Tabloids: OMAHA BIN LADEN Osama's brother rides the range as a cowboy

Reddit: Osama Bin Laden is dead since December 26, 2001. Translation of Funeral Article in Egyptian Paper.

Given the similarity between the sensationalism of many Reddit posts and the sensationalism of tabloid articles, it is important to note that Reddit has broken new ground in the field of tabloid journalism. It has managed to create entirely new tabloid sub-genres, such as police brutality, and the comparison of the US to Germany in the mid thirties.

SWM Seeking LTR with Beautiful Code

I've dated lots of code. I've had my share of one night stands (hell I've even paid for it). My longest relationships lasted about 9 months. I'm getting older though, and now I'm looking for some code to have a long term relationship with.

I'm in a situation now that I've never really been in before. I'm the only developer on the project, and I'm looking at working with the same code base for several years. Since I started the project from scratch, I can't blame my predecessors for any blemishes. I have no manager, so I can't blame any ugly hacks on artificially imposed deadlines or poor design decisions made by non-developers. When I get stuck there's no one I can go to for help.

The consequences of having a long term relationship with code is that I have to live with my decisions. Any line of code I write will be revisited at a later time, probably a lot. I'm married to this code. This is not some post-modern divorce-prone marriage either. This is a medieval catholic marriage where the only way out is beheading.

The longer my relationship with a project, the clearer it becomes to me that writing good code is important. Good code is easily modifiable. This means that making a change is simple, rather than complex. The fewer side effects each change generates, the more easily modifiable code is. This has been a hard concept to get for me since I've only ever written quick and dirty code for short-term projects where once some basic functionality was accomplished, the code was never revisited. In a longer term project, code is rewritten, again and again as users dig up bugs and as performance issues slowly rear their ugly heads.