[Ilugc] .a-tip-a-day (patch - apply diffs and act as inverse of diff)

  • From: rmathews@xxxxxxxxx (Roshan Mathews)
  • Date: Wed Sep 30 20:16:59 2009

I had told myself to leave when things get flamy, but this is hard to
walk away from, so just a few words. (Muhahahaha..)

On Wed, Sep 30, 2009 at 6:01 PM, Kapil Hari Paranjape <kapil@xxxxxxxxxxx> wrote:

That is certainly true. There are indeed a large number of good
programs written in C --- however, even those programs would be
almost un-understandable if the comments are stripped out!

This is so not true!  There are tons of very hairy C (by which I mean
subtle, so you have to pay attention) that are still very
readable/understandable.  I remember K&R and UPE having lots of
examples which made me marvel at their ability to write C code which
was direct translations of English text, which was a direct
translation of a thought in their head.

The kind of things you talk about, like assigning a char to an int
and so on are _precisely_ the things that make the language difficult
to understand since one has to run a small compiler + semantic
analyser in one's head to keep track of programs that do that.

There is much merit in your words above, but it's like saying "you
shouldn't eat apples because oranges have lots of vitamin C".  Aye,
Python allows you to defer decisions about types till much later, but
that doesn't make C hard.  C++ sure, many would agree is hard, but C
itself is a very simple language, which is why it is so popular.

Readable code is not necessarily efficient. For example, in Haskell,
one definition of the list of primes is:

 primes :: [Integer]
 primes = sieve [2..]
       where sieve (p:xs) = p : sieve [x | x<-xs, x `mod` p /= 0]

This is almost exactly the mathematical definition of the Sieve of
Eratosthenes written thousands of years ago! So it is very readable
(comments are not required!). However, it is not an efficient program!

It is readable because you understand the syntax.  Since I have only
had Haskell code shown to me, I can make out that the first line says
that primes is a list of integers, which is the sieve of the list 2
and 'something', that something is a car/cdr list with the car
followed by gobbledegook, here I guess what it's doing from what I
know of sieves not from the code.  (x, where x comes from xs, such
that x%p <> 0)

Also the readability vs. efficiency issue isn't that simple.  OCaml, I
hear, is very very efficient, and very strongly typed, but with type
inference, so your code apparently won't have many type annotations.
The ideal language would be something that looks like Python and runs
like optimized C.

Hope this clarifies --- and douses the flames a bit!

I hope the same, clarification and flame dousing, and world peace,
while we're at it.

Roshan Mathews

Other related posts: