Simple Programming Fixes

I spent a substantial part of my engineering career programming, starting with geophysical-type cases when I was working my way through school. One or two stand out as the types of screw-ups this column recounts.

The first was back in the days of CDC 6000 machines, in the days of programming on cards, FORTRAN, in fact. In those long-gone days, the compiler output was commonly punched out as a deck of cards. A "job" was fed into the machine as a deck of cars followed by data also punched on cards. So, from the heft of the stack of cards, it was easy to get a visceral feel for the efficiency of the program.

A guy I knew needed a program to do some fairly simple data manipulation. After a few months and failure of the program to do what was needed, he told a friend about his troubles. The friend was able to write a program in a couple of hours that not only did what was needed, but was one-third the size of the original program.

Decades later, in the days of NextStep, I was asked to help solve a disconcerting "memory leak" problem in a large piece of special-purpose business-processing software. The leak rate was high, about a megabyte a minute, which wasn't tolerable in working software. I set the software up on my computer running the test suite and let it run for about 10 minutes. Then, I stopped the code, converted the Next swap file to a regular file, sent it though strings, piped it into a disk file, moved the file to the local server, and emailed the people who had asked to take a look. This listed all the occurrences of readable text and sorted it with a count on each identical string.

About 10 minutes later, several of the programming staff came by wailing that everything was leaking. They figured out that someone (who had by that time left the company) had turned on the "No reuse" flag in the compiler to help with debugging, so no memory was being returned after temporary use.

Keith Henson is electrical engineer, a proto-transhumanist, and a writer on life extension, cryonics, memetics, and evolutionary psychology.

Bobengr, I will make the assertion again, which is why self driving cars will never work: ALL of that code is written by programmers, and programmers are NOT normal people. That is not intended as an insult, just an assertion that states that no car drivingf code will be able to handle exceptions.

I remember fixing punch card errors by taping chads into the punch holes that were wrong and then cutting new holes with a very small pocket knife. And the cards ran, but it was important to cut carefully.

WilliamK. wrote: ". I once fought what appeared to be a hardware noise problem for a week, and it wasn't until I got the software guy to add a way to view the input readings directly that it became clear that it was a path-dependant multi-tasking problem. He had used the same name for two different variables used in separate parts of the program, and depending on the timing between the two parts, that could cause errors."

I remember a similar situation. A couple of our co-ops had done a senior project involving an FPGA and some code which monitored a communication bus. During development it was rock-solid, but as they added flourishes (and approached their deadline), the device began declaring faults when there were none. The two hardware co-ops asked me to step in. (At that stage, I had a reputation for magic fingers.)

By this point they had done everything they could think of to suppress noise, ground wires everywhere, copper foil tape everywhere else, but still a problem. After looking at a few signals which seemed very clean, I asked to look at the code.

The co-ops apologized that the third co-op, who had written the software, wasn't there to explain it, but they showed it to me nevertheless. It was pretty obvious from the code indentation and white space that the programmer had written the main function and later slapped a loop around it to repeat. What he had not done was to re-initialize a variable used inside the loop. I noticed this after just a minute or two of study.

I added one statement to set the problem variable to 0 and commented it heavily. The project ran as it was supposed to. Later on the programmer co-op called me to ask what I had found, and how I had found it. I pointed out that C automatically sets all integer variables to 0 at first usage and so he had not re-initialized it at each iteration. Had he been programming in FORTRAN he wouldn't have made this mistake because variables aren't initialized. (Probably why I was attuned to the error.)

Hello Nancy--thank you so much for the Personality Test. Two great web sites. I took the test and here are the results for me. I never though I was a loaner but when programming, I really need peace and quite; door shut, TV and radio off, no grandkids, no impending appointments, etc etc. (Where do you get a life like that?????? ) Again, many thanks. Bob

You're a Doer.You are very quick at getting tasks done. You believe the outcome is the mostimportant part of a task and the faster you can reach that outcome the better. After all, time is money.

You like coding at a High level.The world is made up of objects and components, you should create your programsin the same way.

You work best in a Solo situation.The best way to program is by yourself. There's no communication problems, youknow every part of the code allowing you to write the best programs possible.

You are a liBeral programmer.Programming is a complex task and you should use white space and comments asfreely as possible to help simplify the task. We're not writing on paper anymoreso we can take up as much room as we need.

bobjengr, your comment about type "A" personalities and programming caught my eye because as a programmer - I sometimes exhibit Type A personality in my urgency to get the task done - I have spent hours straight into the wee hours on a program not due to patience, but due to both the satisfaction of the programming task and the desire to "make it work." Your comment prompted me to google programmer personality types and I came up with a couple of interesting links. The first one describes several different programmer personalities and the second one is a programmer personality test which I took - it was fun and labeled me fairly accurately...

I remember punch cards, too. That's the reaon I became an electrical engineer rather than a software engineer: I couldn't imagine spending my time sitting at a keypunch machine or waiting in line at the card reader to run my program. Obviously, I'm not a good person to ask about the future of technology!

Some micros are a little picky about memory space because the op-code used for fetching from RAM is different than fetching from ROM (or FLASH). If the compiler is forgiving it will allow you to mix and match where the string is located without objecting. As always, just because it builds doesn't mean it's correct. The better compilers keep track of the string's location and issue an error if you try to fetch a variable in RAM instead of variable that is really a constant FLASH. As a rule I try to make as many objects constant as possible because RAM is typically in much shorter supply than FLASH.

Interesting indeed. Not really a software problem, nor really a hardware failure. One of those firmware faults where setting a switch that "seemed like a good idea at the time" had some later unintended consequences. I once fought what appeared to be a hardware noise problem for a week, and it wasn't until I got the software guy to add a way to view the input readings directly that it became clear that it was a path-dependant multi-tasking problem. He had used the same name for two different variables used in separate parts of the program, and depending on the timing between the two parts, that could cause errors. A software problem found by the hardware guy, (me). But it took a week of chasing to convince others that it was not hardware.

Focus on Fundamentals consists of 45-minute on-line classes that cover a host of technologies. You learn without leaving the comfort of your desk. All classes are taught by subject-matter experts and all are archived. So if you can't attend live, attend at your convenience.