Monthly Archives: November 2015

Just because someone fancies him/herself a competent programmer does not make it so!

While updating an application we inherited recently, Jeremy (one of our programmers) emailed me this example.  (This happens to be Visual FoxPro code, but we often encounter similar programming in Visual Basic, C++, and PHP code we inherit…)

This is really a circuitous way of performing a simple function.

This is really a circuitous way of performing a simple function.

“OK, Dave,” you’re probably saying–what’s so bad about it?  Well, a few observations come to mind:

1) Even with the comment above this code block, it’s difficult to understand what in the world the programmer was attempting to do.  There are much better ways to strip embedded spaces from fields.

2) The code uses single-letter variable names.  Suppose the program bombs, returning an error  message such as:  “Variable N not found.”  Guess how many times the letter ‘N’ occurs in this program?  How long will it take to find the specific ‘N’ being referenced?   Better:  use Hungarian notation.  For example:  lnX = AT(‘ ‘, … etc).   It’ll be a whole lot easier finding lnX in the code than trying to locate the specific instance of ‘N’ that caused the error.

3)  This code will write and rewrite strings to the database up to 20 times per record–when a single write per record would suffice.

4) This logic, spanning nine lines of code, creates a nested looping structure.  Nine lines will be much more difficult to maintain (and debug) than what’s needed.

So, how would we recommend changing the coding above?  How about a single line of code: 

UPDATE <table> SET ponumb=STRTRAN(ponumb,’ ‘) WHERE AT(‘ ‘,ALLTRIM(ponumb)) > 0

An added bonus:  this logic will only write to the database when a PO number actually contains embedded spaces.  The fewer times our code updates the database, the better.

Positive Feedback

Yesterday, a visitor to our website named Adam downloaded a copy of Contact! — our free contact manager software. But recent updates we made had introduced a problem with the installer.  This was the kind of problem that that wasn’t easily uncovered during beta testing.

When Adam called it to our attention, we updated the logic to address his issue.

I thought I’d share his response …

Subject:RE: Email verification for Contact
Date:2015-11-24 16:50
Hiya Dave 

The new download has resolved the issue.
Thank you very much for your prompt response and resolution of my issue with
your software.
It's nice to find a company that is prepared to take the time to resolve an
issue with their product instead of just ignoring the request. Even more so
when you consider the fact that your product is a free one.
Hats off to you Sir.

Kind Regards
Ajay (Adam)