Archive for the ‘programming’ Category

How to write a bug

Tuesday, August 21st, 2007

In order to break my slump I thought I’d give a quick description of a project I recently worked on.  I was helping set up a demo of an application that was moved onto the fabric.  The app was written in C and we didn’t change any of its code.  We ended up running it by shelling out from Java to make it easy for the developers who didn’t know C.  The person asking for the demo wanted to see our reliability feature but didn’t want to see the usual hardware demo we give which involved pulling a power cord or network cable.  So I had to invent a software bug that would illustrate how an application can be made reliable by running it on top of Appistry’s software.

So to make a short story long, here’s what my first try looked like:

Random generator = new Random(System.currentTimeMillis());
if( (generator.nextInt() % 4 ) > 0 )

   doSomething();
}

The basic idea being that by generating a random integer in the code running on the fabric I could then use the modulo operator to inject a bug about 25% of the time.  Because it’s random, it would be unpredictable (the best kind of bug).  The modulo operator would give me values from 0-3 and therefore if I got a 0 I would run the bug:

else
{
   throw new Exception();
}

The error case just throws an Exception because the fabric will attempt to retry the job if an unchecked exception is thrown.  We tested out our new bug and it didn’t work.  It was running the error case way too much.  So basically I had a bug in my bug.  After reading the javadoc on the Random.nextInt() method I figured out that it will generate negative numbers!  So I added the following fix:

if( Math.abs(generator.nextInt() % 4 ) > 0 )

Now I get my 25% failure rate like we wanted.  We show the client running and submitting a handfull of requests to the fabric.  Then, on the log on, the fabric, we show in realtime that the failure randomly occurs.  But when it does, the job is automatically resubmitted on the fabric and the answer is sent back to the client.  The client doesn’t have to be concerned with retry logic and only gets its correct answer.

I thought a cool web demo would be to use Ajax and setup a button for people to cause a software bug to happen while the results are coming back to the browser in realtime.  Maybe I’ll write that in my "spare" time…

-jasen

My first program

Friday, July 6th, 2007

I have some friends that run the online community GrupThink. I went and signed up for an alias and added a grup for posting programming cookbook questions and answers.  The Perl Cookbook was the most valuable book to me when I was learning Perl and I always look for content like that when picking up a new language.  I envision people posting questions and getting replies with code examples.  It could become a repository for multiple languages…or not…whatever.

I posted the first question asking how to write an infinite loop in BASIC.  My first 100% original program was this:

10 PRINT "KMart Sucks!"

20 GOTO 10

I used to type that in on the computers on the shelves and then walk around the store for awhile.  The monitors would be scrolling with the message and there was no way to stop it unless you knew how to break the interpreter or shut the machine off.  I caught employees several times shutting the machines off which made me very happy, it meant that I won.  I must have been like 10 years old when I was doing that stuff.  What a nerd.

JavaOne ‘07 - Day 1

Tuesday, May 8th, 2007

So I’m at JavaOne, the Disneyland of Java.  We arrived a day early to setup our booth today.  There are a few shipping issues, some missing signs, etc.  but that is par for the course at shows, as far as I can tell.  I haven’t seen one without some type of last minute issue that resolves itself the next day.  But the tech part of the demo is working.  The development team, whom I have high respect for, delivered our most common demo with Spring integrated into it to correspond to our announcement for the show.  We have the ability to take a normal Spring application and deploy it on our fabric with no changes to the underlying code, which is consistent with the Spring philosophy (and Appistry’s as it turns out).  So we have this cool Swing app that sends a bunch of transactions into a fabric of machines that we truck around to these shows.  The development team took that app and converted it to a Spring app, and then put that on top of our fabric so that we can demonstrate code running on Spring with our dependability and scale it out on commodity hardware.

So yesterday I started debating as to what the dress code should be at JavaOne. I said jeans and t-shirts, the Sales and Marketing guys said khakis and dress shirts.  Today as I was walking around the floor with our VP of sales I pointed out the preponderance of people wearing jeans and t-shirts or jeans and whatever.  He pointed to one group of five people and said there were two wearing khakis.  I said one of those was wearing cargo pants so it counts for me, not him.  Tomorrow I’m going to wear jeans and a dress shirt in a blatant compromise.  If the majority of people walking up to our booth are dressed down in the standard programmer uniform, then I’m breaking out my OpenBSD t-shirt.  Remember the days when wearing ultra casual clothes meant you were so good at coding that you could wear whatever you wanted?  I had a boss once that accepted an interview as a favor when he was younger.  He didn’t want the job so he showed up in shorts and a tank top.  They thought he must have been so freakin smart that they fell all over him and did everything they could to hire him.  Man, I wish those days would come back.

I read in the paper this weekend (yes the paper, it comes to your house and is made from trees) that the telecom market is growing again based on high bandwidth applications.  I’m going to call this the "YouTube Effect" and hope that I’m the first one to say that.  Maybe we’re around the corner from actual sustainable technology growth?  That would be awesome, engineers being highly prized but without the bubble this time.  Just smack anyone that starts day trading tech IPOs at outrageously inflated values.

So anyway, day 1 at JavaOne was all about getting my cool "Java" backpack and a tshirt that won’t fit me.  But my stuff works, so I’m good to go.  Tomorrow we’ll take the nice JavaOne shuttle to the Moscone Center for our complimentary exhibitor breakfast and work the booth.  There are a couple of cool sessions that I want to find time for; they actually are scheduled all day until after 10:00pm.  My wife thought they’d end early so people could go see the sights.  I was like, "No these are uber-geeks and we want 12 hours of tech sessions all week because that’s how we roll."  Actually I said nothing like that, but I like to pretend how cool I sound retroactively.

See you tomorrow.

-j

Will I dream Dave?

Wednesday, May 2nd, 2007

I thought the memorable line from 2001: A Space Odyssey would be a fitting title to my first blog post.  Mostly because it was one of the main influences that led me to become a computer geek.  I remember spending sleepless nights wondering how a machine could dream.  Of course I didn’t have the benefit of a college education and multiple sci-fi books to contaminate my imagination back then.  I think I finally decided it was possible, but it would probably require more computational power than what my Commodore VIC-20 could manage.  A few years later I became enthralled with the Apple Mac SE-30, it was based on the Motorola 68030 processor and I had to have one.  Well, I didn’t have that kind of cash back then, so I had to wait about 20 years until I could buy one for $2.00 at a used computer store.  I still want to get apache running on it so I can server a web page from the coolest computer ever.  Maybe I’ll do a blog post on that sometime.

Anyway, after reading the last paragraph you probably have a pretty good handle for how much time I spent alone in my room between the ages of 9 and 33.  I’m still imagining how to make a computer dream I guess.  I plan to use this space to talk about all kinds of cool technology.  I’ll post a lot about Java and related technologies like Spring.  I’ll also talk about Perl, Python, C++, design patterns, natural language processing, agile software processes, artificial intelligence, and any other cool topic that crosses my mind.

Working at Appistry has afforded me the opportunity to build my own virtualized fabric in my house.  So when I start discussing something like lambda reduction and show some code samples, I’ll probably expound on the idea of how I used it on my application fabric to solve some cool problem.  If anyone thinks of something fun to do on a virtualized grid compter, let me know and maybe I’ll give it a try and write a post about it.