I didn't say that it wasn't contextual. But I would still argue that in most cases, most natural and sane yes/no questions have a sensible no as a default.
Questions about if something should change or stay the same (status quo) are often phrased so that the negative answer represents the status quo.
Do you want to move to country X?
Should I paint your bedroom purple?
Is it OK if I play loud music all night tonight?
Questions about if someone has done something in the past are often phrased so that the negative answer means that the person hasn't done that something.
Did you sell my car?
Have you ever killed anyone?
There are of course always exceptions. Like neutral factual questions, or questions where it's not unlikely that the person doesn't know for sure. Like "Is she busy?" or "Does store X sell product Y?".
Continue to install this software, the process of which you yourself initiated in the first place? [Y/n]
That kind of thing is what I was thinking about. But there are cases of both. You didn't say it was not contextual, no, but I didn't feel like it was clear enough that you didn't mean that. Sorry if I misunderstood. All the best.
I didn't claim that it always should be the case. One can always find exceptions. But I would argue that for every exception you can find, one would easily be able to give multiple examples where my assumption would be valid and sane.
Like:
"Do you want to go for a walk?"
"Do you want to have sex?"
"Are you interested in buying this used van?"
"Have you ever tasted goat meat?"
"Will you marry me?"
(All these questions were asked on the first day of meeting my now wife...)
no you don't, that is just bad programming. In this specific case, you need to remove the risk of NullPointerException and leave everything as it is. Adding if statement is pointless here.
edit: if the logic of the code is to compare the values of two strings and one is null, it is obvious the boolean will return false, so adding an if is utterly pointless. The only change that can be made is removing the tertiary operation, since equals will return the needed value.
It's because strings are objects, and you can have two string objects representing the same sequence of letters. Comparing objects with == in java only tells you whether both objects are literally the same object.
Depending on the “why” this isn’t necessarily bad. I’ve had to do shit like this for clients with really old systems or bad data (converting a massive access application where they were storing ‘book’ data as yes/no) so we had to take that data and display the yes/no choice the users expected but store them as booleans. Sometimes you just have to work with what a client gives you. Room for improvement here, but it’s not horrible.
149
u/_grey_wall Apr 14 '22
Should really be
"yes".equals(input)
That way if input happens to be null, you won't get a null pointer exception.
17
u/maubg Apr 14 '22
Every is fine to me, push to main branch
12
u/[deleted] Apr 15 '22 edited Apr 15 '22
No space before
?and:, wtf?22
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Apr 14 '22
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
26
u/Costyyy Apr 14 '22
I mean, what's wrong with it? I guess you could lowercase the input just in case.
1
u/[deleted] Apr 15 '22
I dont know java, but love the use of ‘.equals’ instead of ==. ‘answer = input == “yes” ?’ Would be confusing to read.
1
u/Lucky-Biscotti701 Apr 15 '22
Lol
1
u/ososalsosal Apr 15 '22
When the caffeine stops working.
Definitely been there.
1
u/rob113289 Apr 15 '22
Can't you new up a Boolean with "yes" as a param?
1
u/[deleted] Apr 19 '22
There are so many things wrong with this code.
1
u/The1Freeman2112 Jul 02 '22
Depending on the “why” this isn’t necessarily bad. I’ve had to do shit like this for clients with really old systems or bad data (converting a massive access application where they were storing ‘book’ data as yes/no) so we had to take that data and display the yes/no choice the users expected but store them as booleans. Sometimes you just have to work with what a client gives you. Room for improvement here, but it’s not horrible.
1
u/[deleted] Jan 12 '23
I don’t get it
-1
u/catithebathtub Apr 14 '22
cs student in his 2nd year?