To write or not to write
Tuesday, July 1st, 2008If you have spent any time working as a software developer you probably know that the most essential skills in our field is the ability to make the right choices. No, really, every single time you writing a code you have to think, do you want to make all that iterations in a loop or use a recursion, do you want to use clever functional style techniques with closures and stuff or just OOP, or maybe just plain procedural code, do you want to store your data in a database or in a simple file and so on and so forth.
But there is a one choice you have to make even before you start your favorite editor and it is - should you write that thing yourself or maybe just reuse someone else’s code from out there?
It is really, really hard question. From developers point of view it always fun to create something by yourself, you’ll have fun and get more experienced. And it will do exactly what you want it to do. But from business perspective it’s easier to reuse or even buy someone else’s code, since it’s already written, bugs are fixed and you have guys outside of the company working on it so you could use them as help and they also will fix bugs in your code for free.
In most cases the choice is obvious, nobody would write his own database if he can use mysql, mssql or whatever and it’s enough for his needs, nobody in his mind would create his own language to use it internally, except really specific cases when that actually makes a point, like in FogBugz for example, nobody would write his own graphical editor if what he need is just to edit couple of dozens of photos. But you see, sometimes you have to write that stuff yourself even if it’s complicated and will take a lot of effort and time to build. The obvious rule of thumb here is to write only the core set of features, something that will distinguish your application from it’s competitors and download all the other parts from the Internet.
But there are situations when there is no right choice and one of them is when you want some tool to make some job just for yourself. Like you have to find something in a bunch of files, are you going to use grep or write a Perl script for that? What if you have to generate or edit some of the text files based on other text files, are you going to write sed script or a program in Ruby?
There’s no right or wrong choice here. Some of us will write ruby code faster than read man page for grep and find out what options he should use. Others will write sed script faster than figure out how to write in a file in C++. And the speed is not always a benefit for a choice, learning something new might be much more enjoyable and will pay off in a long run.
Anyway, the reason of this whole post is that I recently chose not to write and I want to tell you a story about it. And proof to myself the choice was correct.
Couple of weeks ago I bout an
bluetooth headset and wanted to use it in a car with my
Kaiser. But I’ve noticed that despite it is plugged in to car charger, simultaneous usage of GPS and Bluetooth drain battery in about 5 hours. Not usable. Then I remembered that some phones have a feature to turn bluetooth on when incoming call is arriving and disable it afterwards. I’ve checked that headset pairs automatically once bluetooth on a PDA becomes active so I just had to find a simple program to turn it on and off depends on call events. And I couldn’t find any. Just an empty spot here, really. But googling shows me
MortScript for similar problem and I gave it a go. The first revision of a script was simple - it was waiting for a window with title ‘Phone - incoming call’ to became active, turn bluetooth on and then wait until all windows with ‘Phone’ in a tittle will go in to the background. A little bit later I added feature not to turn bluetooth off if it was on already.
while(TRUE)
while(WndActive("Phone - incoming call...") = 0)
Sleep(1000)
endwhile
if ( RegRead("HKLM", "System\State\Hardware", "Bluetooth") = 8 )
Run("\Program files\vijay555\VJVolubilis\VJVolubilis.exe", "-blueon")
while(WndActive("Phone"))
Sleep(5000)
endwhile
Run("\Program files\vijay555\VJVolubilis\VJVolubilis.exe", "-blueoff")
endif
endwhile
You would have to install VJVolubilis and MortScript for that to work.
I’ve spent couple of hours on that script and it worked like a charm with one little detail, it was running a infinite loop eating up precious CPU cycles and draining battery. Sadly, MortScript doesn’t support events all that much.
But then I SKSchema came along, application that knows about events and could run some predefined actions on them. At first I just added two actions - turn bluetooth on incoming call and turn it off on disconnect. That worked except it would turn bluetooth off after call even if it was on long before call arrived.
So I removed a loop from MortScript and made SKSchema run it on call. Script then based on active window title will figure out when call is over and turn bluetooth off.
if ( RegRead("HKLM", "System\State\Hardware", "Bluetooth") = 8 )
Run("\Program files\vijay555\VJVolubilis\VJVolubilis.exe", "-blueon")
while(WndActive("Phone"))
Sleep(5000)
endwhile
Run("\Program files\vijay555\VJVolubilis\VJVolubilis.exe", "-blueoff")
endif
And then I got thinking, as a developer, I could write that code in C# or even C++, it will work faster, it wouldn’t depend on windows titles and use normal events. It will be better.
But I already got the working solution. There’s no point in spending even a couple of days on that task anymore. Nobody except me will ever use it anyway.
So I decided leave it as it is. It automatically signed me off ‘Done and getting stuff smart’ category since those guys don’t think they just do but I knew I didn’t belong there anyway.
Huh, long post, all the right arguments, I know I am making a right decision here and still something bothering me. Yes, I just want to spend considerable amount of time learning Compact .NET framework, knowing I will never use this knowledge, and nobody except me would use the result product and I do have working solution already. Only my laziness helping me staying on the sane side right know. I guess it is damnation of developers, writing code even when you really shouldn’t. Please give me the slightest reason to do that, say that you would use this product and I will give it to you for free, no strings attached. Let the choice I want to win actually win. I am at your will here.