× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: RE: field initializtion
  • From: "Larry Loen" <lwloen@xxxxxxxxxx>
  • Date: Mon, 26 Mar 2001 17:07:19 -0600
  • Importance: Normal


Brad Stone wrote:

>Joe,

>From other sources and NGs I've heard the opposite.  That returning null
>from a user class is NOT acceptable and generally a pain in the arse.  i'm
>looking to what others (not just Joe, people!) have seen is the norm.
>Because Java is used on many platforms, there seem to be many different
>opinions as to what is reasonable and what is not.

Fair enough.  Assuming I'm following this right, the question on the table
is "what is null, really, and when does it make sense to have it?"

The difference here might well be the difference between "zero zebras" and
a null set that might have contained zebras, but was empty instead.  Many
people are confused about this (especially in nontrivial examples).  A lot
of very sophisticated classes return some sort of String as a primary
output, making this more acute than it might be.

If "zero zebras" is really the equivalent situation for some String I'm
supposed to return, I would return "".

If there was a genuine need and desire to represent "the empty set", I
would return null.

On the whole, my own experience is such that I frequently return null and
not empty strings.  Maybe that says more about the way I think about
problems than anything else.  Certainly, a string of zero length ("") could
be a valid result.  A null may even be a valid return, too, but it usually
does not mean the same thing semantically.

Consider this not particularly contrived example:

 /* Print out all non-empty lines of a file */
while( str = infile.readLine()) {
   if (str.equals(""))
   else System.out.println(str);
}

I've probably not written code quite this simple-minded, but I've come
close.

The distinction in concept is quite evident, useful, even necessary.  And,
I see nothing magical about java.io versus mycorp.mypkg.  If it's good
enough for Javasoft, it's good enough for my classes, too.




Larry W. Loen  -   Senior Java and AS/400 Performance Analyst
                          Dept HP4, Rochester MN


+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.