Monday, January 29, 2007

Programming Shims

When I was at CodeMash, I attended a very cool session given by Neal Ford called The Productive Programmer. In this session Neal talked about "... how to become a more productive programmer every day by using tools that you didn't know you already had." Some of the stuff was no-brainer stuff. I was happy to find that a lot of the things discussed where things that I already practice. Here is a brief list of all the things I can remember:
  1. Learn all IDE shortcut key combinations
  2. Get a refactoring tool (ie. Resharper or Refactor! Pro)
  3. Write shims where possible (more later)
  4. Learn Regular Expressions!
  5. Find a scripting language you like and use it
  6. Find a good text editor (notepad++, editplus, etc...)
    1. Multiple Clipboards
    2. Macro Support
    3. Regular Expressions
    4. Customizable Shortcuts
    5. File Templates
    6. Allows Plug-Ins
  7. Learn to love and use macro's
  8. Etc...
He went into a couple of stories where he had to write little apps to help automate simple things that were a bit timely up front, but saved time in the long run. For example, he was part of a team that was split between many different offices (even across seas) and the team was using Subversion for to version their source code. Every time the development team checked in the code, they had to provide a simple comment on what changed. At the end of every week, they had to update their corporate wiki with notes about what they did that week. We do this at Data Dynamics and I do see how this is rather redundant; developers are forced to update the information in two places. Neal decided to write a "shim" to fix this... He wrote a script to take the users comments from their source file check-ins and update their status page on the wiki with this information (files checked in, what time, comments, etc...).

He claimed that the little bit of work he did to figure out how to do this has really improved the overall productivity of the whole team. Developers just check-in their source files and their wiki's are updated automatically. Plus, the project leads and product managers were able to check the various wiki's with an accurate reading of what got done at the end of every day. They no longer had to wait til the end of the week and then rely on developers to remember to update their status pages.

I admit that I get caught up in writing shims a lot. I actually wrote one the other day in Excel. My mother-in-law is an accountant and every year, her and her secretary (who is actually her sister; my aunt-in-law if you will) have me print out daily schedule forms for them. I've tried to convince them to use Outlook or something similar to keep track of appointments, but they insist on the paper form...

Anyway, every year I have to create an Excel sheet that starts from the first week in the next year to the week of April 15th (unless April 15th falls on a weekend, in which case do that next week). Each page represents a single week and appointments run from 7am to 7pm in 1/2 hour increments on each page. I dread doing it every year because I always have to rebuild it or use last years file and modify / edit / format it accordingly. Last week I decided to just sit down and write a "shim" to do it instead. Here it is:
Sub CreateScheduleSheet()
Dim year As Integer
Dim eachDay As Date
Dim columnIndex As Integer
Dim rowIndex As Integer
Dim wereDone As Boolean
Dim thisCell As Object

' get the year
year = CInt(InputBox("What year do you need the sheets for?", _
"Year Entry", Format(Now(), "yyyy")))

' get the first date cell
' since the sheet has to start on a sunday, find
' the first sunday (on or before) the first of the year
eachDay = DateSerial(year, 1, 1)
Do Until Weekday(eachDay) = 1
eachDay = DateAdd("d", -1, eachDay)

' start at b2 and loop through all columns til we're done
wereDone = False
columnIndex = 2
rowIndex = 2

Do Until wereDone

' get the current cell and increment the column index
' if the date a saturday, skip a column
Set thisCell = Sheet1.Cells(rowIndex, columnIndex)
columnIndex = columnIndex + IIf(Weekday(eachDay) = 7, 2, 1)

' set the date and increment the date
thisCell.Value = Format$(eachDay, "m/d/yyyy")
eachDay = DateAdd("d", 1, eachDay)

' check to see if we're done yet (remember to end on a saturday)
If eachDay >= DateSerial(year, 4, 15) Then
If Weekday(eachDay) = 7 Then
wereDone = True
End If
End If
End Sub
It works rather well and has already come in handy actually. I printed out the wrong year the first time, so I just came back home, ran the macro with the new year, and viola. It has some assumptions built into it, but it serves a single purpose and has already saved me a small chunk of time. Now I won't dread it when I remember I have to create a paper schedule next year during tax season.

No comments: