March 8, 2010

How are your development gifts viewed by your company?

This morning @JohnMacIntyre wrote a blog post entitled Timing your exit by the reception of your gifts. While I agree with his point, I thought it might be valuable to provide my perspective on why those gifts may or may not be appreciated by their intended recipient in at least one market.

When a company sees development as a profit centre, then the little gifts are appreciated. There is added value in the product and the savings/revenues generated by the product are immediately reflected upon. This view is frequently seen by companies who are having a good time financially and are seeking to extend the benefit of their good fortune or by companies where development is the core of their business model - i.e. sale of software in some form.

However most companies writing software aren't in the market of selling that software, they're writing it for their own use internally. When a company like this falls on hard times, management frequently reverts to considering development as a cost centre. As pressure mounts and politics set in, managers have to fight harder for the recognition they deserve and in other cases to save face and avoid retribution. They start to point fingers to divert attention away from themselves when they’re asked to account for their shortcomings.

At this point, it doesn’t matter how many value added extras are included in your software if all of the core objectives aren’t completely in order. Those trying to divert the spotlight from themselves will divert it on you, just to get it off themselves.

I digress, my point was this: The minute you start to see development as a cost centre, you cease to consider the value added benefits and immediately view them as a time sink.

Consequently I think the level of appreciation of these gifts boils down to one question: Is the development department looked at as a profit centre or a cost centre within the company?

The answer to this should drive your approach to your workload and hence the company’s perception of your benefit to them.

If it’s looked upon as a profit centre, and you do nothing beyond meeting the core objectives, you’ll be seen as someone who does no more or less than asked – to your benefit or detriment, whichever you decide.

If it’s looked upon as a cost centre and you are always going above and beyond to provide extras that aren’t necessary, then you’ll be looked at as a time waster who can’t focus on the goal.

March 3, 2010

Of a personal nature... [a.k.a. just how bad can one morning with a wife and two kids get?]

I'm not having a great day, it's gotta be said... and 140 characters just wasn't going to cut it this morning. I thought everyone could do with a laugh at my expense because to be honest, if this had happened to anyone else, I'd be laughing at them.

I was awoken by Aimee [my lovely, but sick wife] at 4am to go fetch her "clear pop that has sugar in it and a glass of ice" because she's spent the last 2 hours losing her insides from every possible exit and doesn't have a snowball's chance in hell of getting down two flights of stairs to the basement without falling and breaking her neck. So I drag my ass out of the nice warm bed and down to a freezing cold basement to find the only thing we've got is Tonic Water... which she won't drink. Everything else we have is diet. Fabulous... well, Tonic Water will have to do.

The ice is frozen solid except for the snow in the bottom of the bag; I can't find an ice pick, the meat tenderizer is having no effect and I'm already shivering. I finally manage to break off a chunk that fits in the glass and take it and the Tonic Water up to her.

I fall asleep for what seems like 3 minutes and somehow it's already 6:45am. Charlotte [our 5 week old] has a poopy diaper which Aimee can't deal with without losing her cookies [those at least that she has left to lose], and Aimee's woken Olivia [our 18 month old] up to put her in the bath to get her ready for daycare... and she's already called her Mom to get her to come and help with Charlotte because she doesn't want to get her sick too. Her mum's already on her way over. Crap! I'm totally not ready to get out of bed yet - but because Olivia's in the bath and Aimee's mother's on her way over, I have no choice. Double crap!

I go to change Charlotte to find she doesn't have a poopy diaper at all, I change it anyway, whatever. I go back to the bathroom and turn on the shower to warm it up, I turn back around to find that Olivia's pooped in the bath. Great timing Olivia, perfect. We have to leave in 15 minutes and now not only am I not ready, but I have to bath you in the sink, clean and disinfect the tub and everything that was in it during the poo fiasco of 2010, have a shower, get dressed, get milk and a snack for the car ride, make sure I've got all my stuff for work, put out the recycling and get you strapped into your car seat. It's not looking promising...

I drag her out of the bath and wash her off in the sink and get her dressed and take her downstairs and go back upstairs to empty and disinfect the bath and take a shower. I get done in the shower and go down to grab Olivia to leave the house.

I'm a bit phlegmy because I'm sick and coughing too, which caused me to spend an extra 10 minutes in the bathroom praying to the porcelain gods. I get done with that and go to put Olivia in the car to find that she's got snot covering almost her entire face and is threatening to wipe it all down my work clothes. Gross.

I get her cleaned up and get her in the car to take her to day care and get in to find that I've got no gas left.

February 18, 2010

Debugging Windows Services in C#

Well it's been a while since I had anything to blog about; rather, it's been a while since I've had the time to blog about anything. Recently @JohnMacIntyre commented that I should post regarding a technique that I've long used for developing and debugging Windows Services in C# which frankly are a pain in the ass when not designed with this purpose in mind.

My technique is simple, and it didn't cross my mind that other people weren't doing this or something similar:

  • Design your working class - this class actually does any work. It will be instantiated and configured by your application shell before being pushed into your service class.
  • Design your service class - Your service class is going to receive your working class via its constructor and when told to start will tell your working class to do its work.
  • Design your shell application - This could be a Windows Service shell, or a console app, windows forms app, whatever, it's not important. The point is that your shell application will do very little at all. It will read your configuration file for any necessary settings before instantiating and configuring your working class, and then instantiating and configuring your service class, pushing your working class into it. From here, your shell application only tells your service class to start or stop. Your service class will handle the rest.

Sounds simple enough - if a little um... vague. So let me clarify with an example - here's a basic design brief that demonstrates:

Design a service that will poll some web service every 30 seconds for information and push the received information into a database.

So where do I start?

Okay, here's my architecture:

Class 1 [Working Code]: This class will connect to the web service and retrieve the information and push it into my database - once. It doesn't handle the timed polling, it doesn't handle anything but calling the service, retrieving the information and storing that information in the database.

Class 2 [Service Code]: This is a class will initiate a timer at an interval specified in the constructor. When instructed to start, at the specified interval, it will tell Class 1 to do its thing.

Class 3 [GUI/HMI/Windows Service Shell]: This could be any wrapper, a console application, a Windows Service, a Windows Application, an ASP.NET application it doesn't matter. It's going to instantiate Class 1 and push it into the constructor of Class 2. It will then tell Class 2 to start, at some later time, it will tell Class 2 to stop and clear up after itself. The point is that Class 1 and Class 2 are important, and Class 3 is just a holding cell for them.

A little psuedo code to demonstrate:

Class 1: Working Code

public class InformationWorker
{
 private string _webServiceUrl;
 public string WebServiceUrl
 {
  get
  {
   return _webServiceUrl;
  }
 }
 private string _webServiceUserName;
 public string _webServiceUserName
 {
  get
  {
   return _webServiceUserName;
  }
 }
 private string _webServicePassword;
 public string WebServicePassword
 {
  get
  {
   return _webServicePassword;
  }
 }
 private string _dbConnection;
 public string DataConnectionString
 {
  get
  {
   return _dbConnection;
  }
 }
 public InformationWorker(string webServiceUrl, string webServiceUserName, string webServicePassword, string dbConnectionString)
 {
  _webServiceUsrl = webServiceUrl;
  _webServiceUserName = webServiceUserName;
  _webServicePassword = webServicePassword;
  _dbConnection = DataConnectionString;
 }
 public void RetrieveAndStore()
 {
  RawInformation ri = GetInformationFromWebService(WebServiceUrl, WebServiceUserName, WebServicePassword);
  StoreRawInformation(DataConnectionString, ri);
 }
 private RawInformation GetInformationFromWebService(string WebServiceUrl, string WebServiceUserName, string WebServicePassword)
 {
  //Omitted for brevity;
 }
 private StoreRawInformation(string connectionString, RawInformation ri)
 {
  //Omitted for brevity;
 }
}

Class 2: Service Code

public class PollingService : IDisposable
{
 private _timer;
 private Action _eventAction;
 public PollingService(int TimerInterval, Action eventAction)
 {
  _timer = new Timer(TimerInterval);
  _timer.Elapsed += TimerElapsed; 
  _eventAction = eventAction;
 }
 public void TimerElapsed(object sender, TimerElapsedEventArgs e)
 {
  if (_eventAction != null)
   eventAction();
 }
 public Start()
 {
  if (_timer.Interval > 0)
   _timer.Start();
 }
 public Stop()
 {
  if (_timer.Enabled)
   _timer.Stop();
 }
 private bool _disposed;
 private void Dispose(bool disposing)
 {
  if (disposed || !disposing)
   return;
  
  //Kill the timer;
  if (_timer != null)
  {
   if (_timer.Enabled)
    _timer.Stop();
   _timer.Elapsed -= TimerElapsed;
   _timer.Dispose();
  }
  disposed = true;
 }
 public void Dispose()
 {
  Dispose(true);
  GC.SuppressFinalize(this);
 }
}

Consider this a console application, I'm not going to reference a config file but configure programmatically - it makes no difference for the purpose of demonstration. This could equally be any other type of application shell.

public class ShellClass
{
 public void Main(string[] args)
 {
  string WebServiceUrl = "http://www.webservices.com/MyWebService";
  string UserName = "ben.alabaster@webservices.com";
  string Password = "SomeRand0mPa55w0rd";
  string DatabaseConnection = "Data Source=localhost;Database=SomeRandomDatabase;Integrated Security=SSPI";
  InformationWorker iw = new InformationWorkder(WebServiceUrl, UserName, Password, DatabaseConnection);
  
  int TimerInterval = 30000; //Every 30 seconds;
  
  using (PollingService ps = new PollingService(TimerInterval, iw.RetreiveAndStore))
  {
   ps.Start();
  
   Console.ReadKey();
  
   ps.Stop();
  }
 }
}

You can now test your service code without having to step through painful WinDbg sessions and attaching to your web service in the first seconds of startup. When you've finished debugging you just transform your console/GUI code into a Windows Service:

public class WindowsService
{
 private PollingService _ps;

 public void OnStart()
 {
  string WebServiceUrl = "http://www.webservices.com/MyWebService";
  string UserName = "ben.alabaster@webservices.com";
  string Password = "SomeRand0mPa55w0rd";
  string DatabaseConnection = "Data Source=localhost;Database=SomeRandomDatabase;Integrated Security=SSPI";
  InformationWorker iw = new InformationWorker(WebServiceUrl, UserName, Password, DatabaseConnection);
  
  int TimerInterval = 30000; //Every 30 seconds;
  _ps = new PollingService(TimerInterval, iw.RetrieveAndStore);
  _ps.Start();
 }

 public void OnStop()
 {
  _ps.Stop();
  _ps.Dispose();
 }
}

January 18, 2010

No formal education? No worries, become the most prolific writer of all time... or maybe the U.S. President...

Whilst some of the names found on the list of self-educated people that made a difference on Hacker News this morning are common knowledge to many, I was stunned by some of them, which perhaps I shouldn't have been.

I have pulled some of the more notable names from the list and will shuffle them in a slightly different order to purposely skew your sense of perspective:

For contributions to literature:

  • Samuel Clemens a.k.a. Mark Twain
  • Leo Tolstoy
  • Hans Christian Anderson
  • Jane Austen
  • William Blake
  • Charles Dickens
  • F. Scott Fitzgerald
  • Ernest Hemingway
  • Herman Melville
  • J.D. Salinger
  • George Bernard Shaw
  • Edgar Allen Poe

World Leaders & Influencers:

  • George Washington - U.S. President - I
  • James Monroe - U.S. President - V
  • Martin Van Buren - U.S. President - VIII
  • Zachary Taylor - U.S. President - XII
  • Abraham Lincoln - U.S. President - XVI
  • Andrew Johnson - U.S. President - XVII
  • Grover Cleveland - U.S. President - XXII & XXIV
  • William McKinley - U.S. President - XXV
  • Harry Truman U.S. President - XXXIII
  • Karl Rove - George W. Bush's chief strategist (W's Puppet Master)
  • Benjamin Franklin - One of the founding fathers of the U.S.A.

Science, electrical engineering and communications:

  • Nikola Tesla - Inventor and pioneer, arguably the father of electrical engineering as we know it today. Refined the A/C power that we use today.
  • Alexander Graham Bell - Inventor of the telephone.
  • Thomas Edison - Inventor of the lightbulb along with 1000 other patents.
  • Albert Einstein - E=mc² - 'nuff said.
  • Michael Faraday - "The best experimentalist in the history of science". Carried out pioneering work with electromagnetism.
  • Reginald Aubrey Fessenden - Built the first power generator at Niagara Falls.
  • George Westinghouse - Founder of the Westinghouse Electric Company.
  • Guglielmo Marconi - Credited as the father of radio.

For contributions to computer technology and software:

  • Steve Jobs - co-founder and CEO of Apple.
  • Steve Wozniak - co-founder of Apple with Steve Jobs.
  • Bill Gates - co-founder and CEO of Microsoft - until he retired handing the reigns over to Steve Ballmer. The richest man in the world.
  • Paul Allen - co-founder of Microsoft, owns 80% of TicketMaster.
  • Lawrence Ellison - co-founder and CEO of Oracle.
  • Thomas J. Watson - Founder of IBM.

For contributions to entertainment:

  • Allen Konigsberg - better known as Woody Allen
  • James Cameron
  • Walt Disney
  • David Geffen - co-founder of DreamWorks and Geffen Records
  • Stanley Kubrick
  • Steven Spielberg
  • Quentin Tarantino

For contributions to the automotive, aerospace and travel industries:

  • Henry Ford - Founder of the Ford Motor Company - learned about mechanics by repairing watches.
  • Soichiro Honda - founder of the Honda car company.
  • Orville Wright - co-inventor of the airplane.
  • Wilbur Wright - co-inventor of the airplane.
  • William Lear - the Lear Jet.

Other notables:

  • Richard Branson - of Virgin fame.
  • Richard Grasso - Chairman and CEO of the New York Stock Exchange.
  • Florence Nightingale

So if you have no formal education, and you're wondering what to try your hand at next, your most likely choices are most acclaimed writer of all time or U.S. President, and if they're not your bag, world changing scientist or founder of a megalith computer corporation.

Good luck!

Programming maxims to live by

Today I came across some maxims in The Art of Unix Programming by Eric Steven Raymond that I think should apply across all platforms. I found this extract particularly relevant:
  1. Rule of Modularity: Write simple parts connected by clean interfaces.
  2. Rule of Clarity: Clarity is better than cleverness.
  3. Rule of Composition: Design programs to be connected to other programs.
  4. Rule of Separation: Separate policy from mechanism; separate interfaces from engines.
  5. Rule of Simplicity: Design for simplicity; add complexity only where you must.
  6. Rule of Parsimony: Write a big program only when it is clear by demonstration that nothing else will do.
  7. Rule of Transparency: Design for visibility to make inspection and debugging easier.
  8. Rule of Robustness: Robustness is the child of transparency and simplicity.
  9. Rule of Representation: Fold knowledge into data so program logic can be stupid and robust.
  10. Rule of Least Surprise: In interface design, always do the least surprising thing.
  11. Rule of Silence: When a program has nothing surprising to say, it should say nothing.
  12. Rule of Repair: When you must fail, fail noisily and as soon as possible.
  13. Rule of Economy: Programmer time is expensive; conserve it in preference to machine time.
  14. Rule of Generation: Avoid hand-hacking; write programs to write programs when you can.
  15. Rule of Optimization: Prototype before polishing. Get it working before you optimize it.
  16. Rule of Diversity: Distrust all claims for “one true way”.
  17. Rule of Extensibility: Design for the future, because it will be here sooner than you think.
I think these are all great rules of thumb that every programmer should adhere to.

January 7, 2010

Why am I suddenly getting type or namespace errors in my ASP.NET web application

I just spent the last 20 minutes bashing my head against this problem, and I know that at some point it's going to come back and bite me again and I'm not going to remember how I fixed it, so this blog post is really just a reminder to my future self that this is how I fixed it - hopefully it will help others too.

I just added files from our source code repository that were contained within a folder within my APP_CODE directory. No sooner as I added them and I started getting the following error at every line that referenced objects contained in other files that resided directly in my APP_CODE directory.

"The type or namespace name could not be found are you missing a using directive"

I immediately checked that the namespaces were referenced correctly - and they were. I checked that the classes I were referencing were marked as public and that I could access them directly, and indeed, they were and I should.

My colleague @JohnMacIntyre (in a rare moment of brilliance) told me to check the web.config for the compilation settings. Sure enough I found:

<compilation debug="true">
    <codeSubDirectories>
        <add directoryName="helpers"/>
    </codeSubDirectories>
    <assemblies>
        <add assembly="System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    </assemblies>
</compilation>

I removed the <codeSubDirectories> section and hey presto, suddenly everything works again. The order of compilation is top-down with the APP_CODE directory being compiled last consequently if you have multiple folders defined here, code in earlier folders cannot be 'seen' by code in subsequent folders but not the other way around and none of the code in these folders can see code in your APP_CODE folder, however code in your APP_CODE folder can see all the code in those folders.

December 31, 2009

Ten years ago today, and where will we be ten years from now?

Ten years ago today, I was getting ready to experience my first New Year's celebration in Canada. If anyone from Citizenship & Immigration is reading this, can you please find out where the heck my citizenship has gotten to?! I took my test almost a year ago and I've heard nothing despite chasing you a number of times! I still don't know if I passed or failed even! I would like to pledge allegiance to the Queen (despite the irony of the fact that she was my Queen before she was yours given my British Heritage) and get my Canadian passport and so that I can actually get some value from my hard earned tax money you keep taking from me every pay cheque and actually voice my opinions at the polling stations! If you could get on that, I'd be most appreciative - it really sucks that I have to pay so much for something I have no right to vote about.

Now that's out of the way - where has technology gone in the last 10 years? Well, I recall days of trying to convince bosses that email on everyone's desk was a good idea and that internet access for all the developers in the company would actually make them more productive. That was a long hard fight. Today developers can barely function if the internet goes down and like most of them, I find it hard too. Thank god I can afford to line my bookshelves with the most up to date books so that if I can't waste time on Twitter, Facebook, Delicious or any number of other social distractions I can still work. Actually, now I think about it, I start to wonder if my boss at the time was actually right.

While the internet has become the backbone of most of our every day lives and has gone from strength to strength in terms of performance - now most of the free world has access to broadband I wonder where we're going from here.

Where will we be ten years from now? The "cloud" is picking up speed and looks like it will become synonymous with the internet. Service based applications that were touted to be the next big thing ten years ago are only just starting to become serious contenders as people have started to wrap their heads around the possibility of accessing their data from anywhere via any type of device they choose in the moment - especially as the performance of mobile devices picks up.

My prediction for the coming decade is that mobile devices will become so integrated into our lives that we will have a single mobile device that will be capable of handling our entire mobile life - from paying for your coffee at Starbucks to complete mobile access to information, visual and verbal communication, GPS, traffic, music. We're already close - the iPhone and Blackberry are almost there, in fact, they'd likely be there already if they weren't so hell bent on keeping everyone else out of their APIs. Although, maybe financial companies will actually wise up and quit using these stupid pin pads you see everywhere that can still be hacked and instead use fingerprint or iris recognition or something that can't be lost, stolen or hacked - an in the meantime actually make my life easier because then I can forget about remembering the PINs for dozen cards in my wallet.

In the home, I predict that we'll finally be able to have our home media centers set up the way we want instead of the way the Cable or Satellite providers dictate we must have them. If you're reading this Satellite and Cable providers, read my previous blog post and take heed of my rant about your ridiculous policies that force me to interact with my TV in a way that is completely retarded.

I believe that ten years from now, technology will be far less painful to use than it is today. When they say "plug it in and it'll just work", we might actually be able to believe that will happen - because today when you say that, as a developer I have to roll my eyes and say "Whatever". I think our lives will revolve a lot less around our computers - instead our lives will revolve around us living and our computers will do what they're supposed to - handle all the crap we don't want to deal with - like having to run around the house and make sure all the lights are off before we go to bed, that the door is locked, that the garage is closed, it will make sure the heating is on or off and the temperature is set correctly so I don't have to figure out the stupid thermostat for the 15th time this month. It will look after the pool for me so I don't have to worry about whether the chemicals are balanced, the cover is on or off, the water is topped up to the right level and that it's clean enough to use. While much of this is available today, most of the market lives quite happily without it - wasting time on tasks they hadn't considered could be completely automated. I believe this has largely to do with the prohibitive costs or the complexity in setting it up.

What else do I think we'll see in the next 10 years?...

  • The way we interact and search for information on the internet will be augmented or change dramatically. We will interact with it in a more natural manner.
  • As the performance of mobile devices increases and integration of positioning devices such as accelerometers, GPS, compasses, thermometers etc, we will start to see augmented reality becoming popular.
  • We've yet to really see information overload, although we've complained of it. In the next ten years, as the internet extends our reality in a more natural manner our ability to learn and interact with our environment will be changed in ways we can only begin to imagine.
  • As facial tracking and recognition software improves, we could look at someone and have access to all their tweets, blog posts, Facebook profile, resume, LinkedIn profile in a display of some kind - a contact lens perhaps?
  • Thought control of our devices giving us access to information just by thinking about it.

When it comes to technology, we are truly living in an exciting time. Imagine being able to look at someone, having our mobile device recognize them and then just by thinking "blog" we've got that displaying in our augmented reality contact lens, or checking their resume. Or we can call someone just by thinking about talking to them, their avatar shows up projected in front of us by our augmented reality lens - we could interact in a manner similar to Twitter in a virtual office space interacting with a group that aren't even there - except on our contact lens. The mind boggles at the possibilities that we're already on the cusp of producing.

I don't think that we'll see the ability to implant thoughts in people's heads though. It would be truly great if Matrix style, you could load a program in your mind and suddenly you're able to do something - like fly a plane, do complex math and understand things you couldn't understand before. Imagine where science would go then - if scientists had immediate access and understanding of everything they need to as a result of a single thought, then what as a race are we capable of? I think as our understanding of the human mind advances this will become possible, but while I'd be over the moon to see this in the next ten years, I don't think that's probable - perhaps in the next 50.