Sunday, September 24, 2006

Refactoring Pong

I just finished refactoring what I wrote for the 2006 STIC contest. In a way, the solution for Pong had two parts. One was the framework on which I relied to write the players, and another one was the actual application of the framework to Pong.

As it turns out, I could separate about 20kb of source code and generalize the framework I found. Now it has a name --- the perception pattern.

Something that I found interesting was that as I was pushing up methods into more abstract classes, Pong classes became quite empty. In particular, the class that models the pong player ended up with 3 private methods that answer instances of Pong eyes, hands and interfaces, as opposed to the more general answers the messages in the superclass provide.

I think the perception pattern is a powerful tool that can help being touchingly expressive. I used it at the office to implement an autonomous agent that mimicks people's actions. It is seriously good stuff. It is so easy to change and improve. It is beautiful.

Now that I have a refactored perception pattern implementation, it will be easier to create other things.

Wednesday, September 20, 2006

Another first

Last night I finished my first Winamp DSP preset. It is a slow-me-down pitch changer with linear interpolation. I am happy because, although linear interpolation is not very sophisticated, it sounds better than the preset that comes with Winamp, which just repeats samples.

Well. It sounds better most of the time. I wanted to use natural cubic splines, but it is definitely much more effort than I am willing to spend writing C-style code in those tiny windows with no debuggers.

Tuesday, September 19, 2006

Hotel at OOPSLA

Watch out, the hotel across the street from the convention center may not have rooms for you if you decide to come in early or leave late.

If you need extra days, La Quinta has a reasonably priced hotel 4 blocks from the convention center, closer than the other two offered through the conference. Also, La Quinta has free wireless internet access.

Monday, September 18, 2006

StrongTalk and the Blue Book

Once upon a while Alan Kay said that, although the Blue Book had a complete reference implementation of the virtual machine, to his knowledge nobody other than the initial four had attempted to make a new virtual machine from scratch.

In addition, he also commented on Al Gore saying that with the Internet in the hands of the public, it would be possible to have a much more educated population. Alan's wife snapped back: the knowledge is already in libraries, and very few people take advantage of it. Why should the Internet make a difference?

And this brings me to StrongTalk. Now the source code is out there. Should I expect, in the view of how other things have happened, that in the next year or so we will have amazing virtual machines, just because a reference implementation is available? The answer must be, again, no.

The SELF thesis, the foundation of StrongTalk's compiler, has been available for more than 10 years. The SELF system is proof that it works. StrongTalk itself, as proof that it can be done in Smalltalk as well, has been out there for another decade. And what happened since then? Nothing. Why should a bunch of .cpp files make a difference now?

No, my friend. For this to happen, what is necessary is action. I hope this is the time though, and that StrongTalk's release spurs us into making it a reality. As with everything: it is now, or never.

Go Smalltalk Go!

Wednesday, September 13, 2006

Presentation at NYC --- another one coming up!

Well!... it was interesting...

I had all these problems with getting the laptop to use the projector properly. 40 minutes to get it to work really make me wonder if I wouldn't be happier with a Mac. Most likely, the NVIDIA drivers make sense to most people and I am just unable to use them properly. I still do not understand how the thing is supposed to work.

After that, however, things went better. Ahh, my friend, but if you weren't there... then you missed a working model of how things that can perceive their environment can also react to it!

I really enjoyed the conversations at the bar, and it was interesting to see how different people see things from different points of view. In addition, I was scheduled to do the OOPSLA demo in November. Details such as the date will be confirmed when we get closer.

See you at the next NYC SUG meeting!

PS: the meeting's address is 440 9th Ave, 8th floor.

Sunday, September 10, 2006

Caffeine abstinence syndrome? Bah!

From The Register comes this snippet.

Scholey reported to the British Psychological Society in 2000 on his study of the psychological effects upon drinkers of caffeinated and decaffeinate coffee. As everyone is told, caffeinated coffee (CC) makes you stay awake and keeps you more alert. Decaffeinated coffee (DC) supposedly does not.

Scholey and research colleagues conducted a simple experiment. They informed each subject in the experiment, all of whom were coffee drinkers, that each would be assigned to one of two groups (A or B). They informed subjects that those in A would be given CC, those in B would be given DC, each subject would then take a computerised test, and each subject would be told which group they were in (and what they were given).

In reality, without being informed, all subjects were divided into four groups (A1, A2, B1, B2). Those in A1 were told they were getting CC and were given CC. Those in A2 were told they were getting CC but were given DC. Those in B1 were told they were getting DC and were given DC. Those in B2 were told they were getting DC and were given CC.

The researchers found that, as predicted, subjects who drank CC were faster and more accurate on a computerized test - but only if they thought they had been given CC. Subjects who drank CC but thought it was DC performed less well.

Most interesting of all, subjects who thought they had drunk CC, but in reality had drunk DC, performed on the tests as if they had really had drunk CC. Thus, what you think is real can be more important than what is real. Mind over matter goes a long way.

Oh, but then, what about all the times when we let some axiomatic truth stand by itself without applying further inquiry? Sigh :(.

Thursday, September 07, 2006

New phrase coined

You know those objects. You have seen how they depend on each other's implementation details to work. Their methods routinely violate encapsulation, Demeter's Law, and every bit of responsibility driven design you can think of. But now I know.

They are guilty of insider messaging.

Wednesday, September 06, 2006

Chapter 5 is done --- AGC is next

Roughly a year has gone by since I started writing the book. I just finished chapter 5, and the book draft is currently 232 pages long. Next comes a chapter called, in a quite self explanatory fashion,

AGC is Garbage Collect

This one should take longer to write, as I will have to create code that does not exist yet. So much to do, so much to write about!

Sunday, September 03, 2006

The religion of numbers

I had a chance to read a paper on interpolation of interest rates not long ago. The idea is, given a few data points, to generate a "smooth" curve that goes through them. Now, natural cubic splines are the ideal tool for this because it is them who minimize the integral of the absolute value of their second derivative --- in other words, they are the function that oscillates less around the sampling points.

To my surprise, this paper criticized natural cubic splines because, when sampled outside the range of sample points, they behave like a line and lose their curviness. Well, of course they will, because they are designed to minimize their waviness.

But what was the solution? Just to add a sample point further out in the future according to what is desired, right? No. To interpolate these values with quartic splines instead to keep curvy behavior when extrapolating.

Now, quartic splines are considerably more complicated to manage, they are not the smoothest interpolating function, and yet the decision is made to use them? Exactly why is this? Because a particular behavior is wanted when extrapolating.

But if you already know the kind of values you want, why come up with a more complicated curve instead of saying what the desired values are? Why not add a point further out in time so that cubic splines can be curvy too? Besides, it is what you want, right?

Perhaps there's some interesting argument I am missing. From what I saw in this paper, though... I can't help feeling that this is just a matter of a function being trusted more than a data point. Why put faith on a function to give you something you find close enough to what you want, instead of specifying what you already knew you want for an interpolation mechanism to use it? I don't get it.

Saturday, September 02, 2006

Ruby Quiz #93

The happiest number between 1 and 1 million seems to be 15,999, with a happiness index of 20*. For base 10, the code is as follows:

    Integer>>happyDerivation

      self = 0 ifTrue: [^0].
      ^(self // 10) happyDerivation
        + (self \\ 10) squared

    Integer>>happyDerivations

      ^self addHappyDerivationsTo: Set new

    Integer>>addHappyDerivationsTo: aSet

      (aSet includes: self) ifTrue: [^aSet].
      aSet add: self.
      ^self happyDerivation addHappyDerivationsTo: aSet

    Integer>>happiness

      ^self happyDerivations size


This is easily extensible by adding the base as an argument.

I have a feeling all bases are happy, although I can't quite muster a proof right now. Is there a counterexample?

* The problem statement seems to indicate the only unhappy numbers are those in which the procedure above never ends, and this is what I assumed. Also, I assumed that since 1^2 = 1, 1 is happy, and its happiness index is 1 because starting at 1 one finds that the number 1 is happy.

But if the statement meant that unhappy numbers are the ones that do not reach 1 instead, then we just need isHappy to answer ^self happyDerivations includes: 1.