Vviewpoints
Article development led by
queue.acm.org
I
M
A
G
E
B
Y
K
O
N
G
S
A
K
Dear KV,
Forgive me, for my ACM membership has lapsed, and for my sins I
have been saddled with mentoring a
spaghetti coder.
I am working on a piece of new software—greenfield for once—but with
stiff reliability requirements. My helper, a young, self-proclaimed “devop,”
aims to improve as a programmer, and,
unfortunately, this person got stuck
with me.
No matter how hard I constrain
the work I dole out, I just cannot stop
this helper from the obscene coupling
known as spaghetti code, all masquerading under obsessive, perfect syntax.
We cannot even get into the hard reliability aspects of the software, because
tangled messes that lint perfectly and
break opaquely just keep piling up.
After many approaches, each one
narrower in scope than the last, I
have come down to doling out work
units that are constrained to writing single, well-defined functions
in a Python library, but even then I
am failing to keep this person from
needlessly chaining functions, silently mixing and transparently
passing data through multiple layers of interfaces, and, most painfully, burying important error output in ways we all know too well as
spaghetti code.
Assuming this apprentice is will-
ing and eager, how can one go about
breaking this fundamental coupling
mentality in implementation and
open this person’s mind to engage
the actual problem at hand—what the
software does!
I do not want to botch this and produce the next Darth Vader!
Mr. Function Defines Form
Dear Function,
Well, at least you didn’t mention goto,
the root of much of the spaghetti code
of my well-spent youth. Yes, KV was
once young, but because of programmers such as your ward, he has never
looked young or beautiful.
Once upon a time, spaghetti code
was defined by the fact that it jumped
all over the place without any rhyme
or reason, but, as you say, you have
someone, who even when given a constrained contract such as single functions, is still able to make a plate of
pasta of it.
Perhaps it is time to introduce the
idea of narrative to your Padawan.
Code, as I have pointed out countless
times, is a form of communication
between the people who write and
maintain it and is only incidentally
executable on a machine, which we
call a computer. I cannot seem to say
Kode Vicious
The Obscene Coupling
Known as Spaghetti Code
Teach your junior programmers how to read code.
DOI: 10.1145/3267356