IDig IComparable

17 years, 8 months ago
[ Geek ]

(Apologies for the code samples, indenting and justification is hosed so it ain’t pretty. I’ll fix that someday when all I have to do in a day is tinker with websites.)

Anytime I contemplate doing any of the following to a custom class: sorting, overriding Equals, overriding GetHashCode, or building typed collections, I typically start with IComparable. That is, I start by having the class implement IComparable.

Let’s say you’ve got a User class and it’s uniqueness is measured by it’s primary key in the database, represented by it’s Index property. I typically start by overriding GetHashCode(), so in this case you’d have:

public override int GetHashCode()
{
return this.Index;
}

The rules are that if GetHashCode is identical for two objects then they’re equal. So implementing IComparable is just a matter or relying on your GetHashCode:

public int CompareTo(object obj)
{
if (!(obj is User))
{
throw new ArgumentException();
}
User user2 = (User)obj;
int compare1 = this.GetHashCode().CompareTo(user2.GetHashCode());
return compare1;
}

Now that you’ve got a working CompareTo, you can use it for your Equals:

public override bool Equals(object obj)
{
if (this.CompareTo(obj) == 0)
{
return true;
}
return false;
}

If you asked me, that’s a clean, quick and simple way to have your objects support comparisons, hashing, and sorting using IComparable. As well, if you need a custom, strongly typed collection for you object then you can use CompareTo for comparison methods such as Contains, BinarySearch, etc.

Obviously this won’t handle every class and things will get more complicated but it takes care of the majority of cases and gets a strong foundation in place.

Sorting with IComparable Links

New category…big day, big day….

17 years, 8 months ago
[ Audibles ]

headphones.jpgI’d like to welcome a new category to this sad little site. It’s about the tunes man. Sometimes I want to tell people what I’m listening to. I’ve tried leaving voicemails for myself but it’s just not doing it for me. If this entire category irritates you in some fashion, please email me here.

To the first post. I can’t stop listening to Chad Vangaalen. Listen to him on cbc here. There, that’s it, that’s all I had to say.

Making Wooden Stuff

17 years, 8 months ago
[ General ]

So my friends, and now business partners, Pat, Mark, and I just signed a commercial lease today. We’re setting up a woodworking co-op space. Full cabinet makers shop for a few good men. Get a hold of me if you’re interested!

That’s a picture of wood there.

Conference

17 years, 8 months ago
[ General ]

nerd.JPGGenerally I don’t do the conference deal. I suppose I’m cheap and the few times I have gone to one it always feels like we’re sitting around talking about doing neat stuff while…..well you know.

So this is the first conference invite I’ve received in years that I’ve actually considered. Guy Kawasaki, Joel Spolsky, some guy from Red Gate, Eric Sink, and more. Okay, and Jeffrey Pfeffer, who is kinda like the father I’ve never met. Oh and not to mention that one guy Hugh MacLeod. I think I’m being punk’d.

Desktops and cheap parts

17 years, 8 months ago
[ Geek ]

Some may remember my recent switch back to a desktop. The idea being that it’d be significantly cheaper to build my dream desktop than get a new laptop. I’d then run vmware, sshd, etc allowing me to work on that desktop remotely.

That means when I’m doing tasks like compiling in visual studio, I’m actually building on my burly new machine instead of my sad old laptop. Another big reason for the switch was to have access to cheap parts and easy hardware upgrades. I haven’t taken advantage of that until last night.

I bought, and installed, 2 x 1GB of RAM for $79. I now have 4 GB of RAM total. I feel like I’m cheating.

Business Plan

17 years, 8 months ago
[ General ]

Business plans are great but I’d rather have a business than a business plan.

Prototypes and Crappy Software

17 years, 8 months ago
[ Software Development ]

Typically in software when someone asks you to build them a prototype what they’re actually saying is “I have little to no cash”. I’m cheap myself so I love the idea of building things quickly for little cash. The sh*t hits the fan when the person asking doesn’t truly understand what they’re getting.prototype.jpg

There are those rare to non-existent occasions where they’re actually saying “I know exactly what I’ll end up with in asking you to meet these unreasonable deadlines but just build it fast”.

The longer the time horizon gets, the more expensive building software this way will get. So if you build it, get it into some sales meetings or get it in some customers hands and the concept is proven flawed and you either abandon the business idea or significantly refactor it then perfect.

You just saved yourself a ton of cash and are a genius. Clearly building a so-called enterprise grade product would have been a very expensive mistake. Of course you also lack a business but let’s ignore that for now. It was good learning, it was better to know sooner than later, and it didn’t cost you much.

Short time horizon, cheap.

This will sound strange but the worst thing that can happen from a purely software perspective is the opposite. That being that you hit a home run with a valid money-making business idea and your software ‘prototype’ proves it. Now you start tacking things on, expanding, etc. Two years later, you’re almost in the black, you’ve got an actual working business but somehow your ability to progress technically has ground to a halt. You and your team have literally stopped dreaming cool ideas because you’ve been conditioned that technically they can’t be done, regardless of reality.

What happened? You delivered a prototype to prove a business concept, get some quick cash in the door. That prototype then became your product and eventually became an unmaintainable code base.

What’s unmaintainable mean? In most cases, unmaintainable means unreasonably expensive to make even the slightest change whether that’s new features or handling more volume etc.

Well there’s no such thing as unmaintainable right? Anything’s maintainable with sufficient piles of cash? Sort of but it’s uglier than that. One example is people. Smart, talented developers will flee from code bases like this. I guarantee you this and have seen it over and over again. So now you’re paying a lot of money to bad developers to tack pushpins onto your ball of rubberbands.

Long time horizon, expensive.

I wish I knew where I wrote this quote down from….”being first to market and developing the application as rapidly as possible often comes at the expense of long-term maintainability. In addition, these goals require different sets of skills, quality control practices, and management mentality”

Reread the above paying close attention to the role of the word “often”. Ah, a glimmer of hope. So can you do both? Can you build as rapidly as possible AND deliver long-term maintainability?

Short answer, no. Trust me, it’s just simpler for everyone involved if you take that answer and don’t read any further. Still reading eh? Ok, so I will tell you yes you can have both but it’s so rare and takes such an obscure combination of people and skills that it’s just safer to work on the assumption that it can’t be done. How do you do it? Well as hammy hamster would say, that’s another story….

DemoCampGuelph2

17 years, 8 months ago
[ General ]

The date for our second DemoCamp in Guelph is set. We’re on for Wednesday July 18th. What can you do? Simple:

  • If you can attend, go to our page, edit it and sign up indicating you’ll be attending.
  • If would like to demo, contact me asap.
  • Talk us up, spread the word, get people out!

Trial and Error

17 years, 8 months ago
[ Office Gossip ]

Quote from IDEO founder David Kelley about their guiding philosophy,”enlightened trial and error outperforms the planning of flawless intellects”.

Wisdom

17 years, 8 months ago
[ Office Gossip ]

Quote from Hard Facts referring to the single most important quality of a leader, advisor, or team. To travel “through life with an attitude of wisdom – the ability to act with knowledge while doubting what you know”.