Archive for October, 2007

Something Fresh

October 30th, 2007

As a .Net Developer, I spend a lot of time on Windows. I am fairly familiar with the Windows Desktop and Server operating systems. It can get a bit old doing the same thing over and over. While software development is by definition the building of new stuff, one can still become a little bored or wore down by doing the same kinds of things day after day. It is always wise to try to keep things fresh.

Recently, it has been easy to keep things fresh in Windows-land. Its a fairly exciting time to be a .Net/Windows developer with the rapid releases of Atlas (ASP.Net AJAX), .Net 3.0 (WPF, WCF, WWF), Silverlight, and the fast approaching .Net 3.5 and Visual Studio 2008.

New technologies like those listed above are like new toys to a software developer. For me, digging into WPF for the first time a year ago was in like getting a new iPod. It was a pretty new toy like the previously mentioned expensive electronic gadget, but didn’t really cost me anything other than time. I suppose WPF did cost me a little in money for the books I purchased, but those costs were already factored in for me as a developer.

Recently I have had the need to learn WCF. I have had the joy of a new book and a cool new technology with which I have spent the last month. Starting this week, it is Windows WorkFlow. In between work projects, I have been enjoying the Silverlight Alpha 1.1, Visual Studio 2008, and C# 3.0. There is plenty to keep the .Net developer hopping these days.

Microsoft isn’t the only game in town. I always encourage developers to build a Linux machine if they have not done so before. It can be difficult working outside of your comfort zone, but learning Linux/Unix is both fun and professionally rewarding. Things are done a little differently in the Linux world, and I have been surprised over the years the ideas for .Net projects that have sprung up from work done in Nix.

It used to be a bit of a challenge to get a Linux machine up and running. However, new releases make it dead simple. The people at Fedora and Ubuntu are building easy to install, richly featured operating systems. You can download these for free, and Ubuntu will actually send you a disk in the mail. Redhat offers virtual machine images of Fedora configured for various uses. They call these Linux appliances. We use just such an appliance at my workplace for our Subversions Source Control server, hosted in VMWare Server.

Of course if you are going to setup Linux, you will want to program on it. There are a number of programming languages that one can use on Linux. The obvious set of technologies is known as LAMP: Linux, Apache, MySQL and PHP. And the great thing about all of these is that they can be easily added to Linux during or after the initial install process. Out of the box, your Linux machine can be ready to program.

Keep it fresh, and I think that you will experience less burn-out programming and will be learn some new stuff along the way.

Good Books, Bad Books

October 28th, 2007

I love a good tech book. In an era where huge amounts of information can be found online, a good tech book can really cut through the confusion caused by contradicting or poorly written messages, articles and posts online. As a professional software developer, I feel that buying books are part of the job.

My brother is a professional diesel mechanic. He runs the shop for his company, and it is his responsibility to keep their fleet of trucks and other equipment running. As long as he has been into messing with mechanical contraptions, he has been buying tools. He started out buying smaller, inexpensive stuff. Over the years he has progressed to better and better tools. If he quit his job tomorrow he would have a fine set of tools (and tool chests) to take with him to another job. He also reads about mechanic stuff all the time.

Buying tech books is much the same to me. Some coworkers of mine over the years have argued that “the company” should buy the books. “If we need something, our employer should put up the money” they argue. While I don’t disagree with this view point, I have always felt that I should by tech books just like my brother buys himself tools. This is not an obligation that I feel I owe anyone else, it is an obligation I owe myself.

When I buy a new book, I empower myself. Dropping $35 at Amazon.com for each new book can get expensive, but it ultimately gets me ahead in my career. I don’t have to wait for my employer to deem a book worthy of purchase. I can read up on the topics that I feel are going to get me ahead, or that interest me. If I can pick up a good tech book and read a chapter or two every night for a week, I find myself weeks or months ahead of where I would have been without it. This has happened to me on several occasions in my career.

I think I have highlighted how valuable I feel good tech books are. So you can probably imagine how I feel about poorly written books, or books with bad/incorrect information, or both. I despise such books. They take up valuable space at B&N, they clutter up my search on Amazon, and they take money away from authors of good books. And they waste my time and money.

I usually rely on reviews at Amazon and other book resellers to help me make the correct purchase. If a book has very few or no reviews, I will often choose another book, or buy no book. Since I feel reviews are so important, I try to review all the books I purchase after I feel I have adequately read and used them. A tech book may be written in a very eloquent fashion and still contain poor information, so I hesitate to review a book until I have actually written some code or implemented some of the technologies discussed. However, I have purchased the occasional book that is so bad that I write a review as soon as possible to warn others against making the same mistake I did. This happens rarely, but it does happen.

I encourage all of the developers out there to pry open their fat wallets, and don’t be afraid to buy tech books. And don’t be afraid to review those books, good or bad. Reviewing a book fairly does a great service to the community at large, even if it is a bad review. Don’t be petty and you won’t feel petty about writing it, and others will benefit from your words and choose a better tome.

Something New Every Day

October 26th, 2007

Today I ran into an issue that I had not encountered in C#, which is getting unusual for me as I have been writing .Net apps in C# since 2001. When initializing a private instance variable, .Net does not allow a reference to “this”. Some nugget of knowledge on this subject is floating around in the back of my head, but did not float to the front until I got an error in the VS IDE today. Here is an example:

public class Blah : BlahBase
{
private MyType t = new MyType(this); //Doesn’t work!
}

In this example, I wanted the instance of MyType to hold a reference to its parent object. I won’t go into all of the reasons here, but this pattern makes it possible to simplify a lot of things in my Blah class. Additionally, I need to be able to instantiate a lot of objects of type MyType, and also do it in any class types that inherit from BlahBase. My descendant classes will have a number of constructors, so doing initialization in all of these constructors of the MyType instance fields will become cumbersome and I could very easily introduce bugs with one missing line here or there.

To give a reference to Blah (or any given descendant class of BlahBase) to an instance of MyType at declaration, I decided to turn to reflection. In the BlahBase constructor, I looped through all the the Non-pubic, Instance fields of the current type using this.GetType(). I then check the type of each field to see if it is a MyType, and call FieldInfo.GetValue() to get a reference to the object, and Invoke() to set the reference to “this” via reflection as well. While the reference is not actually given to the MyType instance at initialization, it is given to each MyType instance before anything in in a child class of BlahBase can use it.

I keep telling myself that this is bad. Calling things via reflection is not very type-safe. Errors tend to happen at runtime instead of compile time. Additionally, reflection is slower than direct method calls or assignments. But really, I am probably dealing with 20 instances of MyType as a worst case. The performance difference is not going to be very bad. I will tend to write cleaner, more bug free code using this structure, as will other developers using BlahBase as a base type.

However, this is not type safe. The wrong change to MyType could cause a run-time error in the future. However, this is an error that will be very easily detected in testing. I am willing to trade for the over-all better OOP design here, and more developer productivity.