public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Bob Plantz <plantz@cds1.net>
To: Joel Dice <joel.dice@gmail.com>
Cc: "W.H. Kalpa Pathum" <callkalpa@gmail.com>,
	gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: Could you please explain this code segment
Date: Thu, 17 Dec 2009 19:53:00 -0000	[thread overview]
Message-ID: <1261075878.2170.50.camel@bob-desktop> (raw)
In-Reply-To: <alpine.DEB.2.00.0912171013210.30036@jdpc.ecovate.com>

On Thu, 2009-12-17 at 10:40 -0700, Joel Dice wrote:
> On Thu, 17 Dec 2009, Bob Plantz wrote:
> 
> >
> >
> > I have seen many, many examples, both in industry and in academia, where
> > programmers write tricky code claiming it is more efficient. I claim (a)
> > efficiency is seldom an issue, and (b) looking at the generated assembly
> > language almost always shows it is not more efficient.
> >
> > I believe that the best code is that which (a) correctly solves the
> > problem, and (b) is the most simple-minded in appearance.
> 
> Perhaps, but the code in question here is not merely obscure - it's simply 
> meaningless.  I think it's a mistake to put such code in the same category 
> as e.g. an affine transform implemented in inline assembly which has 
> well-defined meaning.  The latter may pose a challenge for a maintenance 
> programmer, but at least it will yield to persistence.  In contrast, 
> undefined code is no better than a "todo" comment - you're only option is 
> to replace it completely with something well-defined based on the 
> documentation and/or context.
> 

I agree that there are situations where obscure code is the best,
perhaps the only, way to solve the problem. For example, in 1984 I had a
consulting job where one of my assignments was to write a logarithm
function for an embedded MC68000 environment. The only way I could get
the required speed and accuracy was to use double-precision integer
arithmetic. I wrote it in assembly language and used several "magic
numbers" to keep intermediate values in range while maximizing
arithmetic significance. My comments took more space in the listing than
the actual code. To their credit, the programming team asked for even
more documentation during my walk-through of my code.

These situations are uncommon -- and lots of fun to solve!

The most common uses of obscure code that I've seen are programmers
showing off their "understanding" of the language being used. I believe
that a good programmer does not ask what his/her code does, but rather
explains it -- either through simple, easy-to-read code, or with
thorough commenting. I use the term "good" to mean relative to the
programmer's skill level.

--Bob


  reply	other threads:[~2009-12-17 18:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-17  8:22 W.H. Kalpa Pathum
2009-12-17  8:46 ` Ineiev
2009-12-17 12:20 ` John (Eljay) Love-Jensen
2009-12-17 17:04 ` Bob Plantz
2009-12-17 18:52   ` Joel Dice
2009-12-17 19:53     ` Bob Plantz [this message]
2009-12-17 20:11 Bill McEnaney
2009-12-17 20:22 ` Brian Budge
2009-12-17 20:28   ` Joel Dice
2009-12-17 22:02 Bill McEnaney
2009-12-18  5:11 ` Joel Dice

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1261075878.2170.50.camel@bob-desktop \
    --to=plantz@cds1.net \
    --cc=callkalpa@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=joel.dice@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).