weblog.masukomi.org

mah-soo-koh-me

 

Kindle: first impressions December 12, 2007

Filed under: Uncategorized — masukomi @ 7:32 pm

Kindle, initial impression

A coworker brought in his new Kindle. Here are my initial thoughts after a couple minutes of playing:

  • Processor is dog slow (searches took way too long, menus take way too long)
  • Refresh rate is annoyingly slow. Changing a page is still faster than changing a real paper page but not nearly as fast as you’ve gotten used to on your computer.
  • I feel like I’m only looking at half a page at a time. There just aren’t enough words on the screen.
  • Previous / next button placement is terrible. Both thumbs end up being over the next button.
  • Previous / next buttons feel cheap.
  • There’s nowhere to hold onto while typing so you feel afraid you’re going to drop it.
  • It knows about tables of contents and you can jump to the chapters of the book listed there BUT there’s no way to jump to those chapters from anywhere else, not even the search page.
  • The screen is very very readable. e-ink is a great technology.
  • The Amazon.com store integration is quite nice.

Conclusion: wait a couple generations and this may be a really sweet device. I’m still annoyed about the DRM though. I don’t want to have the problem of buying all these books and then wanting to switch to another e-book device someday and having to re-buy them all over.

 
 

Alphabetical != ASCIIbetical December 10, 2007

Filed under: Uncategorized — masukomi @ 7:11 pm

[BEGIN RANT]Partially this is a case of Java community being populated by idiots, but people seem to be wholly ignorant on this issue in other languages too. Google for java alphabetical sorting capitalization or any combination of words you can think of that might get you an algorithm that sorts a collection alphabetically. You will find hundreds of wrong responses and no correct ones. Most of them say to use the Arrays.sort(..) or Collections.sort(..) methods. But both of those use natural order (or asciibetical as i like to call it) not alphabetical order so 1 is followed by 10 not 2 and things starting with a capital letter aren’t beside things with the lowercase version of the same letter. Some people think of calling .toLowerCase() on everything first so that at least they eliminate the latter issue but i have yet to see a single example of an actual alphabetical sort in Java (or any other language I’ve checked). Silly me, I just figured that alphabetical sorting was such a common need (judging by the number of people asking how to do it I’m not wrong either) that I wouldn’t have to write the damn thing. But I didn’t count on the stupid factor. Jesus Christ people. You’re programmers. You’re almost all college graduates and none of you know what the fuck “Alphabetical” means. You should all be ashamed. If any of you are using your language’s default sort algorithm, which is almost guaranteed to be ASCIIbetical (for good reason) to get alphabetical sorting you should proceed to the nearest mirror and slap yourself repeatedly before returning to your desks and fixing your unit tests that didn’t catch this problem.[END RANT]

[Update] There is apparently one person who knows the freaking difference. Someone get that man a cookie!

[Update 2] Alphabetization/Alphanum/whatever you want to call it is entirely language dependent. Obviously an algorithm that works for English is unlikely to work for other languages. Attempting to create a generic purpose one that handles special characters of multiple languages is brain dead because there may be other rules that affect alphabetization in them.

[Update 3] Jeff Attwood points out that this is called “Natural sorting” not “Alphabetical” sorting. Unfortunately the Javadocs for Collections.sort(…) talk about sorting things according to their “Natural ordering” which may be technically true but just adds to the confusion.

 
 

The Word Game December 9, 2007

Filed under: Uncategorized — masukomi @ 7:03 pm

The Word Game

I don’t remember the exact origins of The Word Game. I just remember that John was involved. The word game is great for passing time on long road trips, seeing how your friends brains work, and enhancing a child’s vocabulary. You can also play it by yourself. It’s an association game, but the rules are subtle.

The rules I can tell you:
Phrases and short sentences are allowed, but words and names are preferred.
All words are legal, especially interesting ones.
You continue until you either can’t come up with an “acceptable” response.
Then you start over.
Any response that no-one complains about is “acceptable”. It should be fairly obvious when a response isn’t satisfactory.
Associations can be based on the sound of the word, the meaning of the word, things associated with the word.
Cooler words are better.

Since the best way to explain the game is by example I just played a very short round with myself and wrote it down for you. If I wasn’t playing solo each line would be a different participant’s response as we went around the group.

Gary Shandling
Gary Gygax
triple thorax
triple goddess
phases of the moon [this would only work if you hung out with pagans]
Moonstruck
starstruck
pile of muck
pig pile
puppy pile
3 mile
3 mile island
nuclear winter
nuclear radiation
plutonium
I love my mum.
chrysanthemum
Christianity
Christmas
Michaelmas

It’s not uncommon when playing to spend a while throwing out different words that all rhyme (imagine all the “…ing” words you could iterate over), but I tried to avoid that here so as to give you a better example of the different types of “acceptable” associations.

I know, it looks kinda silly, but it’s actually a lot of fun, especially in the car. I find that the faster you play the more fun it gets. Also, it’s not just a matter of finding words and phrases that happen to be
associated somehow. You want to use the coolest words you can think of. Even though there are lots of “…ing” words, as mentioned above, if you can think of one, but it’s not particularly cool, it’s better to take the game off on some other more interesting association.

 
 

SSCM 0.4 Released

Filed under: Uncategorized — masukomi @ 6:03 pm

Some of you may be interested to know that SSCM v 0.4 has been released. Notable changes: supports move operations, fixed a bug with perforce support, allows you to live dangerously and just accept all detected changes into the repo without asking.

The two things I’d like to get in there now are branching and merging all the known repos with one command each. Should be relatively trivial for the distributed clients, but the centralized ones will be a little work. Anyone feel like pitching in?

 
 

Disovery coding through tests December 8, 2007

Filed under: Uncategorized — masukomi @ 3:57 pm

Testing as a process of discovery

The other day a coworker said,

Some times you get situations where the specification for the unit or module you are writing just are not available.  The code writing is a discovery process as much as anything else.  Moreover, some of the packages and methods being called don’t have predictable or documented behavior.  That’s ugly and horrible, and I don’t know how that’s allowed,  but nonetheless, from the perspective of someone who wants to do unit testing in such an environment, can you give any tips?  I mean, do you mock up approximations to what you *think* these external things *should* be doing if you really don’t *know* what they are doing?  Do you do your best, updating mocks and tests, “in the face of adversity”?

Really we’ve got two questions here:
How do you address the desire to write tests when you don’t know what exactly you need / want yet?
How do you handle external libraries where you’re just not confident in what the expected behavior is?


How do you write tests for something when you don’t know what exactly that something is yet?

Let’s look at coding a simple User Story and Acceptance Test and tackle them in a way that allows for maximum flexibility and exploration while coding.

The User Story (for a cash register):
Keep a running receipt with a short description of each item and its price.

Its Acceptance Test:
Setup: The cashier has a new customer.
Operation: The cashier scans a toothbrush for $2.25.
Verify: The receipt has a description of the toothbrush and its price.

Let’s assume we’ve written absolutely no code. But we want to take a test driven approach and we don’t want to write tests for the bits we haven’t really figured out yet, because, well… we haven’t figured them out and we want to keep the possibilities open. So let’s write the bare minimum required to test this. From the user story and acceptance test above we can tell exactly what classes and methods we’ll need to write and test. So we’ll need:

  1. ICashier (cashier interface)
  2. ICustomer (customer interface)
  3. IRegister (register interface)
  4. IToothbrush (toothbrush interface)
  5. IReceipt (receipt interface)

As for methods we’re going to need:

  • IToothbrush
    • getPrice()
    • getShortDescription()
  • IRegister
    • scanItem()
  • IReceipt
    • addItem()
    • print()

Now, there are three approaches we could take here:

  1. Write a full interface and tests for all of these with all the other methods we expect them to need (like a getUPC() method on IToothbrush)
  2. Write an interface and tests for all the methods we know we’ll need (the ones listed above)
  3. Write an interface and tests just for the items we are using RIGHT NOW.

I’d been doing the latter for a little while and was pleased as punch to find out, when listening to a podcast interview with Martin Fowler, that this is exactly what  he’s been doing lately too. I think that this is the best possible approach because it keeps you focused on what you actually need, it gives you much smaller and more quickly obtainable goals, and it gets things working faster. If you took this approach you might proceed something like this (again, assuming no code has been written at this point):

  1. Write the IToothbrush interface.
  2. Add the method you want to address first (get price)
  3. Write a unit test for that method.
    • check that a toothbrush never has a null price
    • assert that the price is going to be a decimal number
    • check that the price is never less than zero.
  4. Now that you’ve got a properly failing test you write a Toothbrush implementation with just a getPrice() method.
  5. In your Toothbrush implementation you’d probably have a no parameter constructor that set up a default price of $0.00, or your getPrice() method would be smart enough to guarantee a non-null price was returned, either way, your test would pass.

I’d say just repeat for each item in the list  but it’s not quite that simple. When you get to the getShortDescription() you’ll probably have a test that it’s not null, but we’ve got no method in our spec for actually setting a description so we can’t make an implementation where that test passes unless we create a method to set the description or allow it to be set in the constructor. XP people advocate doing the simplest possible thing that will work, which in this case makes sense and would be to set it in a constructor. So, now we’ve got to add a unit test for the constructor, and it’s reasonable to think that we should set the price in the constructor too. So, in order to really test the getShortDescription() method we also need to write a test for the Toothbrush constructor. So, testing getShortDescription() leads us on to the next bits we need RIGHT NOW.

  1. Add the getShortDescription() method to the IToothbrush interface
  2. Add the testGetShortDescription() unit test
    • check that the description isn’t null
    • check that the description isn’t empty
    • check that it’s actually “short”
      • this could, conceivably lead you to want create a generic Item interface that has a validateShortDescription(…) and / or truncateDescription(…) method, but I’d recommend holding off until you finish with the items required for this acceptance test. While a good idea, and something to plan on, it’ll be nicer to actually get through this initial acceptance test before diving down the rabbit hole of nice-to-haves.
  3. Add testConstructor() method to your ToothbrushTest test case
    • test that we can instantiate an object with a valid price and short description
    • test that we can’t instantiate an object with an invalid price and valid short description
    • test that we can’t instantiate an object with a valid price and invalid short description
    • test that we can’t instantiate an object with an invalid price and short description
    • test that the price and short description come out through the two getters we have in our interface.
  4. Add a constructor that takes a price and a short description to Toothbrush
  5. Add getShortDescription() to toothbrush.

By taking such a focused approach we haven’t constrained what could happen with any of the other functionality in toothbrush. Let the emerging specification define if you need a getColor() method on your toothbrush. If it’s not there now and none of the methods you’ve worked on so far have implied the need don’t go there at all… otherwise when you finally do get there you’re likely to find that “blue” wasn’t an acceptable thing to for it to return at all what it really needed to return was an array of RGB values:  [0,0,255].  My advice would be to  add a comment to the interface noting that you think a getColor() method might be useful and what you think it should return, that way as you keep coming back and updating IToothbrush you’ll keep that in mind and won’t forget or accidentally code yourself into a situation where it’s difficult to derive the color.


How do you handle external libraries where you’re just not confident in what the expected behavior is?

The same approach we just discussed for writing the unit test should guide what we mock up of untrusted external libraries AND how we proceed in working with them. Normally I try and work under the assumption that the libraries I depend on are dependable and never write unit tests for them, but sometimes you need to find out what you can depend on or what exactly some methods do because they’ve got no docs. So first you look at the library and ask yourself what methods, based on your limited understanding, do you absolutely need to use? Then you write unit tests that test that confirm that when using it the way you plan on using it it does what you think it would do. You don’t have time to test their entire library or all the possible edge cases for their code so you just test that the bits you will be using work the way you think they do when called in the way you’ll be calling them. For example if your code can’t possibly pass in a negative number then you don’t need to worry if their classes correctly handle negative numbers or not. You just need to make sure that the class handles the full range of numbers you could be passing it correctly and nothing else. Now you know that it does (or doesn’t do) what you expected and you know some things that you can safely pass it.

Depending on how untrusted the library is you may also want to make sure that everyone in your group knew to not use anything in that library that they didn’t have a minimal test case for.

Mike Clark wrote an article wherein he describes a similar approach but for a language instead of a library. His idea was that when you start learning a new programming language you just don’t know how exactly things work. You assume things may work one way but that’s not always the case. He set out to write test cases for all the things he learned how to do in the language. This had a few good side effects: it got him familiar with the testing framework of the language, it got him to actually use all the language constructs (doing is far better for memory retention than just reading) and he now has a test suite of his mental beliefs of how the language works. If a new version of the language comes out he’ll know right away if his mental model of how things works needs to change because his tests will fail.

 
 

Pretty graphs you can’t show customers December 5, 2007

Filed under: Uncategorized — masukomi @ 2:41 pm

This projects has been rolling around in my brain for a while but I haven’t tackled it yet because I have too damn many other projects in process. So I’m putting it here in the hopes that maybe someone will pick it up and run with it.

I want to put together a collection of javascript based graphing tools that generate pretty SVG graphs of your data in a way that’s fun to look at for people who have to work with it every day but not necessarily something you’d ever want to try and explain to a customer. I want to do this because we deal with a crapload of really interesting data at work, but a lot of it is just internal and only of interest to geeks. Also I’d like a visually interesting way to keep an eye on the status of our systems and the data flowing through them. Stacked bar charts and line graphs get old fast.

Here’s my first idea:

Imagine you have a wooden beam. Hanging down from that beam are strands of ivy. Each strand of ivy represents a thing you’re watching (customer actions, a product’s sales, a website, whatever). The length of the strand represents the number of hits to / quantity of that thing. Now, imaging that that thing has some quality goodness/badness, happyness/saddness, good profit margin / bad profit margin, etc.. As each item is added to the end of the ivy the ivy curves to the right or the left based on how much goodness/badness (or whatever) this item contains. If every item you added had some goodness the line would angle off to the right. Bad items would, similarly, curve it off to the left. If you have a relatively even distribution your lines will simply curve back and forth in a wavy line like a real piece of dangling ivy.

Originally the ivy was just a metaphor to help people visualize it but brainstorming with John brought up the idea that when an item’s goodness/badness crosses a threshold a leaf is added to the line. Maybe the leaf could have an onClick event to take you to a page with details. Maybe the leaves could be different colors or sizes to emphasize how important the event is (relative to how far over the threshold it is).

Imagine how cool it would be to have a whole collection of fun little graphs like this to keep an eye on your data! The beauty of it is this is actually really easy to implement. I just won’t let myself do it until I release the next version of SSCM out the door (with merging and all that goodness), and release the source code to TicketEverything!.

There’s a good tutorial on creating svg objects and you could pre-generate complex items, like the leaves, with Inkscape, or any other vector based illustration app that can export svg.

 
 

At least she knows exactly what she’s doing December 4, 2007

Filed under: Uncategorized — masukomi @ 1:02 am

I’m a big fan of Laurell K Hamilton. My only complaint is that, as of late, both of her two major series have devolved into soft-core porn. The Anita Blake series started out fairly standard vampire hunter with love interest and became soft-core. Her Meredith Gentry series started out as soft-core. I just watcher her doing some Q & A at a book store and am happy to say that at least she has no misconceptions about this. When asked about having been approached with movie deals for her books she quipped:

“I wondered about the people who approached us for Merry. Have you read these books? I mean short of literally doing pornography, how could you do these books? I don’t know. I guess if you cut the sex out, and then, what’s the point?”

For anyone curious about her books, The Anita Blake series does get pretty good, but at the start of the series you can tell she hasn’t had much writing experience, and now fifteen books into it the writing is good but you’re wishing she’d leave the excessive sex in the Meredeth Gentry series.

 
 

Szechuan Shredded Vegetables with Pressed Tofu December 2, 2007

Filed under: Uncategorized — masukomi @ 7:05 pm

Last night I got off my butt and cooked something interesting for movie night. The recipe was generally well received although I learned that most people don’t share my affection for ginger. Anyway, I’m posting this recipe here for three reasons: Jess was considering making it, comments need to be added to the instructions, and I need suggestions for improving it.

First the (vegan) recipe:
Szechuan Shredded Vegetables with Pressed Tofu
from 1,000 Vegetarian Recipes

Makes: 5 1/2 cups; serves: 4 to 6 [Kate: 4 to 6 very, very, tiny people]

1/3 cup vegetable broth
1 tablespoon soy sauce
1 tablespoon mirin or sherry
1 tablespoon corn starch
2 tablespoons vegetable oil
1 tablespoon minced fresh ginger
3 cloves garlic, minced
1/4 teaspoon red pepper flakes
3 cups julienned carrots
2 cups julienned celery
1 cup julienned snow peas
1/2 cup julienned scallions (white and green parts)
2 cups julienned, pressed tofu
1 teaspoon sesame oil.

Instructions:
1. In a small bowl stir together the broth, soy sauce, mirin, and cornstarch; set aside.
2. In a wok or large skillet, heat the oil over high heat. Add the ginger, garlic, and red pepper flakes; cook, stirring, 10 seconds.
3. Add the carrots celery, snow peas, and scallions; cook, stirring until softened, about 4 minutes. Add the tofu; cook, stirring, until heated through, about 2 minutes.
4. Add the soy mixture to the wok; cook, stirring, until sauce is thickened, about 1 minute longer. Stir the sesame oil.

Variation: Use julienned red or green bell peppers instead of - or in addition to - the snow peas.

Post Creation Thoughts:
First off this is an entree. The specified directions make 5 1/2 cups. There is no way in hell you can feed 4-6 people on 5 1/2 cups of anything. I doubled the recipe, served it with rice, and just had enough for 7. This is really easy to make but if you double the recipe, you pretty
much have to, you should know that 6 cups of julienned carrots is a
lot. You’re going to be julienning veggies for a while, and unless
you’re going to get your guests to help, buy shredded carrots, and
julienne everything else in advance.

Don’t bother julienning the tofu. Slice it, press it, throw it it.
Whatever shape you cut it into is going to get broken apart with all
the stirring. If you do the tofu in advance and let it sit in even more
moisture will seep out to the bottom thus saving you from having to
spend lots of time

The fourth instruction suggests stirring until the sauce is thickened. This means when you actually make the sauce your veggie broth has to be cold. Otherwise as soon as you add the corn-starch it starts to thicken immediately. Also, I think she’s smoking crack. There wasn’t nearly enough sauce for anything more than a thin coating so you’d never be able to tell if it was thickening or not. I doubled everything, but I’m thinking I should have quadrupled the sauce. It smells nice but it needs something. I’m thinking add sesame oil to this too.

Screw the celery. The celery adds nothing to except a little crunch. The only noteworthy comment about the celery was from someone who doesn’t normally like celery saying that he had no problem with it in this dish. I added julienned red bell pepper, next time I think I’ll forego the celery and just use the red bell pepper. Also, julienning scallions is not worth the effort; just cut them up normally, also you’ll get more surface area on your cuts which should bring out the flavor a little more.

The ginger: I added about 2 3/4 tablespoons of ginger for the doubled recipe (an extra 3/4). It was a bit much for people who weren’t ginger fans. I thought it was perfect and left your lips just barely tingly.

If you follow the official instructions you’ll end up with a bland thing-o-veggies that people don’t mind eating but aren’t going to be thrilled with. I like bland foods but with all the chopping I had to do it annoyed me, so I called in Miller to help spice it up. We added garlic powder, soy sauce, sesame oil. The latter two helped, I’m not sold on the garlic powder for this dish but it was a step in the right direction. My thoughts: more “soy mixture”, more sesame oil in that mixture, sesame seeds might be nice too. More red pepper flakes. I don’t like hot foods but there just weren’t enough in there to be worth bothering. Maybe a little bit more real garlic (not powder) the default amount doesn’t really stand out much I don’t think, and I actually added a little extra.

Mirin vs Sherry: I used mirin (should be wherever they hide the Asian foods in your supermarket), but couldn’t taste it. This was probably due to the fact that there just isn’t enough sauce in the default recipe IMNSHO.

The tofu had little to no flavor. Maybe let it sit in the soy mixture for a while before cooking, and/or throw it in for a minute after step 2

Wok, wok, wok. Don’t even attempt this without a wok. It’s a matter of sheer volume. If you don’t have a wok go get one. I don’t understand how people cook without them.