May 14

The Story Begins

In which our intre­pid (or is that tepid?) Hero finds him­self on the shores of the Sharp Sea look­ing through the Windows to the Presentation of the Foundation of all things.

Last time I men­tioned that I was work­ing on a project to sim­pli­fy con­fig­ur­ing our main prod­uct and that I decid­ed to make it a reg­u­lar Windows appli­ca­tion instead of a (shud­der) VBA application.

I like learn­ing com­put­er lan­guages and so I thought that this would be a good time to learn C#. I had dab­bled with it over the years and had writ­ten some small pro­grams in it, but noth­ing serious–nothing that required learn­ing the details or the dark recess­es of a lan­guage. And with 3.0 out I fig­ured I could learn about all the cool new fea­tures. That and I just can’t bring myself to use Visual Basic. It is a pow­er­ful lan­guage with some neat fea­tures but it just brings up too many old, painful mem­o­ries.1

So I fired up Visual Studio and told it to cre­ate a new Windows Forms Application.

Hey, what’s that WPF Application template?

Oh, that is Microsoft’s lat­est attempt to make a good UI library. It’s just anoth­er rework­ing of their old stuff. Don’t wor­ry about it.

Shouldn’t we at least look at it and see if it’s any bet­ter? I mean learn­ing some­thing new is fun and it’s one of the rea­sons were doing this on the side.

No, we know some­thing about how Forms work and we don’t have the time to learn a com­plete­ly new sys­tem if we want to show some­thing soon to con­vince peo­ple not go the VBA route. Don’t wor­ry it will all be fine.

OK, if you say so… 

Talking to my inner self can be annoy­ing. Where was I? Oh yeah, the appli­ca­tion solu­tion was cre­at­ed. Add a few sup­port projects, steal code from oth­er projects, rename a few things, and com­pile. Yay it runs!

Time pass­es…

Microsoft annoys me.

You talk­ing to me?

Yeah. They’re real­ly big, have very tal­ent­ed peo­ple and they still cre­ate com­plex, hard-​to-​use stuff like this. It’s a real pain to get things on the win­dow, look­ing nice, and be func­tion­al. You have to write so much code. Ugh.

You know, there is the thing I heard about once…I’m think it was called WPF. Someone once said we should look at it. I can’t remem­ber who…

OK, OK. I get the mes­sage. Just to make you hap­py I’ll take a quick look, you’ll see that it’s just the same old stuff repack­age like always and we can get back to mak­ing this work.

Thanks, this will be fun… 

Fire up a new solu­tion, this time a WPF Application. Looks pret­ty much the same, an emp­ty win­dow. OK, the tool on the left look pret­ty much the same, maybe one or two new things. Nothing sur­pris­ing there. I guess it time to read up on this. I’ll give it an hour or so.

Time pass­es…

OMG, this is even more com­pli­cat­ed than Forms! Look at all the options and settings!

Time pass­es…

Wait, bind­ing? Like Adobe Flex? We liked bind­ing in Flex.

Time pass­es…

Item tem­plates? Data tem­plates? What?

Time pass­es…

I’ve got it! I get it! Wait! Microsoft made this? This is…good. This is…right!

I told you we should look at it.

But it was just anoth­er “Microsoft threw too many peo­ple at the prob­lem” thing. How could I have known?

You should lis­ten to me more you know. This half the brain has good ideas too you know. 

The Recap

For those try­ing to keep track, I, like many oth­ers, do not have the most favor­able opin­ion of Microsoft prod­ucts. I do have a lot of respect for the peo­ple who work for Microsoft. Some of the bright­est stars of my field (soft­ware devel­op­ment) work for them. But in my opin­ion, the com­pa­ny some­how man­ages to infect them and caus­es them to pro­duce things that are, shall we say, not so good. I think that it may have some­thing to do with bureau­cra­cy and iner­tia, but what­ev­er the rea­son, I am not a fan of most of the prod­ucts that have come out of Microsoft for the last few years (many years in fact).

But WPF changes all of that. Now mind you, it is not per­fect. There are some things I would change but over­all this is how a win­dow sys­tem should be. The sep­a­ra­tion of con­cerns, the sim­plic­i­ty of exe­cu­tion (once you get over the “how does it work” hump), and the abil­i­ty to change just about every­thing is fan­tas­tic. As time goes on and I learn about new fea­tures in the sys­tem I go “wow that’s great. I wish I had known about that before.”

And the great thing about this is that it works as a Windows appli­ca­tion and a brows­er appli­ca­tion. And with Silverlight using the same basic tech­nol­o­gy I see great pos­si­bil­i­ties ahead.


  1. The new Visual Studio 2010 is going to include F# as a stan­dard lan­guage. Finally a func­tion­al lan­guage may become main­stream. I miss Scheme. 
May 12

Something a Little Different

For the past few years I’ve been using Java for the major­i­ty of my pro­fes­sion­al and pri­vate devel­op­ment. Using it pro­fes­sion­al­ly was sim­ply because that is what my com­pa­ny want­ed. Privately was because I was using it pro­fes­sion­al­ly and so the envi­ron­ment was there and start­ing up a new project was easy. Java is a good, sol­id lan­guage with a pletho­ra of libraries and sup­port but every time I went to make an appli­ca­tion with a nice UI I was stymied. Everything just seemed hard to do in Swing—much hard­er than it should be.

Recently, I was put on a new project at work. For this project we are build­ing a sim­ple con­fig­u­ra­tion tool for our main prod­uct. Configuring usu­al­ly requires gath­er­ing lots of sim­i­lar items and so some­one thought that Microsoft Excel would be a good plat­form. One of the biggest things that it had going for it was that it was the tool that the require­ments gath­er­ing peo­ple were already using. They were just using it to col­lect the tables of data, but with no pro­grammed sup­port. The they would give that infor­ma­tion to some­one else to input into our con­fig­u­ra­tion files. So, some­one thought that it would be a help­ful idea to auto­mate many of the steps they went though and gen­er­al­ly improve the expe­ri­ence. The only prob­lem was that they used VBA.

VBA is a great macro lan­guage, but as a tool for build­ing appli­ca­tions it sucks. It real­ly just blows. Try hav­ing mul­ti­ple peo­ple work­ing on it at the same time. And this was the project that I was put on. Oy.

So to keep myself sane I decid­ed that I would look into alter­na­tives. As this was a tool tar­get­ed at a small group of peo­ple (say 20–30 peo­ple total) and all of these would be on some form of Windows I fig­ured that we should just go ahead and make this a full Windows appli­ca­tion. I had dab­bled with C# and GDI so I thought I’d try my hand at mak­ing a tar­get­ed appli­ca­tion (while work­ing on the VBA/​Excel debacle).

So the next few entries will be my expe­ri­ences with doing an appli­ca­tion not in Java. We’ll see how it goes.

Feb 15

Google phone interview part I

I applied for a job at Google and thought I’d write about my expe­ri­ences with their inter­view process. Many oth­ers have writ­ten about the process and my expe­ri­ence was sim­i­lar to theirs. I sub­mit­ted my resume through their web site and even though the mar­ket isn’t great right now I got a response from one of their recruiters who I’ll call Carol.

Carol informed me that I had passed the first round by sub­mit­ting a resume that was good enough to ring some bells and that she was sched­ul­ing me for a phone inter­view. Right away my heart start­ed pounding—I heard about these myth­i­cal phone inter­views from the web. These minia­ture tort…er…interrogation ses­sions were renown for their abil­i­ty to bring even the might­i­est of us to tears.
 
“How about Wednesday?” she asked. “Wednesday is fine” my finely-​tuned grey mat­ter spit back with­out con­sid­er­ing a) I would be out of the area (oth­er peo­ple would call it a vaca­tion), b) it was only 4 days away (five if you count the day of dri­ving to get to my des­ti­na­tion), and c) I had­n’t talked with my wife about it. So not only did I not ask for more time but I had just com­mit­ted to spend­ing most of my (our) vaca­tion pre­ping for a mini inqui­si­tion. I could hear the con­ver­sa­tion in my head: “Oh hun­ny,” I would say to my wife, “you know those longs walks in the woods you were plan­ning on…well…and, ha ha, this is sooo funny…you see, he he…I just agreed to do a phone inter­view, ha ha, on Wednesday, he he, that, ha ha, I have to spend every (snick­er) hour of every day study­ing for! Isn’t that great? Hunny?” Yeah right. I’m a dead man.

Luckily I’m mar­ried to an under­stand­ing woman who decid­ed to be supportive—so sup­port­ive that she drove (she hates dri­ving on long trips) and had me study on the dri­ve up. She also had me research­ing the web for tips. Does any­one else see the irony of using Google to search for “Google phone interviews?”

So the big day arrives. I have my phone ful­ly charged (yeah I’ve had the phone dies in the mid­dle of the impor­tant phone call), I have my notes, and most impor­tant­ly I have my pre­ferred caf­feine deliv­ery sys­tem: Coke. In fact I’m on my sec­ond when my wife says “Did you check to make sure the cell recep­tion is good?”

Cue the dramitic music and zoom in on the bars on my cell. At this point one could ask “what bars?” but I’m not sure that my heart could take that. “NO BARS!!” I screech not real­iz­ing that the human voice can actu­al­ly hit that high a tone. My wife looks at me like I’m…well…stupid. “You know it does­n’t work on the first floor. Go upstairs and check.” My wife is very patient. I get upstairs and look at the phone with trep­i­da­tion. One bar…two bars…three bars!…no two bars!..no three!…two…

I’m not sure how long I stood there watch­ing the third bar flick­er in and out until I real­ized that the best recep­tion is in the bed­room and I go in there. Yay! Four Bars!!!

I should men­tion at this point that the place we are stay­ing is out­side of Klamath Falls, OR and that there are hills between us and the cell tow­ers. There is one low spot that seems to line up with the bed­room on the sec­ond floor. I know this as we have been there sev­er­al times. I’m an engi­neer, OK a soft­ware engi­neer, but I under­stand the prici­ples and yet I can’t seem to get my brain wrapped around this and I’m about to take what is reput­ed to be a tough phone interview.

My phone rings. I’m doomed.

Jul 23

Java Complexity

Java as a lan­guage is get­ting more com­plex with each ver­sion. From ver­sion 1.0 to 1.4 most of the com­plex­i­ty was added through libraries. Thousands or lines of code were added in hun­dreds of new class­es. But this com­plex­i­ty was contained–if you did­n’t need a fea­ture you could ignore it com­plete­ly. At worst, you might miss out on some new, neat fea­ture. But start­ing with 1.5 the lan­guage itself changed (OK 1.4 added asser­tions but that’s a very small fea­ture that can be read­i­ly ignored).

Version 1.5 added enums and Generics. Enums are a medium-​sized change, main­ly a way of list­ing enu­mer­a­tion val­ues, but there are sub­tleties that make them com­plex (like con­ver­sion to/​from inte­gers, access­ing all the defined val­ues, etc.) Generics are a big change. The fact that all the col­lec­tion class­es were retro­fit­ted to be gener­i­cized1 means that most new code will have to deal with them whether they want to or not. Trying to ignore them just results in streams of warnings.

Now with 1.7 or maybe 1.8 we are talk­ing about adding clo­sures and pos­si­bly con­tin­u­a­tions and prop­er­ties. If you think that code with gener­ics is hard to read then just wait for clo­sures. The sub­tleties of where a braces goes to decide if a clo­sure is being defined is guar­an­teed to cre­ate uncer­tain­ty and confusion.

My ques­tion is “are we adding too much com­plex­i­ty?” The thou­sands of lines writ­ten for the libraries before 1.5 are extreme­ly use­ful and in fact are still used after 1.5 so gener­ics, enums, and clo­sures are not nec­es­sary for use­ful code. So why do we see the need to add this complexity?

When I start­ed using Java I thought it was a nice sim­ple lan­guage for writ­ing web tools but that it was­n’t a “real” lan­guage for use in “real” work. But then I start­ed using it for a real project and I real­ized that it might be a sim­ple lan­guage, but it could do what I need­ed. Granted pre‑1.2 things were a lit­tle coarse but by the time 1.2 came out things real­ly start­ed to smooth out. Then as I used it more I kept think­ing “this is a bor­ing lan­guage; it has no fun fea­tures.” Years lat­er, as I have got­ten old­er, I have begun to recon­sid­er my eval­u­a­tion. Yes, Java is a rather sim­ple lan­guage, but that may be a good thing.

I like func­tion­al lan­guage as I think that func­tion com­po­si­tion is a very pow­er­ful fea­ture that results is small­er code bases. But when I look at what’s com­ing in future releas­es I start to wor­ry. Here where I work we have devel­op­ers of dif­fer­ing lev­els and I have seen them have prob­lems with even the sim­ple things in 1.4. Complex fea­ture like Generics are going to make it hard to keep every­one up to the nec­es­sary lev­el of competence.

Even though I was one of those clam­or­ing for Generics I am now not so sure that they should have been added to the lan­guage. I con­sid­er myself a senior devel­op­er and while I am now com­fort­able, but not an expert, with using gener­ics it is such a big change that I would say that Java 1.5 is actu­al­ly a new lan­guage. As a senior devel­op­er I have no prob­lem learn­ing new lan­guages and in fact I learn new ones for fun. But think of the junior and even mid-​level devel­op­ers. May of them are still try­ing to get a han­dle on the base language.


  1. I know this isn’t a real word yet, but it is becom­ing preva­lent in the busi­ness and it seems to be the right word for this sit­u­a­tion. 
Jul 17

Java Generics III

Last time I talked about using gener­ics to make get­ting val­ues out of col­lec­tions nicer (and a pro­pos­al that would obvi­ate their use) so this time I want to talk about the oth­er half–passing items into a col­lec­tion. This encom­pass­es all meth­ods that take a para­me­ter of the col­lec­tion’s gener­ic typ­ing includ­ing those that add items to the collection.

If you look at the byte-​codes gen­er­at­ed for call­ing any of these meth­ods you will see that there is no run­time check­ing of the objects being passed. This is because the meth­ods of the base object are defined as tak­ing Object types. The only check­ing hap­pens at com­pile time. So as long as the sta­t­ic type is cor­rect every­thing is fine but it is easy to over­ride the sta­t­ic type (acci­den­tal­ly or on pur­pose) so what hap­pens? Well, if you attempt to retrieve a val­ue from the col­lec­tion and the type is not assign­ment com­pat­i­ble with the tar­get then you will get a ClassCastException.

Let’s think about that for a moment. The excep­tion is not thrown when the invalid val­ue is added to the col­lec­tion (when track­ing down the error would have the con­text of the sit­u­a­tion) but when it is removed (or exam­ined). This defeats the basic rule of “fail as ear­ly as pos­si­ble”. It also means that a state­ment with no cast oper­a­tor can fail with a class cast excep­tion. This seems counter to the spir­it of the lan­guage and in fact leads to con­fu­sion. You look at the line that the stack trace points to and say to your­self “there is noth­ing there that can throw a class cast excep­tion.” After a this hits you a time or two you will remem­ber but why should you have to make that effort?

I will grant that the gener­ic def­i­n­i­tion does make it hard­er to acci­den­tal­ly put in the wrong thing, but it does­n’t elim­i­nate it entire­ly. If we are going to have a checkcast byte-​code on retriev­ing the val­ue then why don’t we have it on putting the val­ue in as well?