Code as Part of the Software Development Process

Diomidis Spinellis
Department of Management Science and Technology
Athens University of Economics and Business
Athens, Greece
dds@aueb.gr

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

Reasons

Strategy

Example: tail -f (NetBSD)

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

[...]

        for (;;) {
                while ((ch = getc(fp)) != EOF)
                        if (putchar(ch) == EOF)
                                oerr();
                [...]
                if (!fflag)
                        break;
                /*
                 * 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));
                clearerr(fp);
        }

Example: tail -f (FreeBSD)

        if (fflag) {
                kq = kqueue();
                if (kq < 0)
                        err(1"kqueue");
                action = ADD_EVENTS;
        }
        for (;;) {
                while ((ch = getc(fp)) != EOF)
                        if (putchar(ch) == EOF)
                                oerr();
[...]
                if (! fflag)
                        break;
                clearerr(fp);

                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);
                                n++;
                        }
                        EV_SET(&ev[n], fileno(fp), EVFILT_READ,
                            EV_ADD | EV_ENABLE | EV_CLEAR, 000);
                        n++;

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

Maintenance and its Tools

Evolution

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

Maintenance Activities

Strategy

Example: locating the authentication code in the ftp command.

Porting

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

Refactoring

Reuse

Inspections

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 (http://www.freebsd.org), Debian (http://www.debian.org), NetBSD (http://www.netbsd.org)). (moderate)
  5. Modify your system's kernel to log all accesses to files in the /etc directory. (difficult)