Page 3 of 3

Re: Not Equals

Posted: Fri Oct 03, 2014 7:06 pm UTC
by speising
so, what do you guys think of

Code: Select all

if (!Boolean.TRUE.equals(foo(bar)))
?
(relatively honest question, since i just recently came to java from c#)

Re: Not Equals

Posted: Fri Oct 03, 2014 7:22 pm UTC
by EvanED
Flumble wrote:Why is <> mentioned but not ><?
>< looks like a cross (×) which signifies not-ness. And it looks like an annoyed emoticon, so you can use it for types lacking order.

Because <> is actually used by a couple languages but I've not seen any that use ><?

Re: Not Equals

Posted: Fri Oct 03, 2014 8:14 pm UTC
by mousewiz
speising wrote:so, what do you guys think of

Code: Select all

if (!Boolean.TRUE.equals(foo(bar)))
?
(relatively honest question, since i just recently came to java from c#)


Please don't ever write that again.

This is preferred Java syntax:

Code: Select all

if(new Boolean(Boolean.TRUE.equals(foo(bar))).equals(Boolean.FALSE)){
    //stuff
}


(or, just do !foo(bar) / foo(bar) == false / foo(bar) != true... whichever seems more readable to you; they're all perfectly readable to me, though I think certain function names might be more suited to certain operators.... !goingToExplode(), invariant() != true, flagCurrently() == false, for some fabricated examples)

Re: Not Equals

Posted: Fri Oct 03, 2014 8:26 pm UTC
by ahammel
Grimbal wrote:Whether it is wrong depends on the language. You can argue that it is not logical though.

It is semantically wrong if it had anything to do with the < or > operators, which it looks like it does.

Re: Not Equals

Posted: Fri Oct 03, 2014 10:08 pm UTC
by speising
mousewiz wrote:
speising wrote:so, what do you guys think of

Code: Select all

if (!Boolean.TRUE.equals(foo(bar)))
?
(relatively honest question, since i just recently came to java from c#)


Please don't ever write that again.

This is preferred Java syntax:

Code: Select all

if(new Boolean(Boolean.TRUE.equals(foo(bar))).equals(Boolean.FALSE)){
    //stuff
}


(or, just do !foo(bar) / foo(bar) == false / foo(bar) != true... whichever seems more readable to you; they're all perfectly readable to me, though I think certain function names might be more suited to certain operators.... !goingToExplode(), invariant() != true, flagCurrently() == false, for some fabricated examples)


actually, foo returns an Object, so it would have to be !((boolean)foo()) i guess, which i would have written if it was my code. my guess is that the original implementer wanted to avoid casting? but the thought processes of the one who wrote foo are a mystery, too.

Re: Not Equals

Posted: Sat Oct 04, 2014 4:28 am UTC
by phlip
EvanED wrote:Because <> is actually used by a couple languages but I've not seen any that use ><?

There are some flavours of BASIC that will accept >< (and also =< and => in place of <= and >=)... But still, I agree that, by its construction, <> implies "is less or greater than", which is only really equivalent to "not equal" if the type is totally ordered (and thus the trichotomy holds). If the type isn't totally ordered (or ordered at all) then you can have a<b and a>b both be false (or type errors) but a<>b be true.

[edit] Apparently I'd already said this in this thread... Oops.

Re: Not Equals

Posted: Sat Oct 04, 2014 7:13 pm UTC
by mousewiz
speising wrote:
mousewiz wrote:
speising wrote:so, what do you guys think of

Code: Select all

if (!Boolean.TRUE.equals(foo(bar)))
?
(relatively honest question, since i just recently came to java from c#)


Please don't ever write that again.

This is preferred Java syntax:

Code: Select all

if(new Boolean(Boolean.TRUE.equals(foo(bar))).equals(Boolean.FALSE)){
    //stuff
}


(or, just do !foo(bar) / foo(bar) == false / foo(bar) != true... whichever seems more readable to you; they're all perfectly readable to me, though I think certain function names might be more suited to certain operators.... !goingToExplode(), invariant() != true, flagCurrently() == false, for some fabricated examples)


actually, foo returns an Object, so it would have to be !((boolean)foo()) i guess, which i would have written if it was my code. my guess is that the original implementer wanted to avoid casting? but the thought processes of the one who wrote foo are a mystery, too.

Oh... that's weird. In that case I'd probably go with !foo(bar).equals(true) (I think autoboxing figures that out, but it's been a couple years so I might be mistaken). Mostly because most people put their constants on the right hand side of the operator, so it seems a little less backwards. I wouldn't cast it without ensuring that it's a Boolean first, and doing that check just to use it in .equals seems like a waste since .equals should do the check for you anyways. If it *always* returns a Boolean, and is called often enough, I might just wrap it and make the wrapper return [bB]oolean.

Re: Not Equals

Posted: Mon Oct 06, 2014 8:46 pm UTC
by shieldforyoureyes
Shift-8, duh.

Image

Re: Not Equals

Posted: Thu Jan 07, 2016 10:39 am UTC
by Wildcard
shieldforyoureyes wrote:Shift-8, duh.

What the heck kind of keyboard is that?

I'm partial to != not because I think it's logical, but because it doesn't really have any other meanings assigned to it that can get mixed up with the intended meaning.

That's the real reason (I think) why the != for inequality, == for equality, := for assignment makes sense. None of these is likely to get confused with something else.

Or, y'know, we could use <> for inequality, <- to read the next line from a file, = for equality testing, < to assign, > for greater-than, -lt for less than, <= for less than or equal to, and -ge for greater than or equal to.

And while we're at it let's use ^ for pointers, * for exponentiation, and x for multiplication. Then we can use + for concatenation, - for logical inverse, # for addition, v for OR, and /\ for AND. Yay!

Re: Not Equals

Posted: Thu Jan 07, 2016 2:41 pm UTC
by EvanED
Wildcard wrote:
shieldforyoureyes wrote:Shift-8, duh.

What the heck kind of keyboard is that?
An awesome one.

Re: Not Equals

Posted: Sat Jan 09, 2016 9:15 am UTC
by shieldforyoureyes
Wildcard wrote:
shieldforyoureyes wrote:Shift-8, duh.

What the heck kind of keyboard is that?



Early 70s Tektronix vector graphics terminal. The weird characters are for APL.

Re: Not Equals

Posted: Sun Jan 10, 2016 9:31 am UTC
by phlip
Yeah, "mumble mumble APL something something" was basically my guess...