Manufactoria: A Tile-based Programming Game

May 24th, 2010

What is a “tile-based programming game”? That’s a very good question. I never dreamt of such a thing until I played Manufactoria today. Be warned: if you’re not a programmer you will have great difficulty with this game.

A picture is worth a thousand lines of code, so I’ll show you a screenshot from the game. The following screenshot is an implementation of a bubble sort that operates on a queue of boolean variables.

A bubble sort implemented in Manufactoria

A bubble sort implemented in Manufactoria

It’s an absolutely crazy idea for a game, isn’t it? Let me give you a quick overview of it.

Read the rest of this entry »

Why performSelector: Is More Dangerous Than I Thought

May 14th, 2010

I fixed a rather nasty bug today in AspectObjectiveC. One particular unit test would crash with EXC_BAD_ACCESS every time. After learning far more about registers and ABIs than I ever wanted to know (thanks, Greg Parker), it dawned on me that performSelector: was corrupting memory. It was particularly hard to track down because the crash would happen a couple of lines after the call to performSelector:, when the corrupted memory was actually accessed.

I’ve never had a problem with performSelector: before, but this time I was using it a little differently. The return value of the selector was an NSRect.

Now for the gory explanation.

Read the rest of this entry »

For those who have never used Objective C

April 28th, 2010

There is one feature of the Objective C language that I really love: the method naming. Let me explain with an example.

Here is a nasty call to a C function from the Win32 API that has 12 arguments:

hwnd = CreateWindowEx(WS_EX_LAYERED,
                      TEXT("Hello"),
                      TEXT("World"),
                      WS_OVERLAPPEDWINDOW,
                      10, 
                      10,
                      400, 
                      400,
                      NULL, 
                      NULL,
                      hInstance, 
                      NULL);

Pick an argument, any argument. What does it do? You can probably guess a couple of them, but basically you’re forced to look up the documentation. Sure, 12 arguments is a bit excessive, but even three or for argument functions can be ambiguous. What if you’re trying to understand a function call that is being passed three number literals as arguments? Even if you know the function, you’ll probably have to look up the documentation just to remember the order of the arguments.

Now for the equivalent in Objective C:
Read the rest of this entry »

Video: AspectObjectiveC In Five Minutes

March 20th, 2010

Here’s a quick video about AspectObjectiveC, and what it can do. The code is available from github. I should also mention that AspectObjectiveC isn’t ready for release just yet.

Side Project: AspectObjectiveC

March 11th, 2010

I’ve started a new side project called AspectObjectiveC on github. It’s a little aspect-oriented programming framework for objective-c.

In a nutshell, it allows you to run arbitrary code before, after, or instead of any method at runtime. You can modify arguments before they enter the method, modify the return value of the method, or completely replace the method’s implementation without touching the class’ source code. This includes classes that you don’t have the source code for (e.g. other frameworks). It’s released under the MIT license, even though it doesn’t mention it anywhere yet.

It’s still rough, but it’s working (on my machine :) ). If you want to try it out then build the framework target and whack it into an app as a private framework. It’s got no documentation yet, but the public headers only expose one protocol (AOCAdvice) and one class (AOCAspectManager) with two methods, so it’s pretty intuitive. You can check the unit tests for example usage too.

If you want to contribute code, that’d be great. If you want to test it out on platforms other than OSX >= 10.5, i386 with gcc, that would also be great. Feel free to shoot me an email about it.

Hilarious Massive Facebook Privacy Flaw

February 25th, 2010

My girlfriend just acquired a strange bug with sending private messages in Facebook. Firstly, she tries to send a normal private message like so:

And then, it sends it to some completely random person that she’s not even friends with.

So much for "private" messages.

I tested it in a different browser on a different computer, and it still does the same thing, so it’s almost definitely a server-side problem. I also tested it on my account, but it isn’t happening to me.

When she sends a message to me, it gets sent to Chris Hughes who is a co-founder of Facebook! I wonder if that’s a coincidence. When she sends a message to her friend Rhi, it gets sent to another Harvard alumni named “Zach”. It doesn’t appear to be random, because the same intended recipient always produces the same actual (wrong) recipient.

We filed a bug report, so we’ll see how long it takes them to fix this one.

Update: It was fixed in about six hours or less. Not too shabby.

Update 2: All the stray messages have disappeared from the "sent" section, and hopefully from the inbox of the recipients.

SOLID Class Design: The Interface Segregation Principle

February 18th, 2010

This is that last part of a five part series about SOLID class design principles by Robert C. Martin. The SOLID principles focus on achieving code that is maintainable, robust, and reusable. In this post, I will discuss the Interface Segregation Principle.

The Interface Segregation Principle (ISP): Clients should not be forced to depend upon interfaces that they do not use.

Read the rest of this entry »

SOLID Class Design: The Dependency Inversion Principle

December 19th, 2009

This is part four of a five part series about SOLID class design principles by Robert C. Martin. The SOLID principles focus on achieving code that is maintainable, robust, and reusable. In this post, I will discuss the Dependency Inversion Principle.

The Dependency Inversion Principle (DIP): High level modules should not depend upon low level modules. Both should depend upon abstractions.

Read the rest of this entry »

SOLID Class Design: The Liskov Substitution Principle

November 21st, 2009

This is part three of a five part series about SOLID class design principles by Robert C. Martin. The SOLID principles focus on achieving code that is maintainable, robust, and reusable. In this post, I will discuss the Liskov Substitution Principle.

The Liskov Substitution Principle (LSP): functions that use pointers to base classes must be able to use objects of derived classes without knowing it.

Read the rest of this entry »

SOLID Class Design: The Open Closed Principle

November 14th, 2009

This is part two of a five part series about SOLID class design principles by Robert C. Martin. The SOLID principles focus on achieving code that is maintainable, robust, and reusable. In this post, I will discuss the Open Closed Principle.

The Open Closed Principle (OCP): You should be able to extend a classes behavior, without modifying it.

Read the rest of this entry »