Wednesday, February 18, 2009

Campground Rule for Modifying Code

Dealing with other people's code challenges most software developers. If you program professionally, you can't avoid it. Any project of reasonable size requires multiple developers, meaning someone other than just you. Even if you only deal with your own code, it may look different to you later. At one job, I remember looking at something thinking, "who wrote this?" -- only to find in the comments that it was me, about 10 years earlier.

Code that has been in use for any length of time tends to rot. Design decisions that made a heck of a lot of sense five or ten years ago, when machines were less powerful and memory more expensive, seem silly -- perhaps wrong. As revision after revision is piled on, it tends to make a mess. Add to this the hands of a hundred programmers -- each one knowing the one true way to write code -- and a lot of code tends to become a hopeless jumble.

Worse, that hopeless jumble is tested and works. 

As Joel Spolsky explained, modifying existing code has two dangers. First, code is hard to read, and that hopeless jumble you're trying to enhance already does things that you won't understand without a lot of work. Second, the more you alter the code, the more you'll have to retest to ensure you haven't broken the existing functionality.

Now, if you are lucky enough to have a full suite of unit tests, then you can let yourself go wild and refactor with the assurance that the unit tests will catch any errors. But this is old, revised code. Even if you have unit tests, they probably are out of date or perhaps they no longer work.

One thing that I remember from Boy Scouts -- you have to have the right attitude toward camping. Ideally, you should leave a campsite without any evidence that you had been there. That's probably not possible. But our scoutmasters had  a simple for us to follow: always leave the campsite cleaner than when you arrived. 

This rule applies equally well to code. No matter how badly some bit of code has been abused in the past, you can always have it leave your hands in better shape than when it arrived. If the code needs comments, add them. As you figure out how something works or some obscure requirement that's buried in the code -- note it for future programers. 

If the code has a jumble of if-statements, and you can restructure it to be more clear, do so. If you find dead code, eliminate it. Just be ready to test it fully before you leave it for the next developer. No matter how much you temper your changes, you can always do something to improve the code for the next guy.

And if everyone did this, we'd have fewer hopeless jumbles.

Sunday, February 15, 2009

Your Novice Accent, Revisited

When I received my Novice license back in 1975, the ARRL sent me a little pamplet on the proper procedures for CW operating. It was a reprint of an article by Keith S. Williams, W6DTY from the November 1956 issue of QST: Your Novice Accent (and What to Do about It). I read it many times before I had a transmitter on the air. I'd heard some of the poor operating practices that W6DTY noted. Even in 1975, things had changed somewhat since W6DTY penned that article. Still, it was a great resource for proper operating procedures and helpful operating tips.

The Novice bands of the 1970s, 80s and early 90s were hotbeds of slow speed CW activity. Any time of the day, and most of the night, you could find QSOs in progress in the 80 and 40m Novice bands. By the 1990s, things had changed, and the code-less Technician class became the preferred entry into the hobby.

Today, the Novice bands are no longer -- and new CW operators are thrown into the mainstream, as they were in the 1940s. Although it's harder to find slow-speed QSOs on the bands to copy, and many of the operating procedures have changed. Perhaps it is time to revisit Your Novice Accent.

International Morse code is just as much a language today, although the dialect has changed. The old procedures came about from the operating practices in the 1930s, when most stations were crystal controlled. It's hard to imagine today, but a typical contact might take place between two stations who were many kHz (well, kc in those days) apart. With only a handful of crystals, hams would work across the entire band.

The Novice license originally required crystal-controlled transmitters, from the early 1950s until 1972. Most Novices in this era likely had only one or two crystals for each band. (if they were lucky)

Today's operating is almost entirely simplex -- the two stations transmit on almost exactly the same frequency. Certain types of DX and contest operation end up being split in frequency, but split is the exception.

Tune Around

W6DTY's first bit of advice -- tune around and listen. This is great advice today, but for different reasons. Of course, we no longer wait for the filaments to warm up -- solid state rigs are ready to go when switched on. We still tend not to listen much -- tuning around the band will give you an idea of what is happening. I once worked ZL4PW during a very short opening around midnight local on 30m, just from tuning around.

W6DTY advises to answer another CQ rather than adding your own. Tuning around should let you find anyone calling CQ. Given th elower activity levels on today's CW bands, often a CQ or two would be welcome -- many times the bands are open, but no one is transmitting.

If you do CQ, it's no longer expect for you to tune around many kHz for an answer. Crystal control is no longer the norm, so it is OK to expect an answer on or about your frequency. Tuning a kHz on either side of your frequency should be more than sufficient.

Calling & Answering a CQ

The form of a CQ has changed a little bit from the 1950s. While the basic three by three still applies, there's no reason to repeat this three times. Instead, the basic three by three can be interspersed with periods of listening:

CQ CQ CQ DE AA4LR AA4LR AA4LR K
... listening ...
CQ CQ CQ DE AA4LR AA4LR AA4LR K
... listening ...

Listening periods are short, just a few seconds. These short listening periods allow another station to respond without having to wait a long time.

During a contest, this process might be even more abbreviated:

CQ TEST AA4LR
... listening ...
CQ TEST AA4LR
... listening ...

Notice that we have entirely dispensed with prosigns -- the DE and K are implied.

Answering a CQ is also simplified. There's no need to repeat the CQing station's call three times. After all, he's not going to have to tune around to find you -- you should be calling close to his frequency. You still must decide how many times to send your own call. If conditions are good, once might be enough. In more marginal conditions, two or three times may be more appropriate:

AA4LR DE W1YM W1YM

(Note we've omitted the prosign AR) Quite often, operators dispense with the CQing station's call and the DE prosign altogether -- answering stations simply send their own callsign once or twice, and listen for a response.

The DE prosign is most properly used to  separate the called station's callsign from the caller's callsign. If you are just sending your own callsign, there's no reason to send DE.

Making QSOs

The structure of a beginning QSO hasn't changed in 50 years. We still send RST, QTH and Name, and pretty much in that order:

W1YM DE AA4LR R TNX FER CALL BT UR RST 579 579 IN LOGANVILLE GA LOGANVILLE GA BT NAME BILL BILL BT RIG HR ... etc

Prosigns &  Abbreviations

While many of the formal procedures have been dropped for brevity, we still use abbreviations for the same reason. The ES prosign is actually an old American Morse character for the and symbol (&).

W6DTY's advice about using the BT prosign as a separator of thoughts and ideas is still sound today, as well as avoiding the period and comma.

HW? is typically used today. I can't say that I've heard WATSA? recently.

Most operators today dispense with sending the AR before signing over. They simply sign over:

... BT HW? W1YM DE AA4LR K

The prosign KN seems to get more abuse than any other. It was all too commonly used on the Novice bands, and is much less common today. There's probably no need to use KN in ordinary QSOs. Just use K.

The prosign VA appears today as SK (it's the same prosign -- didididadidah, we just abbreviate it differently). Since the use of AR has diminished, SK more frequently appears as a substitute for K.

W6DTY's advice on the proper use of the R prosign is dead-on today. And, I have encountered a few operators who fall into the deadly silences. I hope I don't do that.

Sloppy sending is still around 50 years later. Although you do hear quite a bit of precise, computer-generated CW these days. It's a pleasure to listen to. Practicing sending before getting on the air is great advice today. Be sure you can handle the key or paddles with confidence. 

CW remains great fun, even 50 years later. There's a timeless quality about it -- it never gets old.