• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Returing null

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have a method which returns a Vector(which is intialized in that method). The method accepts parameters as null(intentially passed) and method makes connection with database and add into that vector using the argument.
Should the vector be null???

Thank you
 
Bartender
Posts: 1205
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Arun Thakur:
Hi all,

I have a method which returns a Vector(which is intialized in that method). The method accepts parameters as null(intentially passed) and method makes connection with database and add into that vector using the argument.
Should the vector be null???

Thank you



Are you asking whether the method should ever return a null (as opposed to non-null but empty) Vector?

That is a reasonable possibility, but the answer depends on what makes the most sense in your program. For instance, I could imagine a program that returns a Vector of all the invoices that a customer (given by the argument) has outstanding. If the customer has some such invoices, then the Vector will have elements. If the customer is found in the DB but has no outstanding invoices, then the returned Vector would be non-nul, but empty. If the customer was not found in the DB, the returned Vector would be null. And lastly, if the database access actually caused some type of Exception, then the method would throw an Exception.

There are those that would say if the customer isn't found, then the method should throw an Exception. That is a possibility, but I like to reserve Exceptions for situations that really are exceptional. (...hence the name.) Having a clerk enter a person's name and that name NOT being in the customer table doesn't feel like an exceptional situation to me. Trying to connect to my Oracle server and not being able to DOES.

Did that answer your question?
[ March 15, 2006: Message edited by: Ryan McGuire ]
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should never return null (nor accept it as a method parameter). Prefer to signal than return a "dynamically-typed nothing". Java implements signals using exceptions. Unfortunately, a signal/exception results in an implicit unrolling of the call stack until the handler - this is a language limitation.

Ignore the baloney about "exceptions are for exceptional conditions", "runtime exceptions are for this and that", etc. The biggest pain of writing software properly is when you have a forced dependency on a prolific violation.
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ignore the baloney...


It might never have occured to you that you can express your opinion without resorting to calling the opinions of others baloney or nonsence or other such juvenile dismissals.
[ March 15, 2006: Message edited by: Garrett Rowe ]
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Garrett Rowe:

It might never have occured to you that you can express your opinion without resorting to calling the opinions of others baloney or nonsence or other such juvenile dismissals.

[ March 15, 2006: Message edited by: Garrett Rowe ]



It occurs to me all the time.
Reality cannot be denied however. That something is accepted by the establishment does not in any way legitimise it.

In fact, one might argue against your assertion that it might never have occurred to me... this is your opinion (under your definition). Another one of your implications is that we are referring to "juvenile dismissals" - again, your opinion under your definition of the term. You've merely assumed it to be reality - so be it - I reserve the right to as well.

What is the difference between my expression and yours? One is accepted by the establishment (I'm sure many would agree with your statement), and one is accepted only by the small number of people who research the relevant topics (i.e. not many in this audience). Does this make my statement opinion and yours not opinion? This is the basis of the debate that rages - I certainly don't accept it. If anything, I have found (through experience only) that you can shortcut the conclusion of any given hypothesis simply by learning all about the established point of view, assuming it is false (called the method of contradiction by logicians), then attempting to prove it true. By doing so, you often prove the contrary (this is a well documented experience throughout history) - sometimes inadvertantly. It's a wonderful feeling, except of course, for the battle that you must now engage in with a majority should you ever wish to communicate (I like interacting, teaching, learning, etc.).

If for some reason you have religious faith or some unforeseen phenomena that somehow legitimises your statement while mine does not, then we merely disagree on what we have faith in - and so I simply suggest we go to the pub and have a beer. Arguing based on faith is ego-centric pointlessness. If otherwise, I suggest that one of us has something to learn - how we go about determining who and what that is, is what matters - at least to me.
 
Arun Thakur
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am doing JTesting actually. And the JTEst actually me assertNotNull(t0, ret), which I my opinion should be null. So should I leave it as it is or there is any other way to check that.??
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your requirements say you should return a Vector that contains data extracted from the database, then when there is no data extracted, you should return a Vector that contains no data. Zero is just a number too, there's no reason to do anything special for it.

But if you are proposing to return null instead of an empty Vector just because you wrote a test that checks for null, then I think you are carrying test-driven programming too far.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I work with a vendor framework (always have someone else to blame) that returns null for no rows, and it adds tons of null testing and exceptions when you forget to do check. I'd certainly rather deal with an empty Vector. Or some more modern collection.

When returning single objects instead of a collection it's a little harder to express "no object" than "no rows". Google up on the Null Object Pattern for a neat way to encapsulate what should happen when there is no object.

 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Tony Morris:

It occurs to me all the time.
Reality cannot be denied however. That something is accepted by the establishment does not in any way legitimise it.



But one can question the conventional wisdom without calling an opinion just expressed by another Rancher "baloney." That's the difference between a reasoned debate and a flame war.

Martin Luther didn't nail up a sign that said "You're all full of baloney!"
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martin Luther didn't nail up a sign that said "You're all full of baloney!"



Hey, I paid $10,000 for that sign, and the auction house promised me that it was authentic.

Tony, I don't disagree with your statements with regards to using exceptions for improper parameter passing, and returning null. I completely agree with you there. However, you just seem to sometimes take a more agressive attack approach to when you post. Let's just be nice about it. Please.

Mark
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ernest Friedman-Hill:


But one can question the conventional wisdom without calling an opinion just expressed by another Rancher "baloney." That's the difference between a reasoned debate and a flame war.

Martin Luther didn't nail up a sign that said "You're all full of baloney!"



I wasn't referring to one particular person/post, when talking of "baloney". I was merely referring to "the establishment". If one subscribes to the establishment in this context, then I hold the opinion that they also subscribe to baloney. I don't like peppering my words to suit the agenda (i.e. ego defence) of others when my primary objective is deriving a closer truth (should one exist). I encourage anyone to place the established point of view under a heavy analysis using some universally recognised method of logic - I'd be most interested in any apparantly sound conclusions that contradicted my understanding/reasoning.

Indeed, if I was inadvertantly subscribing to "baloney", anyone who points it out to me would be most welcome to a free beer on me.

Ultimately, I put this issue down to a culture difference. By referring to "baloney" for some implies an ego attack while for others (i.e. myself), a path of investigation (the awful paradox is that ego and truth often conflict). Is my culture less legitimate that anyone else's?
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just realised that the post before my original one portrays what I subsequently refer to as "baloney" - this was entirely coincidental.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Tony Morris:
I just realised that the post before my original one portrays what I subsequently refer to as "baloney" - this was entirely coincidental.



OK. Thanks.
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Tony Morris:

Is my culture less legitimate that anyone else's?


If "your culture" ever amounts to ridicule of other posters, or taking an unfriendly posture, then yes. It is not accepted here.

JavaRanch is not secretly holding out for greater truths -- we love informing, educating, and helping the people who come here. But we also want them to feel welcome here. If being a friendly place for Java greenhorns to meet is at odds with your culture, then yes, your culture could find better places to visit.

I don't think it has anything to do with culture, though. I think you don't care to understand that people who feel at ease usually learn more.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Michael Ernest:

If "your culture" ever amounts to ridicule of other posters, or taking an unfriendly posture, then yes. It is not accepted here.

JavaRanch is not secretly holding out for greater truths -- we love informing, educating, and helping the people who come here. But we also want them to feel welcome here. If being a friendly place for Java greenhorns to meet is at odds with your culture, then yes, your culture could find better places to visit.

I don't think it has anything to do with culture, though. I think you don't care to understand that people who feel at ease usually learn more.



No, I never aim to ridicule anyone. How people feel cannot be portrayed over an internet medium unless you make assumptions about context - often leading to errors (hence, I remain neutral and assume nothing).

I think you are making the mistake of assuming that I accept and concede to a majority culture - namely, western culture. Sure, I live in Australia and my tv is full of it - I recognise it immediately, but I reject it for me, personally. I simply don't like it.

I sometimes concede to it when I am communicating with others, for example, my 13 year old sister who is in no position to externalise the hitherto "culture" and learn that other people may think differently. I have assumed that the audience on this forum can transcend that level of ignorance. Often times I am mistaken, however, I am an optimist and I continue to assume the best of anyone.

I encourage you to truly identify where I have "ridiculed anyone" without applying any further context. I think you'll find that upon reflection (this requires absence of internalisation), that you must apply cultural context in order to identify the notion of "ridicule". I simply state, "I do not subscribe to this culture". If your answer is, "this forum does" as do all its members, then so be it - I will be forced into making a decision, as I often do. I simply assume that the contrary is true given that it is an globally-accessible medium.

I cannot rule out the possibility that you can come up with some absolute definition of "ridicule" that exists as a static entity external to our very existence and therefore culture, and I'd be most interested in such a notion - only I warn you that you are contradicting the work of many others before you, and it might help to learn of their work beforehand.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If this discussion is going to be constructive (i.e. absent of personal attacks, etc. as are so common on forums), I wish to continue it in the appropriate place.

Funny how it started as "Returning null"
 
I am a man of mystery. Mostly because of this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic