Saturday, March 07, 2009

Talking about design...

So I decided to tackle exercise 3.30 from the Mentoring Course book, which calls for determining whether it is possible to implement Conway's Game of Life without using small integers to run the calculations, and to do so efficiently when compared to an implementation that does use small integers.

Well, I just did. Neither implementations are optimized at all. And yet, the one that uses small integers is (by a few percent) the one that runs slower.

Polymorphism... all polymorphism...

2 comments:

Stefan Schmiedl said...

Is this because of polymorphism done right is relatively fast or because of dealing with small integers is relatively slow? Or does it boil down to the message count for dealing with integers is so much higher than with polymorphism?

Andres said...

With integers you have to ask questions because instances of small integer do not know who they are. With classes you can create singletons that represent the actual things that were represented with integers, except that these also know who they are. Then you can arrange code to ask less questions than would be asked with integers, and so the code runs faster.