Classic Computer Magazine Archive COMPUTE! ISSUE 52 / SEPTEMBER 1984 / PAGE 10

Don't Blame The Hardware

I am having a problem reading arrays on the Atari. This simple program is an example:

10 DIM X(5)
20 FOR I = 1 TO 5
30 READ X(I)
40 PRINT X(I)
50 NEXT I
60 DATA 3, 5, - 2, 7, 4

I always get an error in line 30. I wonder if my computer memory has gone bad.

Lloyd R. Holmes

When faced with a particularly stubborn bug, most programmers start to suspect the hardware—but it's almost never the culprit.

As a general programming rule, never assume the hardware is bad except as a last resort. Some program bugs are so obscure, so hard to track down, that it becomes pretty tempting to blame the hardware. Nevertheless, true hardware errors almost always exhibit outrageous behavior, such as lockups when you turn the machine on, screens that suddenly go haywire, an eerie, inexplicable hum when you use SOUND, etc. Hardware errors are obvious, except when just a few bytes of RAM go bad. You can buy memory test programs, but it would probably be an unnecessary investment.

The specific problem you're having here is syntactic. On the Atari, you cannot READ a data item directly into an array. READ X(I) is just as illegal as INPUT X(I). It's a lamentable eccentricity, but it is easy to get around. Just read the item into a temporary variable, then assign that variable to X(I). To wit: READ T:X(I) = T.

And remember The Programmer's Debugging Rule: Hardware problems are as obvious as they are rare.