As You Were

Devin Coughlin's blog.
Styles: Serious Spare

January 26, 2007

The mach_inject Heresy

Via Wolf Rentzsch himself I ran across a deliciously hysterical post on rixstep decrying the use of code injection on MacOS X. I won't make any comment on the merits of the argument because it's not worth my time. But I do have to wonder what kind of person would write such a thing?

An bizarre phenomenon.

It's very tempting to dismiss these types of blowhards as extreme partisans in the Mac vs. Unix wars too myopic to concede that there are good things and bad things about each — but I don't think that categorization is the right way to understand the phenomenon.

It's not about Carbon vs. Cocoa, or the spatial Finder vs. column view — it's really about the present versus the past.

Whenever two geographical cultures collide, the conservatives on each side mumble and grumble and scream bloody murder. There's really not much you can do about it but say "yes, grandpa" and wait for them to die. When these cultures are technological in nature, should we really expect anything different?

But here's the thing: The NeXT merger was only ten years ago. We'll be seeing these kinds of upheavals every ten years or so for the rest of our lives.

We're seeing it now in tension between compiled languages and scripting languages, managed and unmanaged code, desktop and web-based apps. It's all too easy to laugh at the javascript kiddies and their ridiculously awful user experiences (OMG, drag and drop in Yahoo mail, what a concept!), but they'll be employed doing UI stuff long after all of us rich-client desktop-types have been relegated to working on the back-end.

Adapt or die.

Even without major mergers, the amount of change in Cocoa in recent years has been staggering. I'd just finally mastered traditional Cocoa MVC when bindings came along and blew that out of the water. Then came Core Data and I had to learn a new way structure my data models. Next comes the switch to Intel and all of a sudden the six months I spent elbow-deep in PPC assembly doesn't look like such a great investment. Now we've got to learn Objective-C 2.0, and so on . . . It's hard not to be bitter about all this. Why should I learn x86 assembly when the PPC ISA is so obviously superior? Won't garbage collection make it too easy for the riffraff to come in and pollute the world with their crappy programs? And don't even get me started on the HIG.

Those of who are curmudgeonly by nature will have to fight that impulse for the rest of our working lives. But I don't see how we can call ourselves "real engineers" without keeping up with progress. What was latest-and-greatest ten years ago sits in the closet, unplugged, or clogs the landfills. In another ten it will be someone's weekend hobby.

Easier said than done.

But we're engineers, after all, we value reliability, predictability, safety above all else. How can we keep our designs conservative without becoming conservative ourselves? The pragmatic programmers recommend learning a new programming language every year (of course, they sell books about programming languages). If you're not learning a new language or framework every year, you're lagging behind in your professional development. If you are a Cocoa programmer, learn Ruby, learn Rails. If you've got the web-thing down, try a functional language. OO fanatics should explore prototype-based languages like javacript and Io. You'll need this breadth when Apple discontinues the Mac. (I kid, mostly). Nuns who do crossword puzzles each day live longer than those who don't. Do something new and challenging every day. Even if your new skills aren't immediately useful, the experience you gain while learning them will be. Most of all, don't stagnate — as you can see at rixstep, it's not pretty.

Posted by coughlin at 4:38 PM

January 24, 2007

Pad Thai Blogging

Following Pandagon and Majikthise, I post my recipe for pad thai.

After three years of making really, really bad pad thai, I've finally settled on a protocol that doesn't completely suck.

Prep rice noodles:
Soak 1 package rice noodles (enough for 4 people) in very hot water beforehand. Extra thin noodles should be soaked for 30 minutes, wide noodles will need an hour. In the winter my tap water isn't hot enough, so I microwave for a couple of minutes to warm it up.

Prep green onions:
While the noodles are soaking, prep all the other ingredients. Chop a bundle of green onions into inch-long pieces — put the green stalks and the oniony base in separate small bowls.

Prep lime wedges:
Cut a 1/8 to a 1/4 of a lime for each serving and set aside.

Prep peanuts:
Grind a handful of peanuts with a mortar and pestle/bowl and spoon. You can fry the the peanuts for a short time on medium heat to bring out more of their flavor. Fried peanuts, in particular, will salvage just about any botched pad thai.

Prep meat:
Chop the meat into bite-size pieces and cook thoroughly. I used to use shrimp but seem to be incapable of not overcooking it, so I've switched to beef, which is a little more forgiving. I sometimes add dried red chili peppers to the meat while it is cooking, but this doesn't seem to make much difference. Drain the meat and set aside.

Prep egg:
Break one egg into a small bowl and beat with a fork until it is mixed and set aside. You'll want to do this now and have it ready later.

Prep sauce:
I use Thai Kitchen's pad thai sauce as a base (this contains tomatoes, which is heresy, but using it is much more predictable than trying to find authentic ingredients), maybe two to three table spoons per serving. Add double that amount each of fish sauce and rice vinegar, and a teaspoon of chili oil. Stir well and set aside.

Now for the cooking. Pad thai has to be cooked very rapidly and at high temperatures, so it is important that you have all your bowls of ingredients accessible. I have also found it much easier to cook a single serving of pad thai at a time. People with better kitchen skills than I should be able to do more.

Pour a couple of tablespoons of peanut oil into a wok (it really has to be a wok — anything else and you won't be able to manipulate the noodles rapidly enough without spilling) and heat to medium high heat. After the oil is hot, add the green onion bases and allow to cook for about a minute, stirring. Grab one servings worth of soaking rice noodles and put them in the wok. Using two forks, tease at the noodles and turn them until they are completely coated in oil (if they aren't coated, they'll stick together later on).

While still teasing the noodles, turn the heat up to high (very high) and wait about 30 seconds. Stir the bowl with sauce one last time and pour in one serving's worth. Continue teasing the noodles until the liquid disappears. This should take less than 30 seconds — any more and you don't have the heat high enough. Stir in one serving's worth of the meat. Reduce heat to medium. Add one serving's worth of the egg to the edge of wok and scramble with a fork. When egg is almost done, toss with the pad thai and plate immediately. When the temperature is very high, there is little room for error — you need to be very fast.

Garnish with the peanuts, the stalks of the green onions and by squeezing the lime slices on the noodles.

Now cook the next serving.

Some notes:

  • As Lindsay Beyerstein notes, the fish sauce is NOT negotiable. The more you use the better — it will reduce in intensity as it cooks. My friend Jonah uses tamarind paste and apricot jelly instead of a store-bought sauce, but I'm too lazy to find these ingredients most of the time.
  • You really need a wok to do this right. A thin-walled wok and a gas stove are probably ideal, but I do this with a thick wok on an electric range and it works alright. You want to have extremely high heat when adding the sauce and much lower heat when adding the egg. The easiest way to botch pad thai is burning the egg in the last step.
  • You'll get better with practice.

Posted by coughlin at 12:14 AM

January 23, 2007

The Libary of Babel Function

Ron Avitzur (of Graphing Calculator fame) exposes pulls back the curtains on Tupper's Self-Referential Formula.

After reading the explanation, I don't find the formula as awesome as I did before. It's still a nifty hack, though.

Posted by coughlin at 2:00 PM

January 18, 2007

NSSet Theory

I found an interesting crasher today that essentially went like this:

NSSet *x = ...

. . .

x = [NSSet setWithObject:x];

This is bad for two reasons: 1) the set {x} violated the Foundation Axiom of ZFC and 2) it led to a stack overflow elsewhere in the program when I attempted to send -valueForKey: to each member of x.

This second bit led to an interesting, and very useful, discovery: sending -valueForKey: to an instance of NSSet will return a new set with the results of sending -valueForKey: to each each member of the first set. That is,

[[NSSet setWithObjects:@"Foo", @"Bar", nil] valueForKey:@"uppercaseString"]

returns the set {@"FOO", @"BAR"} and

[[NSSet setWithObjects:@"a", @"bb", @"ccc", nil] valueForKey:@"length"]

returns the set {1, 2, 3}.

So you can see why I was recursing infinitely above. This works analogously for NSArray.

And since today is self-referential day, I must recommend Tupper's Self-Referential Formula. (Via unto.net blog)

Posted by coughlin at 9:57 PM

January 10, 2007

Programming Links of the Day

Posted by coughlin at 5:37 PM

January 8, 2007

Baby Boy Cohen

Josh and Rachel had the bris for their new baby boy today.


(Photo taken 2 January 2007)

He was named Isaac Joseph.

Posted by coughlin at 5:24 PM