Archive for November, 2007

Naming Servers

November 13th, 2007

A posting at Jeff Atwood’s Coding Horror discusses project names. There have been some famous project names throughout the years. Longhorn and Orcas should both be familiar to Windows developers.

Naming servers is a little different than naming projects. Once you name a server, you are probably stuck with that name for years and years. While you are also stuck with a project name, the project will (hopefully) be completed at some point in time.

People inside and possibly outside your department and organization may refer servers by name. So might software.  DNS definitely alleviates some of this.  However, changing the name of a server is never a great idea, so coming up with an adequate name from the beginning is always a good thing.

There are a few of schools of thought on naming computers that I have encountered in my career.

  1. Name a desktop computer based on the person using the computer.
    This method usually ends up just being the person’s domain login. If your name is John Smith, your domain account is probably jsmith and your computer is probably named, you guessed it, jsmith.
  2. Name a computer (server) based on its function.
    Pre-Win2k domain days, it was not uncommon to have machines named something like PDB or BDC, for Primary Domain Controller and Backup Domain Controller respectively. Mail is a popular name for the mail server, etc.
  3. Name a computer based on a random scheme.
    One customer site I visited had machines like QB1Z2. This had no meaning other than the fact that no other machine on the network had the same name.
  4. Name a computer based on location or department.
    In very large organizations it can be handy to be able to *find* a computer, especially if you are the IT guy. A hospital that I visited (a customer) had machines like Triag001 and ER004.  This allowed IT staff to quickly find machines.  Where is Triag004?  Well, it must be in triage!
  5. Name a computer (or often a server) based on a predetermined naming list.
    This method is usually used for servers. I have seen the Periodic Table of Elements used at two different jobs sites. Imagine a mail server named Helium, or a file server named Oxygen. At one site a server was named Upgradium. At one of those two sites just mentioned, all of the externally-facing machines were named after local lakes. I thought this was a pretty good idea for two reasons. First, it was easy to remember if a given server was in the DMZ or could be seen (attacked) by the outside world just by the name. Second, people outside of our organization (partner businesses, etc) probably did not have a knack for remembering elements, but they might remember the name of a local lake.

In the end, I think all of these except #3 are fine ideas.  I personally like #5 for servers because it gives developers and IT staff something fun to do: come up with lists of names.  Its always fun to refer to servers in this fashion as well.

AT&T. Your World. Delivered. To the NSA.

November 7th, 2007

The Electronic Frontier Foundation (EFF) is currently suing AT&T for violating the rights of its customers and a number of other Americans. AT&T (allegedly) illegally captured internet and phone traffic at one of its data centers in California (and maybe elsewhere) at the request of the NSA. There was no warrant for these wiretaps, and the wiretapping was (allegedly) done on the phone lines of US Citizens. A brave AT&T engineer turned whistle-blower named Mark Klein brought all of this to light.

Boing Boing posted a link to an excellent EFF Video by Mark Klein on what he and the EFF allege was occurring at AT&T’s data center, and about certain members of Congress trying to grant retroactive immunity to companies that may have illegally cooperated with the NSA like AT&T. It is worth noting that QWest told the NSA to shove it.

I don’t ever want to get too political on this blog. If you read anything that refers to a politician or some other political statement, I am *probably* joking around. But this is something that truly is disgusting. First of all, the NSA should never have done this (allegedly). And second, AT&T should never have gone along with it (allegedly).

Using and IDisposable

November 7th, 2007

In .Net land, classes that hold onto resources resources that need to be cleaned up after usage should impliment IDisposable. These resources can include database connections, input or output streams, and unmanaged resources such as window handles.

There are a number of classes in the System.* namespaces that implement IDisposable. When you use a class that impliments this interface, it is your responsiblity to call .Dispose() when done with the class. When you author a class that holds onto valuable resources such as those listed above, you should impliment IDisposable and call Dispose on any composite objects your class is referencing that impliment IDisposable, plus do any other cleanup that is needed to prevent memory leaks such as releasing event handlers. Remember, if one of your objects handles an event from another object, that other object has a reference to your object and therefore garbage collection will not occur on your object (memory leak).

Microsoft tried to make it easy to use IDisposable objects in C# by adding the using block to the language:

using(SomeDisposableClass x = new SomeDisposableClass())
{
//some work here
}

The code snippet above will always call x.Dispose() when the code execution leaves the block. Pretty handy, right. Well, not really. What is not obvious about this code block is that it silently eats exceptions. The following code block does the exact same thing as the using block:

SomeDisposableClass x = new SomeDisposableClass();

try
{
//some work here
}
finally
{
x.Dispose();
}

Any exception is just lost. It is never handled. This is very, very bad. When writing code that uses IDisposable, *never* use using. At very least do something like this:

SomeDisposableClass x = new DisposableClass();

try
{
//some work here
}
catch(Exception ex)
{
throw ex;
}
finally
{
x.Dispose();
}

Now why would Microsoft give us such a dangerous language feature in C#? I have read that it was to encourage developers to dispose of resources. I don’t buy it. In my mind, there are three alternatives to the current using block that would have been better. The first is simple, just have using throw any exception it encounters!

My second idea is to create a using block with a catch:

using(SomeDisposableClass x = new SomeDisposableClass())
{
//some work here
}
catch(Exception ex)
{
throw ex;
}

In my imagination, the statement above always creates a finally in the IL that disposes of x.

My third idea is to modify try/catch/finally to handle IDisposable types:

try(SomeDisposableClass x = new SomeDisposableClass())
{
//some work here
}
catch(Exception ex)
{
throw ex;
}

The only wrinkle in this third idea is that a programmer may choose to write a finally block a do some custom logic to dispose of the x object. I am sure the compiler could detect this condition and handle it acordingly.  All in all, I like me second idea the best.

I think it is much more dangerous to silently eat exceptions than it is to create memory leaks. Memory leaks just cause computers to get slow or crash. Silent exceptions are not only difficult to debug, but could be causing data corruption that is not detected during the development and testing phases of the software life-cycle. Put it this way: Memory leaks are George Bush evil, data corruption is Hitler + Stalin evil.  I would happily welcome Microsoft modifying or deleting the using statement from the C# language.

LOLTrek

November 7th, 2007

A coworker sent me this link.

http://granades.com/2007/05/02/loltrek/

It combines LOLCats with a famous episode of Star Trek.

Split and API

November 6th, 2007

A fellow developer (lets call him George) recently made me aware of a static function in Microsoft’s Regular Expression namespace in the Regex class called Split. I had not been aware it existed, but George informed me that if I wanted to split strings that were delimited with more than one char that I had to use this Split function instead of another, better known Split function, in the String class. This is wrong (both functions work), but it highlights a problem with writing an inconsistent API, especially one as popular as .Net.

Split and Join are two of my favorite string functions in any language. They rank right up there with Substring and Trim. Split is used to create an array of strings from a single string, splitting on a delimiter character or string. Take the string “Blue,Green,Red,Orange” as an example. Running Split on this string using “,” as the delimiter would create an array of length four, holding the strings “Blue”, “Green”, “Red”, “Orange”. Join works in reverse. Join will take in an array of strings and a delimiter (“,”) as arguments, and return a single string.

In .Net, Join is a static member of the System.String class, and Split is an instance member of that same class. This makes good sense when one thinks about it. One must first have a string to split it (member), and one needs access to a function without having to instantiate a class to join a set of strings (static). The Join method follows a kind of factory creational pattern.

So far, so good. I like what Microsoft did making one an instance member functions, and one a static member function. But that is where it ends. You would assume that Split and Join would accept the same types of arguments. For example, if one accepts a string as a delimiter, the other should accept a string as a delimiter. Not so.

It is these types of inconsistencies that bubble out during the initial release of any technology. .Net 1.0 was a huge milestone for Microsoft back in 2001. You may or may not recall those days, but Sun was taking a lot of developer real estate away from MS with Java 1.1 and Java 2.0. In my opinion, Microsoft was behind the 8-ball. When getting a massive API out the door that will be the development platform of the company for the next 10 – 20 years, one can be forgive for making little mistakes.

Still, I find things like this annoying. Why not fix a few of these glitches in .Net 2.0? There should be a simple overload of Split that takes 1 string argument (the delimiter), just like there is a simple overload of Join that takes 1 string argument (the delimiter) and the string array to join.

As an example, imagine our string from above is “Blue~|~Green~|~Red~|~Orange”. In this string, “~|~” is the delimiter. The solution is to use the instance method of System.String, Split, passing as an argument an array of strings to use as delimiters. The most common usage is to send an array of length one.

string[] theSplits = myString.Split(new String[]{“~|~”}, StringSplitOptions.None);

To further complicate things, this overload (the simplest that accomplishes what is needed in this example) takes an often-unneeded, second argument. Why not just have the following, MS?

string[] theSplits = myString.Split(“~|~”);

The point I am getting to here is that the most obvious overload that should exist doesn’t, and so “George” from above became confused and went looking for another split function. I have to give him kudos for looking in the Regex namespace. I try to think of things like this when I am writing code that other programmers will use. I *try* to write my functions in a consistent manner so that once a developer knows how to use one, they know how to use them all. A good guide to doing this is Microsoft’s own Framework Design Guidelines book. They learned a lot while doing .Net 1.0, and formalized their design guidelines for internal use and then decided to publish them. This is a common reference whenever I get in a discussion about variable naming, etc, with fellow developers.  I highly recommend the book.

Microsoft really should add the obvious Split overload to the String class. And with the C# 3.0 Extension Methods, you can do it for them.

Disclaimer: The Framework Design Guidelines link uses my Amazon affiliate membership, so I get a few cents if you purchase it with that link. The book is fairly popular for a tech book so you can probably find it at your local bookstore, B&N, Borders, or Bookpool.com as well as Amazon.com.

Programming languages

November 5th, 2007

I have been through a few programming languages in my life. In 6th grade my father got me a Commodore 64, which used a flavor of Basic. Later on in Junior High I took a semester of Basic on Apple II, and messed around with a little QBasic in High School. I really fell in love with programming my first semester of college. Every freshman at SDSM&T was required to take Fortran. The next semester I changed majors to Computer Science and started learning C, C++, Assembly, and once learned Pascal to help a girl I liked with her homework. Because I knew several older guys that went to work at Microsoft, I also had gotten some experience with Visual C++ and Visual Basic. In particular, I remember VB 1.

Once out of school, I hopped into Microsoft’s Visual Basic 5 and Active Server Pages. I also dug into Java 1.0. Soon .Net came out, and I was in VB.Net. But when Microsoft released .Net, they created a brand new language called C#. To my eyes, C# had everything good I liked from Visual Basic 6 and Java 1.1. The common language runtime looked, at least to me, like an improved version of the Java runtime.

I have found myself dabling in other languages over the years. I have gotten into PHP, Ruby, Python, Tcl, and others. But I always feel at home in C#. The additions they made to the language in the C# 2.0 release only added to the language, as will the C# 3.0 changes, when it finally comes out of beta.

A lot of programmers I have met over the years have a similar story. The languages they have cycled through are often dependent on what school they attended, their age, and what their employers were using. But the path usually resembles, in nature, the one I described. Many people find their way to a language they love, the way I love C#.

O’Reilly has a great poster detailing a lot of programming languages, spanning from Fortran in 1954 to our modern languages as of 2004. I see it posted once every 6 months or so at Digg or Slashdot, or one of the handful of programming blogs I read. It details the various connections between languages, and their general histories. As usual, Wikipedia has a fine collection of articles on the subject including A History of Programming Languages and A List of Programming Languages, broken down by timeline, category, generation/relationship, alphabetical, and non-English languages.

Old stuff

November 4th, 2007

It has been spring errrr fall cleaning this weekend. While my wife and I have been under the weather, we have still managed to get a lot of old stuff out of the house. Some of it has gone to the trash, some of it to Goodwill, and some of it I will be taking to work to see if someone wants it.

books_thumb.JPGWhile my wife has mostly been cleaning out old clothes and shoes, I have been concentrating on old computers and books. As I mentioned in a previous article, I like to buy tech books. I also have a difficult time letting go of old machines. But as technologies become antiquated, so do some of the books I have purchased. And the old computers break down.  It is even hard to justify keeping some of the really old hardware I have that is still functioning.  Do I really need a seven-year-old Linux desktop sitting in my spare bedroom when I can download one of 1000 Linux VM images from the web and run it on much nicer hardware.

I ended up throwing out three old computer cases. In two the motherboard had finally gone kaput, and the power supplies we too ancient to do any good with new components. There were also a number of cards like WinModems, 10/100 NICs, and a lot of old, old RAM, and other worthless components. The whole lot are sitting in my garage, ready to be taken to the curb on trash day. I have really turned into a notebook guy anyway, and if I do decide to build a desktop in the future I kept my best case.

Pictured here is a stack of books with which I am parting ways. Many of these are VB 6 books, and related technologies. Also, I have a few certification books. I was really into certifications a few years back. I am a big believer in certifications for young developers. I know my certs got my foot in the door on a couple of jobs.

I figured out that I spent around $700 for that pile of books. That is a bit depressing, to think that one can spend that kind of money on books that have become relatively worthless. I am never going to program in VB 6 again. I am never going to go after any of those certs again. And there are several other subjects that are now out-of-date.  I don’t even want to think how much money I spent on the hardware!

It feels good to jettison so much baggage.  The technology industry is all about change.  My wallet might be a little harder to open the next time I want to buy a computer, knowing that in less than 5 years it will be completely ancient. But when I do buy it and get it home, I will probably be too happy to care.  And I will go through all of this a few years from now.

My monitors suck

November 3rd, 2007

My workplace recently distributed dual monitors to all of the developers.  They suck.  They bought each of us two horrible monitors to replace the one decent monitor we had.  I have tweaked and tweaked my monitor settings with only minimal improvements.  I have been thinking about trying to get some better ones, and need recommendations.  I was happy to see this article over at Jeff Atwood’s Coding Horror about LCD monitors.

Everything is eventually free

November 2nd, 2007

A couple of years ago I picked up a very interesting book called The Singularity Is Near by Ray Kurzweil. Mr Kurzweil offers up a lot of interesting theories about the future and a coming event called the “Singularity”. Kurzweil has an extraordinary resume, so it is hard to discount his ideas as absurd. In fact, I have taken one of his theories to heart, The Law of Accelerating Returns.

This law states that all human knowledge and technology is growing, and that growth is accelerating exponentially. Kurzweil fills several pages of his book with charts full of historical data backing the theory. This trend is easy to spot in the tech sector. Computers are constantly improving in speed and decreasing in price.

Think about cell phones. In the early 90s cell phones we very expensive, both for the actual hardware and for the service. By the mid 90s the hardware had decreased in price enough for most people in the US to be able to afford one, but the service was still very expensive. I remember circa 97 when I got my first cell phone living in Rapid City, SD that a woman who got stuck in a blizzard was saved by a cell phone she had purchased only for the 911 service, and had not activated any pay service! Today, cell phone technology is everywhere. It is relatively inexpensive. An internet connection with cell phone service is several times faster than dial-up, the primary method for of connecting to the internet only a few years ago. Everyone has a cell phone. Little kids have cell phones. I think I saw my cat toting one around the other day. They are relatively cheap, both for the hardware and service.

This brings me to the topic of the post. Everything is eventually free, or at least very close to it. It may take a long time, but it will probably happen to any given technology. This has some interesting implications in the software world. Microsoft makes billions of dollars on just its operating system line. It makes billions more on its office software, and also makes a pretty good chunk of change on some of its server products such as SQL Server, BizTalk, etc.

Linux is free, and is every bit the OS that Windows is. Open Office is a great replacement for MS Office. I have been using it for several years on my Windows laptop and my MacBook. MySQL is a great database server, and it is free as well. However, there are plenty of people still using Windows, and I am one of them.

From a programmer’s perspective, there is a lot of stuff that I get, for free, every day. My source code is maintained in Subversion, a free source code control application. It runs in Linux, in a virtual machine, running on VMWare’s free server software. I use a number of open source libraries for C# developers. There is one that I use for doing very large math, I believe it is called BigInteger. I use Jeffrey Richter’s Power Threading Library, and NetSpell for spell checking, ICSharpZipLib for programatically using zip files. The list goes on and on. I am much more productive today than I was just a couple of years ago because of all of this free software.

Imagine when this paradigm takes root in other sectors. What will happen in medicine when we can finally apply rapidly improving technology to diseases? What about transportation? Energy?  I think programmers are seeing a piece of the future, right now.

When there is a will there is a way

November 1st, 2007

Have you heard the saying, “Through the force of sheer will?” I have, and I think it is a load of crap. Your will won’t get you anywhere without some thought and planning. Simply trying to force your way, by sheer will, is often the worst way to get something done.

I am recalling an interview I had. A programmer was looking for a job with my company, and I was one of the people assigned to conduct a 30 minute interview with this programmer. To prepare for the interview, I read the programmer’s resume and did a couple of Google searches on their name; pretty standard stuff. What I found in the resume was a lot of experience programming, but almost no experience using any of the specific technologies we are using in-house.

Once I sat down with this individual, it became very clear what was going on here. I have seen this scenario before.

  1. A smart developer (candidate) is looking for a job, finds a company they like and a job that looks nice, but for which they are unqualified.
  2. The candidate convinces the recruiters of such things as “Java is just like C#”, or “Sure I can do AJAX, I have a lot of web other development experience.”
  3. The recruiter sends the candidate in.
  4. The candidate acts borderline arrogant trying to make up for the fact that they do not have the domain skills or knowledge needed.
  5. The candidate does not get the job through sheer will.
    1. The candidate wasted their time and effort.
    2. The candidate waster my time and effort.

I hope you will not find it surprising that the candidate at my interview did not get the job. I found it a real waste of time. I could tell that this person had not clue one about the specific technologies in question, especially when they tried to BS their way through several technology questions. Arrogance and ignorance are not a good pairing for a job interview, but unfortunately they often go hand in hand.

This exact scenario has happened more than a few times to me over the years, enough to not just discount it as an anomaly. I have usually run into this attitude when dealing with consultants. Big name consulting firms make their bread and butter money bringing in bright (and sometimes not-so-bright) but unqualified people and ramping them up on the relevant technology, on the customer’s dime. This is nothing new and if that statement sounds profound and/or outlandish to you, then you have just not had the misfortune of dealing with a big name consulting firm. Consultants get used to not having the relevant technology, but ramping up on the tech during the job.

A few years ago I found a job opportunity that I wanted. However, I found myself in a situation where I did not have all of the qualifications for the job, but I thought I still had what they were looking for. The employer wanted a very strange mix of technology skills that I would imagine is very uncommon to find in a developer. Lets just say I was more than proficient in 3 of the 5 things they wanted.

I set out to take a chance with this job. I purchased a book on one of the technologies (1 out of 5), and started reading and programming with this techology. Meantime, the interview process proceeded, but I tried to be as open and honest as possible about my skill set. The skills I did have eventually got me in the door for a real interview. A couple of weeks had passed during this time.

At my interview, I was able to demonstrate my proficiencies with the 3 of 5 skills needed, and some proficiency with one of the technologies that I had been missing. I was also honest about this, explaining that I had been reading up on the technology for the interview. I explained that my intention was not to bluff my way into the job, but instead to demonstrate how fast I could ramp up on the technology before being hired, and that to meet the job requirements, I was willing to do so on my own time.

I ended up getting the job. The first day at work, I already had a month of playing around with the some of the missing technologies in my resume, and I believe I did a pretty good job from day one. When there is a will, there is a way.

Instead of just arrogantly stating that you have a skill or that you can ramp up on it, prove it. If you want a job bad enough, you will go for it in a thoughtful and willful way.