Verifying Results in Tests

5. March, 2009

So you finally got yourself writing a test against a database. In the test, you have to verify that a row in the table is correct, so you write:

assertEquals (
    "2008-09-16-13.50.18.000000;;;;1;2008-08-07;2008-08-07;JUNIT;2008-09-16;t0001;001;;Doe;Jane;;Street;2;Doe Jane;;;;;X;2575;John;;;;US;E;;01;;;;125;01425;0;Shop;;;DOE;JANE;JOHN;032;1;;0001010301;;;;",
    dumpRow(key));

and it sucks. Yeah, junit will notify you when something in that row is wrong and if you have a cool IDE, you can even compare the fields … but it still sucks. If one of the fields in the middle change, you have to scroll and eyeball-diff, wasting your time. The solution is pretty simple:

assertEquals (
    "2008-09-16-13.50.18.000000\n"
    + "\n"
    + "\n"
    + "\n"
    + "1\n"
    + "2008-08-07\n"
    + "2008-08-07\n"
    + "JUNIT\n"
    + "2008-09-16\n"
...
    dumpRow(key).replaceAll(";", "\n");

Instead of dumping the data in a single long string, split it into lines so you can compare fields side by side and without scrolling sideways.


Subtext: Visual Programming, New Angle

2. March, 2009

If you have no idea what subtext is, lean back and watch this presentation.

It’s nice to finally find another person concerned about the state of programming languages. I started with C, toyed a bit with some other languages, moved to Java and today, I’m working mostly with Java, Groovy and Python. I’m doing all my spare-time code in Python. Why Python? Because I get more bang for the key press. And my spare time is most valuable.

So while I thoroughly agree that the idea of subtext is convincing, it’s too limiting at the same time: There are simple problems which you can’t express well in subtext, for example: A switch with 10 cases and some complex code in each case. It would just become too wide. The same applies when formulas have more than ten parameters. Your flow tree looks nice but it takes more screen real estate than the “traditional” version.

So my argument is that we need a way to choose. Software projects need to give up the holy grail of “one language to rule them all.” The IDE should allow to mix and match various languages and more complex “objects” like tables, rich text, animations. Why do I have to waste my time formatting tabular content in a Java file (think array of values) when I can have Excel? Why can’t Java read the data directly from Excel? Why can’t I embed Excel tables in Java source code and access them like a 2D O array? Why can’t I use a rich word processor to write my comments? Why is TAB 1-8 spaces instead of “one level of indent”? Why do I have to use braces when I already indent my code?

Because our computers are not powerful enough today. With every key we press, we have to worry about RAM and performance. Because companies still believe in lock in. Sun would probably add a cross-platform COM API into Java but will Microsoft port Excel to any platform where a Java compiler is available? Oh, we could use OpenOffice. Let’s see. People working for a software development company that has more then two employees: Comment here if your company policy allows to use OO instead of Office. Now let’s see how long it takes to get 10 comments.

In the end, what we have today is the most simple thing that actually works and doesn’t take too much RAM. I hope the time is ripe for the next step. I’m sick of fixed-width fonts, curly braces and source code which is 1% functionality and 99% “make the damn compiler happy”.


Guinea Pig

25. February, 2009

Disclaimer: This is a cynical virtual diary of my journey through Fallout 3. If you don’t like strong language or cynicism, this is not for you.


Moira actually talked me into becoming her guinea pig. Isn’t that what women are for? The things I do to get get laid …

The first task was simple enough. Go to this old supermarket and kill everyone inside. You didn’t believe when she said “abandoned”, did you? I only regret that I didn’t notice the old protectron in the back earlier. Could have done some slice’n’dice for me. Instead I had to waste another bullet to be able to loot it myself.

On the way to the market, I ran over an old school. Yeah, over – not into. Think “bulldozer” instead of “tourist”. Why do these guys have to leave such a mess? I almost tripped in the pools of blood on the ground floor! One day, I’ll find a way to pick up a bucket and a mop. Then, they’ll have to clean the level before I kill them!

Found some new friends, too. Great guys from a “Talon Company”. They seem to be into field delivery of supplies. You know. Guns and armor. And bullets. Plus a little workout to make it worth my time. I like it. Right on, commander!

After returning, I had to stand in the cold, radiated water next to the bomb until I feel sick. I felt sick after a few seconds … can’t this old fool stop mumbling for even five seconds? I’ve been watching him. He’s standing there, slobbering at the thing as if it was the greatest invention since the big bang. The original one. You know? 14 billions years ago? That one. Right. Where was I? Oh, yeah, he’s standing there, mumbling, day in and day out, 24/7. I get fried by the radiation after only a few minutes but this guy … ignorance is blizz. It just seems that the radiation in the water ignores me ignoring it.

After surviving that mostly intact … I hope … thinking about it, I wonder what that trip did to my most precious parts … damn! Maybe Moira is a better actress than I thought. Anyway. I have to visit a playground in a minefield. Knowing that things ain’t gonna be so easy, I start my exploration of the city Minefield from the back side. And what would you know, there is this old cracker running around, firing bullets at me. Why is everyone so hostile around here? A headshot emphasizes my peaceful intentions. After that, I can loot to my heart’s contents. There is so much stuff, I can hardly walk back home.

If I was asked, I would be hard pressed to say whether I prefer to kill or to loot. Maybe I’d be happy with looting alone. It’s only that people are so egoistic. They only always think of themselves instead of me!


Java Tricks: Commenting Out Code

25. February, 2009

How do you comment out code? Using /*...*/? Using your IDE to put // before each line? There is a third method:

    if (0 == 1) {
        ... code ...
    }

Pros:

  • Nests
  • You need only change a single character to “flip” the comment: Replace the 0 with 1.
  • You won’t get warnings because of suddenly unused imports or local variables.
  • The Java compiler will remove this block of code in the optimization step, so no runtime penality.

Cons:

  • Can only be used inside of methods.

If you need a fast way to repeatedly comment in/out a piece of code elsewhere, use this syntax:

    //* Fast flip comment starts here
        ... code ...
    /* and ends here */

Inside of a /*...*/ comment, the sequence “/*” has no special meaning. To comment out the block of code, remove the first “/” in “//*”:

    /* Fast flip comment starts here
        ... code ...
    /* and ends here */

Wikianswers vs. StackOverflow

23. February, 2009

I’ve mentioned StackOverflow a few times. If you have a question related to software development, that’s the place to go. But there is no place to ask other questions.

Well, five days ago, wikianswers started and … there is still no place to ask other questions. I do not doubt that Jimmy Whales knows what he’s doing but for some reason, he didn’t notice Web 2.0. Yes, wikianswers looks nice (well, the top of the page does; let’s not go into the rest, especially the search results and such).

Obviously, this site runs on top of the MediaWiki software. While the guys on StackOverflow pulled every string to make it as simple as possible to ask and answer a question, I feel that the workflow on wikianswers drains a lot of my enthusiasm even before I get to answer a question.

Good luck, Jimmy! We really need a place to ask questions.


Shootout Cancelled

23. February, 2009

Disclaimer: This is a cynical virtual diary of my journey through Fallout 3. If you don’t like strong language or cynicism, this is not for you.


Talked to lots of people. Weirdos. Only this Mr. Burke seemed to a nice guy. He gave me some equipment to wipe this rotten town from the landscape. Hm. That gave me some cool ideas.

Messing with a bomb is more complicated than it looks. Nothing that a little help from my friends can’t fix. One pill later, the bomb is as dangerous as a paperweight. OK, one that glows in the dark, but hey, that only makes it more useful!

Now for the fun part.

I visit Simms. You remember Simms? The sheriff? The nice guy? Whoa did that change when I showed him Burke’s toys. I stay on his heels as he races to the saloon to have word with Burky. One word for you: Shootout. Yes! Finally! Haven’t seen fresh blood for several hours by now, getting itchy.

It’s great to watch that sleaze slime his way around Simms. I was laughing so hard, I almost couldn’t keep my 10mm pinpointed on Burky’s head.

But Simms was a big disappointment. Really. Instead of crippling Burky’s arms and legs, search him, one bullet in the head, and then ask questions, he turns his back on the guy! Oh well. Got what he deserved and I got all the goods from both of ’em. For only two bullets, too. Only … how do I get my house keys, now? And come to think of it … how do I know that Simms was supposed to give me the keys to “my” house … he never mentioned that when we talked. Odd.

Offered the ghoul behind the bar some really fresh meat but Gob (that’s his name) didn’t want it. Apparently, only zombies eat human meat. The things you learn out here! Amazing.

Time to cash some of the loot at Moira’s. Nice body in the blue skin. I feign interest in her stupid idea of a book. Hey! My girlfriend dumped me before I had sex with her! A man gotta do what a man gotta do, right? Right!


Mutation Testing

23. February, 2009

From the website:

How do you know your test suite is “good enough”?

One of the best ways to tell is mutation testing. Mutation testing seeds artificial defects (mutations) into a program and checks whether your test suite finds them. If it does not, this means your test suite is not adequate yet.

Read more about Javalanche on the website.


Just Got The Boot

21. February, 2009

Disclaimer: This is a cynical virtual diary of my journey through Fallout 3. If you don’t like strong language or cynicism, this is not for you.


First day. My girlfriend just gave me the boot. Threw me out of 101, too. Stupid bitch. Next time, she can kill her father herself. Why was he yelling anyway? I didn’t let my father just walk out on me. And I only clubbed ten or twelve or so of his security into a pulp with my baseball bat. Some people!

I wonder what I did yesterday. Somehow, I can only remember three days of my past life. Odd.

Blast. It’s so … open. And that sun. No good for my complexion. Wasn’t  there supposed to be an eternal night after a global nuclear war? Black rain, thick cloud layer, downpour? Maybe it wasn’t so global after all. Probably just a few big gun freaks speaking their mind about politics in D.C. With the little I remember from history 101, they’re probably heroes of the world, now.

Anyway. That red thing on sticks is a water tank. Contaminated water. Great. Just what I need. Next, the food will be radiated, too! How did I ever deserve this?

Luckily, I ran into this town. Megaton. Built around a bomb. Weird. But funny. Megaton. Get it? Megaton? As in bomb? Ah, forget it.

The sheriff seems to be OK. But let’s not judge him to quickly. I’ll wait until he finds me in a big pool of blood. Someone else’s blood. Probably several someone else’s … but at that time, nobody will be left to worry about these petty details.


5’024

20. February, 2009

Just came in to find my reputation on StackOverflow.com has reached 5’024. Sweet 🙂


Things You Can’t Do Anymore After 9/11

19. February, 2009

A few years ago, I helped a friend out. He was working for a small project of a guy, let’s call him Tom, in Munich to build a system to etch waver masks with plasma. The setup was simple enough: A standard PC running Linux with a very simple control language which would send commands to various devices attached via the serial bus. Piece of cake. My job was to complete the “read the recipe” and “send the commands to the devices” (plus read some status data back).

If you’ve ever been in contact with Linux, you know that the words “hardware driver” can cause nightmares even today and that was 1995! Linux 1.2! one-point-freaking-two. After eight hours of frustration, I considered my options: Hack the kernel (and the multi-IO driver in it; only the driver I needed was closed source), give up or try a different hardware with a better driver. Did I mention that the whole thing had to be ready for oversea delivery by 14:00 the next day? Piece of cake.

I pulled out a Linux magazine and browsed through the ads (Finding companies on the Internet? 1995? You’re joking, right?). Lo and behold, there was an ad from a company which was selling eight port multi IO cards. I checked the kernel docs for this card. There seemed to be an open source driver. I checked the clock. 18:00. I checked the address. Hamburg. OK. That might just work. I called the company. Ring … ring … ring … YES! Okay … I didn’t get someone from the company but a security guy. He knew what I was talking about and he was willing to sell me one … but I had to pick it up. Hm. My mother is from Hamburg. One call later, I had the number of an old school friend of her’s. Let’s call him John.

Ring … ring … ring … come on … ring … Yay! He was just back from work, I had literally got hold of him with the door key still in his hands. I explained the situation to him: “Can you pick up a package at [some address], go to the airport and put it on the next airplane to Munich? Oh, I’m the son of your old friend Barbara.”

“Sure,” John said, “can do.” A few minutes later, he was on his way to the north of the city to pick up the package. I called the security guy to tell him that someone was on the way.

Time passed. I called my mother’s friend. No answer. I called again. And again. I got nervous. Again. Oh-dear-God-thank-you, he answered. Things had been a bit complicated, he explained to me. When he arrived at the company, he had no cash, only a credit card. The guard couldn’t operate the credit card reader. After a short discussion, he would accept a written statement that the bill would be paid plus a copy of John’s passport.

Next, he went to the airport, just in time for the last plane to Munich. I had worried how to get the package on the plane but that hadn’t been a problem; he only had to pay for a full seat. Uh … OK. You try that now … my guess is that airport security will shoot you on the spot, not even bothering with trying an arrest. Anyway, the package was on it’s way to Munich. The plane would arrive around 23.00. The clock said: 21:30. Time to pick up the phone again.

Tom, the project owner, had had a meeting in Munich and was on his way back to us (we were in a small city some 20 miles to the south of Munich). Thank God for mobiles! He answered on the highway. We told him to turn back and head for the airport.

23:30. Tom called to tell us that he had the package and he was heading back.

0:00 I got my new toy. Nice. I checked the driver module which loaded perfectly into my kernel. I ran my tests again. They worked. They f******g worked right away after refusing to do anything for eight hours! Can you imagine my feelings? I wanted to scream in frustration and joy at the same time. Anyway. Time to get the recipes to work.

6:30 I have my limits and now, I’d reached them. Usually, I type blind but now, the stuff on the screen didn’t look what I told my fingers, anymore. I made more mistakes than I fixed. But most of the stuff was in place and a first simple recipe, which triggers every system at least once, ran through. An eerie blue glow filled the garage as the plasma comes to life. Cool. I wonder what the neighbors might have been thinking. Forgetting to close the chamber would cause every computer within a 10km radius to burn through. Cool. I drag myself to bed before that little devil in my head gets any ideas.

11:00 I’ve slept only a few hours but there is still some more work to do. When I arrive back at the garage, I find the machine gone. Panic. They have already started to take everything apart and shove it into a freight container. Uff. Whatever bugs are still left in my code will have to be fixed in Asia.

So they sent me home, my colleague would go to Asia. One of Tom’s friends dropped me off at a gas station on the autobahn. There, I asked the owner whether he could call me a cab. Strangely enough, he did, even without asking any questions or even asking anything for the call. Must have been the look on my face. Exhaustion, you know. I bought some sweets in return.

A couple of minutes later, a cab pulled in. The driver, a woman, didn’t seem to be too surprised to pick someone up close to nowhere. Huh. It was her second job today (and it was afternoon), the last customer wanted to visit Zurich. It’s interesting how cheap those far runs are, compared to in-city. We arrived at Meersburg just as the ferry was about to leave. I paid, left a tip and jumped on. On the other side, the bus was already waiting.

It was a mad ride but a very satisfying one. In retrospect, it is a miracle that everything worked out, so much could have failed. I got some money out of it, too, which I invested in stock. It was a fixed date transaction and a few days after I got paid out, the stock market took a steep plunge.