Thursday, May 31, 2012

Secret Santa

I was amused to see a Secret Santa app out on The Code Project: Drawing Names (A Christmas Name Drawing Application by ZachCox).  I too have a Secret Santa program.  But it's in VB.  Not VB.NET.  But actual VB - I wrote it in...checking...November 2000.  I've never brought myself to update it to a new language because it works fine in VB and I never felt like updating the code to handle the new style of dynamically creating controls which worked really well with control arrays in the old VB COM world so you could easily add new rows to the UI.

The programs look suspiciously alike.  Mine worries about who your spouse is as well.  And it worries about who you had last year and avoids duplicating your match up two years in a row.  It also relies on an XML configuration file (savable year to year).  And it mails a notice to every participant (via Outlook, I was lazy).  But it doesn't have nearly as much code as ZachCox's - I think 20% of my code is loading the XML and 20% is testing code, and 30% is the automated VB form code.  The primary code file is all of 19K.  The compiled app is 32K.  The most important bit of code in my opinion is the following...

     Do Until indivSecond <> indivFirst 
          If iTrys > UBound(people2(), 2) + 50 Then . . .

Yep, bit of hardcoding.  Basically, if it gets through the whole list, and is on the last match, and it just can't make it work after 50 tries plus the size of the list, it scraps everything and starts over from scratch.  So it can run for a very long time if it has to start over repeatedly, or you set it up to fail by making someone the spouse of everyone.  But in thirteen years of running it, sometimes repeatedly for testing purposes, it's never taken more than  a few minutes to run my whole family plus any guest family attending Christmas that year.  In this case, brute force of the logic works like a charm.

That said, every year I ponder rewriting it in C# and perhaps making it so people can log in and create lists.  And every year I realize it's the holidays and I'd rather go Christmas shopping, visit Christmas displays, and do anything else.  Just more proof that I'm a very utilitarian coder who uses  code solely to solve his own problems.

2 comments:

Anonymous said...

I have one of these as well. Written in Groovy.

Scooter said...

If it's written in Groovy, then mine must be older.