Subject: A Programmer's Sixth Sense

From: Shlomi Fish <[email-masked]>
Date: Sat, 11 May 2002 11:00:45 +0300 (IDT)

To me it seems that I can take a quick glance at a C code and immediately
gather how well it is written, even if I don't understand it. I can't
quite explain how I feel that way, but I do.

I think after you understand everything that goes on in the code, than
most experienced (and good) programmers can have a good estimate of it.
But I'm not sure if feeling how good it is, can be explained in some way.

I'm definetely against "feeling" rather than knowing and reasoning
assertions. But I suppose some experts can have first impressions that can
eventually be reasoned, and usually found to be correct.

I can give various examples. For example, I cannot understand most of the
code of the Linux kernel, but I know it is well-written, just by looking
at it. I know that the GIMP is well-written, even though its codebase
could use a lot of commenting. I looked at a fellow student's code, that
he prepared for our "Structure of OS" course, and could tell it was awful.
(even though, this time I understood what was going on there) PySol seems
well-written to me (at least its game logic), but it usually takes me a
long time to understand what's going on there, because the code is highly
OO.

Regards,

	Shlomi Fish

----------------------------------------------------------------------
Shlomi Fish        [email-masked]
Home Page:         http://t2.technion.ac.il/~shlomif/
Home E-mail:       [email-masked]

"Let's suppose you have a table with 2^n cups..."
"Wait a second - is n a natural number?"

---

From: Muli Ben-Yehuda <[email-masked]>
Date: Sat, 11 May 2002 11:03:29 +0300

> quite explain how I feel that way, but I do.

There is no metric to gauge how well a piece of code is written. It
might be nonsense to you, poetry to me, and line noise to someone
else. 
 
> code of the Linux kernel, but I know it is well-written, just by

You knew it was the linux kernel before you looked at it. 
FWIW, some parts of the kernel are horribly written. 

> could use a lot of commenting. I looked at a fellow student's code,

You knew it was the GIMP you were looking at. You expected it to be
good, and it was. 

> he prepared for our "Structure of OS" course, and could tell it was

You expected it to be awful, and therefore it was. It's a self
fullfilling prophecy. 

On a related tangent, big open source projects *have* to be written
well, since the code is one of the only line of communication between
the developers. If the code was not well written, the project would
either wither and die, or get rewritten. 
-- 
The ill-formed Orange
Fails to satisfy the eye:       http://vipe.technion.ac.il/~mulix/
Segmentation fault.             http://syscalltrack.sf.net/

---

From: "David" <[email-masked]>
Date: Sat, 11 May 2002 11:47:24 +0200

I have been installed both Mandrake and Red Hat Linux about 10 times each
... This is not because I cannot install it , or run it ... It's because I
can't seem to find any good drivers for 1. My modem : Alcatel Speedtouch USB
                 2.My soundblaster : Maxi Studio ISIS
Does anybody know a good list of all hardware that is compatible with Linux
?

Thx in advance,

David Savoir
----- Original Message -----
From: "Muli Ben-Yehuda" <[email-masked]>
To: <[email-masked]>
Sent: Saturday, May 11, 2002 10:03 AM
Subject: Re: [hackers-il] A Programmer's Sixth Sense

> To unsubscribe from this group, send an email to:
> [email-masked]
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>

---

From: Shlomi Fish <[email-masked]>
Date: Sat, 11 May 2002 18:04:28 +0300 (IDT)

> might be nonsense to you, poetry to me, and line noise to someone

I agree that well-written of a piece of code is not a uni-dimensional
scalar (i.e: belongs to the R field), but there's still some ways to
estimate it. At least once you are very much familiar with it.

> You knew it was the linux kernel before you looked at it.

I don't think that's why I thought so. Many people voice their opinion
that the Linux kernel is generally well-written, but until then I did not
know how well it was.

> FWIW, some parts of the kernel are horribly written.

Naturally, you can expect this in such a large codebase, with so many
people writing different parts of the code. Who is John Galt?

> You knew it was the GIMP you were looking at. You expected it to be

Probably. I judged it according to the interface it gave for scripting.
Actually, I actively hacked on one part of it (the gradient editor) and it
actually was faulty in not having a clear separation of the GUI from the
gradient manipulation logic. And I wanted to create a gradient scripting
layer (and eventually was able to).

That does not mean it was bad, just that some important feaure escaped its
author. This is natural, considering your first releases can always be
improved upon.

> You expected it to be awful, and therefore it was. It's a self

Actually I expected it to be relatively good and was heavily disappointed.
The code itself was legible, but very badly written and designed.

> either wither and die, or get rewritten.

<sarcasm>There can be no metric to measure how well should a code be
written</sarcasm> (;-)).

Taking on on what Chen said, I can say that I had also an experience in
which I slightly changed my opinion about a piece of code. The code in
question was MikMod, which was an ANSI C MOD player that I converted to
Java thru several stages of C++. At first I believed it was well-written.
Later on, I discovered that it had a lot of limitations, but then again,
maybe it was my fault for believing that I could convert it well by
converting every C file into a class.

MikMod became open-source a few years ago, and is still the most popular
library for playing MOD files on UNIXes. I stopped maintaining the Java
version, but it was operational and stable when I finished working on it.
Someone should adapt it to JDK 1.4.x, but like I said, the code is
extremely non-Javaish.

Regards,

	Shlomi Fish

---

From: Oleg Goldshmidt <[email-masked]>
Date: 12 May 2002 08:19:49 +0300

> But I'm not sure if feeling how good it is, can be explained in some

An experienced programmer can probably estimate whether or not he/she
will be able to understand what is going on *and* whether he/she will
be able to maintain it if needed *before* acrually understanding what
is going on. Attention probably latches on familiar patters, snippets
of logic, well thought through identifiers, usage of various
abstraction and modularization techniques (e.g. ADTs), etc.

I suspect the basic feature is readability, including things like
consistent indentation, judicious use of whitespace and comments, and
on top of that come easily recognizable techniques that are perceived
as useful and beneficial.

It is probably easier to determine that code is bad. If it is not
intelligible at first sight, it likely is. ;-)

> code of the Linux kernel, 

You probably can, just not on the first reading. You (and me) need to
invest significant effort. It is rumoured that Linus doesn't need
to...

> but I know it is well-written, just by looking at it.

It is possible that you *know* it is well written. IMH(umble)O, there
are pieces that are not written well at all. It is probably individual
to a large extent. 

-- 
Oleg Goldshmidt | [email-masked] 
If it aint't broken it hasn't got enough features yet.