Saturday, May 17, 2008

More on Assessments

Heh, I just realized that by its very design, Assessments will run the checks in random order without even explicitly meaning to do that. Too funny...

Progress on Assessments

The other night I was working on Assessments and something that was bothering me about their implementation. The thing is that for the sake of simplicity I did the reference implementation using exceptions to notify the assessment engine that a check had passed. Running that through a profiler showed me once more that exception handling is comparatively expensive.

In other words, raising an exception should be something truly exceptional, for otherwise the performance hit associated with handling it can be quite stiff. This clearly shows up in profiler runs, particularly when the code being wrapped in exception handlers executes quickly. In these situations, exception handling can easily dominate the execution cost.

One of the design goals of Assessments is to allow a lot of flexibility in how assessments are evaluated --- or, in SUnitesque, how test cases are run. So I thought a good measurement of whether the implementation was actually as flexible as I had meant was to address the performance issue by having a different way to evaluate assessments to coexist with the original one.

The implementation passed the stress test successfully. The change involved a new class and providing a refinement of 3 methods. What's best is that the existing assessments for Assessments itself could be easily refined to test the new evaluation mechanism too with minimal change to the testing code thanks to inheritance and the use of parallel equivalent test hierarchies (see Chapter 3 of the mentoring book). This is good because the fact that the same assertions are being made allows to prove that both evaluation mechanisms behave in exactly the same way, despite the fact that they handle passes quite differently.

Proper implementation of the tests are just as important as proper implementation of the feature.

Saturday, May 10, 2008

About comments

Once more, I found a questionable code comment of the irritating variety. Basically, I ran into a method like this.

    "The code should do this"
    self butTheCodeTurnsAroundAndDoesSomethingElse.

Now that is helpful... so I just fixed it by deleting the comment and having the code do what the comment was suggesting, which was the appropriate thing to do in the first place.

However, imagine for a moment that you do not look at the code and just look at the comments --- such as when you look at some API documentation for which you are not given the actual implementation. So you read "the code should do this", and then you get the idea that it really does. Wrong!

If you do not have the code to check, well that is unfortunate and it has to be dealt with. But what if you do have the source code? Wouldn't you look at it? After all, what if the comment is wrong? Or what if the code has a bug?

This is where comments start losing their appeal to me. We developers are supposed to be well trained in reading code. What is this business of choosing not to look at code but instead looking at some commentary that may or may not be an accurate description of what the code is doing? And, if after you read the comments, you go look at the code anyway... what was the benefit of reading the comments?

Seriously: if you have available source code, and nothing is funny about it (e.g.: choice of magic constants), why look at comments at all? Or, more strongly perhaps: why would developers, of all people, choose not to look at code?

So... if programmers avoid reading code, then who is supposed to do the actual programming instead?

Progress on Assessments

It had been a while since I last worked on Assessments, and today was the day when I got back to them. What's funny is that I had forgotten what the code looked like, so I was quite gladly surprised to find code nuggets I didn't remember. I chuckled a number of times at some beautiful methods, hehe :).

I just finished the feature tests for Assessments, written in Assessments. I am happy about this, because it means that now I can start building tools for it. Also, something I have in mind is an SUnit bridge so Assessments can run SUnit test cases without needing to make any modification to the existing TestCase hierarchy. After that, I will also make Assessments run SUnit VM test cases, including SUnit Based Validation and SUnit Benchmarks code. Hopefully all will go well.

To be continued...

Saturday, May 03, 2008

More stuff done

I just finished chapter 3 of the fundamentals book. The draft currently has 110 pages.

As it turns out, the draft had reached 102 pages last weekend. This means I did 8 high quality pages, plus some polishing to what I had written last time, in about 3 hours. While it's not the fastest I've written (the record is 15 pages in 4 hours), it's not bad either...

Thursday, May 01, 2008

New month, more work

Last weekend I predicted the fundamentals book draft would reach 100 pages, and indeed it go to be 104 pages long. And, all of a sudden apparently, it has become the month of May. With it, comes yet another deadline that will take time away from the books for a while.

I should hire staff so I can delegate the fluffy work...

Saturday, April 26, 2008

Fresh air

A friend passed on this interview with Donald Knuth. Some excerpts:

[...] To me, it looks more or less like the hardware designers have run out of ideas, and that they’re trying to pass the blame for the future demise of Moore’s Law to the software writers by giving us machines that work faster only on a few key benchmarks! I won’t be surprised at all if the whole multithreading idea turns out to be a flop, worse than the "Titanium" approach that was supposed to be so terrific—until it turned out that the wished-for compilers were basically impossible to write. [...]

[...] With the caveat that there’s no reason anybody should care about the opinions of a computer scientist/mathematician like me regarding software development, let me just say that almost everything I’ve ever heard associated with the term "extreme programming" sounds like exactly the wrong way to go... with one exception. The exception is the idea of working in teams and reading each other’s code. That idea is crucial, and it might even mask out all the terrible aspects of extreme programming that alarm me. [...]

Thank you.

Thursday, April 24, 2008

First pool tournament...

I went to my first 9 ball tournament tonight. Each series was to be played to the best of 3 games, so there was no margin for error. I get there, and I see players with nice looking cues. Hmmm... difficult...

First I played this guy that was not very skilled. I won two games in a row, one finishing with a cross side shot, hit hard, that went down dead center, and another one with 4 consecutive shots that cleaned the table. Basically he didn't play at all.

Then I played this guy that really knew his business. He started playing and now I was being left out of the table. But, when he was going for the run out, he made a mistake. I had 3 balls to go. I sunk two and got an impossible to miss setup on the 9 ball. Which I immediately proceeded to miss, and that cost me a game. So now I was down by 1.

No more margin for error now. The next game starts and again he gets lucky with balls going into pockets almost by accident. Then, he misses and this time I sink the 9 ball with a soft straight stun shot. 1-1.

We start playing the deciding game and it gets complicated. I really needed to stay on the table because all the remaining shots were easy, and the 3 ball which was next in the sequence was in this impossible position: next to a side pocket but out of reach past the middle of the table, the corner pocket in front of it blocked by the 8 ball, and the cue ball set for a straight in shot into the corner pocket that was busy. An up and down shot was out of the question due to traffic and the cut angles. So I went for the just as tough cross corner shot. To make it more difficult, the 9 ball was bothering near the other corner pocket. I decided to hit it really hard with follow so that the cue ball might push the 9 in after the recoil. The 3 ball went in, and the 9 ball almost made the combo too. It was this close.

The game continues. Next up, the 5 ball with a corner pocket blocked by the 7. I went for the combo shot. It was the only thing to do. As I was setting up for doing the 7 with the 5, they asked me if I was planning to sink them both. I said I didn't know. They laughed. Both went in side by side.

Two balls on the table, the 8 and the 9 ball. I missed the 8, and the other guy had a chance at the 9. And, although he missed and it was back to me, he left me this horrible leave. I had this shot across the full diagonal length of the table into a corner pocket, but with the danger of scratching on the other one. I hit it with a lot of draw, the 9 ball went in, and the cue ball missed the pocket on the long rail. 2-1, and a win. Phew...

Then on to the final game, against someone who was billed as not being very talented. And still I wondered if I wouldn't make a silly mistake... after all, I had taken advantage of that in the prior round. He comes to me and says "I am so much going to lose". I don't pay attention... the game still has to be played.

So we go through the first game. He gets a chance at the 9 ball but misses and leaves me something familiar. I won that game with another hard cross side shot.

The next game plays on, and he scratches trying to go for a win. In the end, I had this table long straight in shot, so drawing it was almost impossible because the cue ball just would not stop. I go for the slow shot... and I miss it badly. He makes it, it's 1-1, and again a lot of tension. No more errors allowed.

The next game starts and he gets on a roll. Oh dear, now he is also confident and making the shots he was missing before. The crowd is behind him too. And again, we get to the 9 ball. He tries with a bad leave, and he misses. What shot was left? The same diagonal shot that had to be hit with draw, only this time longer and with more scratch danger. Oh well I thought, I better make it. I hit it harder and with more draw. The 9 ball went in dead center. Then I move my eyes to the cue ball. It had recoiled backwards, but was it enough? Slowly, it backpedaled away from the corner pocket and into the long rail. After that, it took a short bounce and came to rest on the table.

So I won the tournament. That was an experience! And, for the pain and suffering, I also got a nice gift card at a sports store. Good stuff!

Now, back to the normal schedule. I predict the fundamentals book will get past 100 pages this weekend...

Friday, April 18, 2008

Twice this week

The first time... I was dreaming of a nice looking Solaris setup, with a debugger that looked like Smalltalk but was really a C debugger. The stack was top to bottom, and all the lines began with an uppercase character. They were functions. The windows had the pale blue background color I use on Windows. What I was working on was that in some cases the native stack got trashed, and while looking around I found that optimized block contexts were damaged such that answering the message #class would answer nil. At this point, quite happy for having found the bug, I woke up at 3am.

The second time... on the plane back I fell somewhat asleep, and I started dreaming about the VM's internal storage of Windows socket I/O semaphores. I was examining the use of the free list pointers and the CRUD mechanism, looking for potential bugs. Unfortunately a seat had to be fixed next to me, and as such I was prevented from doing further work while resting.

Sunday, April 13, 2008

More progress

I snipped a bit of chapter 2, and the draft went down to 70 pages. Today I started chapter 3, and I reached 78 pages and 300kb of PDF. I really like what I did today. More to come...