Archive for category development

The usual suspects

Whenever I’m presenting anything, I try to start off showing the “Top 20 replies from a programmer when their programs doesn’t work”. In case you’ve never seen it, here it is:

It works on my machine.

Where were you when the program blew up?

Why do you want to do it that way?

You can’t use that version on your system.

Even though it doesn’t work, how does it feel?

Did you check for a virus on your system?

Somebody must have changed my code.

It works, but it hasn’t been tested.

THIS can’t be the source of THAT.

I can’t test everything!

It’s just some unlucky coincidence.

You must have the wrong version.

I haven’t touched that module in weeks!

There is something funky in your data.

What did you type in wrong to get it to crash?

It must be a hardware problem.

How is that possible?

It worked yesterday.

It’s never done that before.

That’s weird…

I’m not quite sure who wrote it originally, but I was given a paper copy several years ago. I must admit I had a good laugh at the time, as I could relate to most of the replies.

So whenever I’m presenting this list, there’s a giggle and a great deal of nodding and smiling going on in the audience. Then I go on to present something that will alleviate one or more items in this list.

But it’s not a laughing matter! It’s the sad state of our beloved profession we’re laughing at. It’s not supposed to be like this.

The Dream

When I’m presenting the list in 10 years from now, there’s not a giggle. Not a smile. Just silent shame of times past or loud laughter at good ol’ days. Hopefully no one doesn’t even recognize the items on the list.

I might have a different kind of list. But not this one. We have made progress.

The worst part of this is that most of these are solved problems. Test Driven Development, Continuous Integration, and Pair Programming have existed a decade. Their poorer, but still useful cousins, Unit Testing, Automatic Builds, and Code Reviews have been around the block even longer. Iterative and Incremental development, Miniature Milestones, and Review and Adapt has been grown ups for a while as well.

So there is no excuse. The answers are at your doorstep. But it takes discipline. And time.

But you’re not alone. I’m off trying to do my part. Our mission is clear. Will you do yours?

According to Steve McConnell in Code Complete 2 it is just fine with regards to putting the most probable clause first. But it is also an anti-pattern in this case; arrow code. With even more nesting it gets worse, and it starts to get nightmarish to follow the possible execution paths.

Introducing Guard Clauses

A guard clause is a conditional which constitutes our first line of defence in our methods. It can break control flow in an elegant matter, so the only thing left to follow is the valid execution path.

There is also nothing wrong with more than one return path in our methods, as long as it is as clean as it gets with guard clauses. Atwood seems to think so as well, so I’m really home safe here ;-p

Recently, we have gotten a couple of “fresh out of school” employees, and here the other day we went through the code of one of our applications and explained how it was built (at least how was supposed to be or “do as I tell you, don’t do as I do”).

Our O/R-mapper returns a generic Collection<T> when it is asked for a list / collection of some objects, and is consistent in doing so. The question however, was why that wasn’t a List<T>.

I had to admit I hadn’t dug into the material properly, so the question kindof got left there in open air. My bad excuse was of course I had been mostly doing managment stuff lately, and so was my companion presenter as well.

So to make a not so long story short, I had to dig into the collections that is found in .NET, and I explain them to myself for later reference, beginning with the aforementioned Collection<T> and List<T>.

The difference

Just to sum it up, Collection<T> is made for extensibility and List<T> is made for performance. See this and this from the FxCop guys.

The starting point

A pretty standard API involves a factory and an add-method. In between the New/Create method call, we usually set some properties on the created child object. When we’re done, we add it to the collection of its parent/container. The factory and the parent/container are often collocated. Below is the standard API I had as a starting point.

Look at the above code and then tell me you haven’t done it before. Bleh… In the above code I’m setting up a ribbon menu structure (as found in various Office 2007 products). The code is tedious to write, and there’s a lot of it. So what if I tried to wrap the API so I could set up my ribbon menu more elegantly, and how do I do that?

The result

I’m going straight to the point and I’ll show you the resulting code. (Because I’m really pleased with it and must share it!) One thing I additionally might do is to resolve the image implicitly from the name inside the configurator to make the footprint even smaller. Oh, and please don’t get hung up on the literals. I’m trying to get a concept across here, give me a break!

In my last post I mentioned that I’ve been doing a lot of catching up on the technology side of things lately, and when I started out reading blogs I quickly realized it was a lot of ?LAs (1,2,3,4,5,.. Letter Acronyms) that I didn’t grasp or understood.

So I made a list of every ?LA and buzzword I didn’t know about while reading (and didn’t need to because of context at the moment), and I’m now at a point where I want to grok’em. I also wrote down things I had heard about or just scratched the surface on, which I wanted a clearer view of.

One by one, I’ll describe them in my own words. I’ll provide pointers to references where I found useful information and I’ll let you in on what detail made me go “Oh, a-ha!”. The list can be found here.

I’ve been steadily increasing my knowledge of SD during my career, but just now I found yet another way to squeeze in some more learning.

So I thought I’d share how I’ve been learning earlier and how I’m acquiring new knowledge these days.

The early years

During my college years I was laying the newly discovered internet at my feet. I had a huge interest for the hardware part of computers, and was an avid reader of Tom’s Hardware and Anandtech. This of course wasn’t a drawback as I worked part-time in a local pc hardware shop as technician and seller. So via classical web pages I was ploughing the local hardware fields. I also had a subscription to the Norwegian version of PC World magazine at the time.

At the time I also discovered Amazon, where I could find great books on .NET and ASP.NET in particular which I was in love it. I bought Alex Homers first ASP.NET (Wrox) book early on, I even submitted a “bug” in the book and I think it still there on its errata. It seems that Wrox denies the books existence, as they doesn’t have it on their web pages. I guess it was replaced by the Professional ASP.NET 1.0 book from 2002. Anyway, here’s a link to the original BETA book!

Fresh professional

The first flirt with IEEE was during my master thesis, and for quite some time after graduation, I had “forgotten” all about it. We had full access to the vast library from IEEE at the University, I remember I had no idea so much had been written about my specific field of interest, and was amazed at the time.

During my first year as professional I had little or no time to further educate myself except the occasional web-browsing you do during death marches. So my main source of mental income where of course from my colleagues.

Making the leap

I hadn’t been developing professionally for long, before I was promoted way past my level of incompetence. I was suddenly the company’s developer manager and I was terrified at first. So to compensate for my incompetence, I scouted the web again for useful information on how to succeed. At least I had the clear sight to see my shortcomings, and make up for it after the fact, which of course is useful at any given time.

I turned to Amazon again, searching for management books in general, software development management books, etc., you name it. A couple of colleagues had heard about Scrum, so I tossed a couple of books about that into my shopping cart. In my search I also found other books, in particular from Steve McConnell which had gotten great reviews. From there it was just the snowball effect, Amazon makes a great salesperson with all its semantics on its books. I ended up with 10 books, and that Christmas I didn’t do much but read!

So with my hard-earned death march experience, possibly natural management talent, a fresh literature study, and a big pile of beginners luck, my management career was of to a flying start.

My brief encounter with IEEE was at this point also coming back to me, and I applied for a personal membership that same Christmas, and we’ve had an ongoing romance since.

It wasn’t long either, before I found specific websites where I could find useful development management information, tips & tricks, and so forth. Joel on Software was one of the first sites I found, and it was a lucky strike.

Doing more managerial tasks, my interest was turned in that direction. I continued to add books to my collection from great people like DeMarco, Lister, Brooks and Yourdon. My technical reading was not up to speed as I had great confidence in my subordinates doing that for me. I still had to code some, but I was more an organizer, scheduler, project manager and so on at the time.

Time of change

Commuting for a 2+ hours a day can make your day pretty short. And it certainly didn’t get any longer when my second son was born. So I was tempted by an offer from a company closer to where I live. I left the firm I was part of building up, and started fresh in Norway’s largest consultant company in engineering disciplines.

Gone was my manager title, and I was back into the world of {} and ;’s at full throttle. And I went off into the web to get up to speed on the technical side of things.

I browsed the usual suspects (Amazon) and found new books to silence my hunger. The theme of books this time was architecture, design, and construction. I should really mention Martin Fowler, which I got a couple of books from. I was tossed into ASP.NET 2.0 and AJAX development project, so I figured I needed some reference work on that as well.

The present

After just a couple of weeks into my new position, I had turned to a several technically oriented web pages which all had the form of a blog. As I followed even more links from those pages, I figured out the beauty of RSS feeds. It wasn’t all unfamiliar, but now I grokked it and started subscribing to feeds through SharpReader.

I was thrilled, much like when I first saw the IEEE library. There were lots of bloggers out there with great things to say about nearly everything I potentially could be interested in. Here I could really see what the innovators and early adopters where doing in our community. So blogs are definitively a great place for information.

My latest addition in my toolbox of learning is podcasts. I still do some commuting, and what better way to fill that time than listening to interesting people talking about interesting subjects? Well, I’m hooked.

And to sum it up

The most important thing here is to never stop learning. Continuous Learning. That should really be the motto. So, to facilitate that today I use these primary sources:

Books

Magazines

Professional societies

Blogs

Podcasts

In a later blog I’ll get more in detail on the specifics in those bullets. Until then; happy learning!