Saturday, November 21, 2009

And it's done, Phexample has no more lolcats

Image from Wikipedia, see http://en.wikipedia.org/wiki/File:Yet_another_lolcat.jpg for the author. CC license.

Lolcats have left the building, Phexample reads easier now.

Stack new isEmpty should not be true.

To get a meaningful error message out of this test, you're faced with a small dilemma. The Phexample framework lies in the should method, thus, for all that should sees, it is called on true, so the test might as well have been

true should not be true.

Now, to squeeze a reasonable error message out of this, such as "isEmpty should return false, but got true," it helps finding the unexecuted code snippet in the caller. Thus, the execution depends on who called you. Maybe not perfectly object-oriented, but context-oriented! There we have a new buzz-word: COP, context-oriented programming.

I learned a few things on the way: Bytecodes in Smalltalk have different sizes, thus you can't just walk backwards from where you are. The containing method must be read forwards, and once you hit the position of the current execution, you know you're a bit too far. Also, you find the current stack frame using the pseudo-variable thisContext, though there are some performance issues with it.

By the way, you can't really ice and copy the stack (someone forbade it in the source, for whatever reason), you're analyzing it as it is being used for the current computation. A bit scary, but it works quite nice. Pharo ftw! Try this in JavaScript!

Get the latest version of Phexample at SqueakSource (there's a Gofer-Script on that page that will do the downloading for you!.

2 comments:

  1. Maybe good solution is using block:

    [Stack new isEmpty] should be true.

    Block can be printed as it source

    ReplyDelete
  2. True enough, that would have made things easier :D. But then again, the block syntax would not have matched the rest of the DSL. Thanks for reading my blog, btw :)

    ReplyDelete

Note: Only a member of this blog may post a comment.