1. A Coding Fantasy
O nce upon a time, a talented young programmer was in a situation where he did not have the resources to seek more education. He had a dead-end job that would never allow any promotion. Further, his family could not help him, and he lived in a decaying and unsafe part of town. Our programmer had four friends who had developed similar programming skills and who also felt limited by their opportunities. They were all slightly depressed and worried about their futures.
Suddenly, the five programmers discovered an amazing opportunity. If they could team up and write a particular computer application, then the attention they would receive would immediately open doors for better jobs.
Of course, anyone in this situation would want to attempt to write the application. But it was not so simple. Previously, the most challenging program each of them had written took three weeks of time at 1-2 hours a day. Most of the time was spent in debugging. Some of those bugs were so difficult to track down that they had twice given up on their programs, only to come back to them out of curiosity. In fact, those three weeks of time were actually spread over six weeks. They all had the same experience.
Upon reviewing the work for this new project, it appeared that the job naturally could be divided into five equal parts. The problem was that each part was five times longer than anything any one of them had worked on before. They had 40 weeks to finish the project. In theory, if all could stay focused, that was more than enough time to finish. But in practice, the complexity was beyond what anyone thought he or she could do. The tantalizing prize was also an invitation to failure. Briefly each thought that the quiet go-nowhere life they were currently living might be preferable to 40 weeks of misery that almost certainly would lead to failure. Who needed that? Maybe something else would come along. Eventually in conversation, the five friends realized that this defeatist thinking is a common reason why people do not climb out of their poor situations in life. Yet, as each one currently understood the project, it was too difficult for them to complete. If they could increase the likelihood of success, then it might be worth a try. So, what to do?
First, the five programmers had to accept the fact that they would have to turn themselves into programming robots. Many of the pleasures that were part of their everyday lives would have to be replaced with hours of coding. This would require a change of both habits and perspective on life. Could they do this? The prize dangling in front of them just might be enough.
The real problem was debugging. Although all parts of the code seemed reasonable enough, there were so many parts that debugging problems would arise en masse. They didnt see how any one of them could be successful. Then someone suggested a solution: For almost every key function written, a companion function could be written to test that function. After each session of coding, the testing functions would be run. Another program would import most of the important functions and run several sets of data through each function. The data would test, for example, almost every if statement in a function.
This meant that if a redesign occurred, the functions adversely affected would be flagged immediately. Writing two functions for every one function needed in the application would be extra work, but the testing functions would be simple to write, and mostly similar to each other. This scheme, called unit testing , seemed to offer hope.
Another member suggested that the group get together every week to read each others code, to discuss problems, and to suggest solutions coming from fresh eyes. In these code reviews they would share both problems and hard-learned solutions. Another suggestion was to document almost every key function with an English description ( docstrings ), so that any of the other members could more easily follow the code. Another suggestion was that they should occasionally try to work in pairs ( pair programming ): one typing and the other thinking about what is being typed.
The group felt that their only chance at success was to adopt these conventions. One of the members later described working with these conventions as writing code in a straightjacket.
Soon after the coding began, the members noticed that progress was slow but steady. The inevitable redesigns, usually based on overlooked special cases and poorly chosen data structures, almost always caused a domino effect of other changes. These changes were all quickly noticed and located by unit testing .
The members also began discussing small differences in coding stylese.g., should one write
if (x and y) == True: print(x)
or
if x and y: print(x)?
Because of differing opinions, they decided to vote on a group style and stick to the groups decision. Eventually, their conventions, which were often arbitrary, began to look correct and any different convention looked wrong. Because the same style was used by everyone, they all became efficient at reading code written in their shop style.
To make a long story short, their combination of sacrifices , commitment , and good decisions about writing code enabled them to complete the project and win a better life. Eventually, they were hired by employers seeking expert programmers.
Their new employers appreciated the members of this group for several reasons. First, the programmers had put so much of their lives into writing code that their skills were excellent. They wrote code quickly and with few bugs. They understood their language, and used its constructs efficiently. Second, and just as important, their code was easily readable by anyone else. Third, they were flexible. They adopted the current house style in coding, even when they personally preferred to write code differently.
In some of the companies where these coders worked, there were layoffs. Our five original coders were never let go. As one employer said, They always give more than is expected. Who would let an employee like that go?
Years passed and they all retired from the business of writing code. One of the younger programmers was a little bored. He missed the coding experience, but was too old to return to full-time work. His spouse noticed that the neighboring high school needed a part-time teacher for a single one-semester class of advanced programming. He took the job.
The previous teacher expected the students to understand different algorithms and build their programming skills by correctly implementing the algorithms in computer code. The old programmer-turned-replacement teacher agreed, and realized that many of the conventions that were necessary for success in business would not apply to students writing small programs. Still, he thought, writing code that was readable was something that should be taught along with algorithms , language instructions , and data structures . Halfway through the course, he had lectured on and had posted the following guidelines.
Advice for Developing Programmers (pain management)
Limit functions to a single task, or to simple and highly related tasks ( cohesion vs. coupling ).
Label and align your output.
Document your programs at the top: name, date, class period (maybe course and instructor), title, and program description. Watch your spelling, grammar, and punctuation.
Code with line numbers and never indent less than three spaces.