Code as Part of the Software Development Process

Diomidis Spinellis
Department of Management Science and Technology
Athens University of Economics and Business
Athens, Greece

Code as a Scientific Communication Vehicle

Social processes that contributed to the success of mathematical theorems:

Gains from High-quality Code

We learn:

Recognize Low-quality Code

Requirements Can Lead to Strange Code

How to Familiarize Yourself with a Body of Code

Don't panic! Don't Panic! (typically you don't have to understand all the code)

Four steps:

  1. Build
  2. Browse
  3. Improve
  4. Contribute
What you gain from OSS is a loan that you have to repay.

Code Reading Reasons

Code as Exemplar



Example: tail -f (NetBSD)

        while ((ch = getopt(argc, argv, "b:c:fn:r")) != -1)
                switch(ch) {
                case 'f':
                        fflag = 1;


        for (;;) {
                while ((ch = getc(fp)) != EOF)
                        if (putchar(ch) == EOF)
                if (!fflag)
                 * We pause for one second after displaying any data that has
                 * accumulated since we read the file.  Since sleep(3) takes
                 * eight system calls, use select() instead.
                second.tv_sec = 1;
                second.tv_usec = 0;
                if (select(0NULLNULLNULL, &second) == -1)
                        err(1"select: %s", strerror(errno));

Example: tail -f (FreeBSD)

        if (fflag) {
                kq = kqueue();
                if (kq < 0)
                action = ADD_EVENTS;
        for (;;) {
                while ((ch = getc(fp)) != EOF)
                        if (putchar(ch) == EOF)
                if (! fflag)

                switch (action) {
                case ADD_EVENTS:
                        n = 0;
                        ts.tv_sec = 0;
                        ts.tv_nsec = 0;

                        if (Fflag && fileno(fp) != STDIN_FILENO) {
                                EV_SET(&ev[n], fileno(fp), EVFILT_VNODE,
                                    EV_ADD | EV_ENABLE | EV_CLEAR,
                                    NOTE_DELETE | NOTE_RENAME, 00);
                        EV_SET(&ev[n], fileno(fp), EVFILT_READ,
                            EV_ADD | EV_ENABLE | EV_CLEAR, 000);

                        if (kevent(kq, ev, n, NULL0, &ts) < 0) {
                                action = USE_SLEEP;
                        } else {
                                action = USE_KQUEUE;
kqueue, kevent - kernel event notification mechanism

Maintenance and its Tools


Maintenance activities often take 80% of the effort over a complete life cycle.

Maintenance Activities


Example: locating the authentication code in the ftp command.


If the two environments differ a lot: focus on interfaces.




The only valid measurement of code quality: WTFs/minute

Further Reading

Exercises and Discussion Topics

  1. Are there examples of "open-source" communication in other engineering disciplines?
  2. Discuss possible business models behind an open-source distribution.
  3. Download, build from source, and install a small open-source program. (easy)
  4. Install an open-source operating system on your PC (e.g. FreeBSD (, Debian (, NetBSD ( (moderate)
  5. Modify your system's kernel to log all accesses to files in the /etc directory. (difficult)