users
[Top] [All Lists]

Re: [cinjug-users] Constants imply DP (was: Question on last Monday's me

To: Mark Windholtz <windholtz@xxxxxxxxx>
Subject: Re: [cinjug-users] Constants imply DP (was: Question on last Monday's meeting)
From: Eric Bardes <eric@xxxxxxxxxx>
Date: Fri, 25 Feb 2005 12:41:14 -0500
Cc: users@xxxxxxxxxx, "Mitchell, John" <jlmitchell@xxxxxxxx>
Delivered-to: mailing list users@cinjug.org
In-reply-to: <3a4860b4050225083956af8634@mail.gmail.com>
Mailing-list: contact users-help@cinjug.org; run by ezmlm
References: <CEB8092DFD93924AB120334CEEC4EC3D013247C5@CVGEXCEMAIL001.ga.afginc.com> <3a4860b4050225083956af8634@mail.gmail.com>
User-agent: Mutt/1.5.6+20040907i
On Fri, Feb 25, 2005 at 11:39:41AM -0500, Mark Windholtz wrote:
> Mitchell, John  wrote:
> > 
> > If a constant is needed by more than one
> > class, what is the alternative?  

Another problem with constants is that they're often associated with
Sentinal Values.  A sentinal value is a special number returned from some
kind of call (insert your favorite term: method, function, subroutine)
that signifies a condition that has to handled differently than if a
non-sentinal value is returned.

Like other topics in "Classic Programming", sentinal values are among
the tried and true techniques that appear in university textbooks.
But the hazard of sentinal values is that they're really mixing meta-data
and data.  And everytime an API mixes the two, the programmer using
it is burdened with needing to decern the metadata from the data after
calling it.

Aside from null, most of the Java API is pretty good about avoiding this,
so I'm having a hard time thinking of an example.  I'll borrow one from
'C'.  The data is a file handle, the meta-data is whether the function
suceeded.  Both data and meta-data are returned in a single value.

  int fd = open("somefile.txt", O_RDWR);
  if (fd < 0)
    fprintf(stderr, "failure\n");
  else
    read(fd, buffer, length);

Some Java OO purists have argued that method which return null are just
as bad as using sentinal values.

Eric

<Prev in Thread] Current Thread [Next in Thread>