Not Equals

Please compose all posts in Emacs.

Moderators: phlip, Moderators General, Prelates

Which do you prefer?

!=
161
76%
~=
2
1%
/=
5
2%
=/=
20
9%
<>
8
4%
Platypus
15
7%
 
Total votes: 211

speising
Posts: 2047
Joined: Mon Sep 03, 2012 4:54 pm UTC
Location: wien

Re: Not Equals

Postby speising » Fri Oct 03, 2014 7:06 pm UTC

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#)

EvanED
Posts: 4324
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Not Equals

Postby EvanED » Fri Oct 03, 2014 7:22 pm UTC

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 ><?

mousewiz
Posts: 107
Joined: Wed Oct 26, 2011 6:50 pm UTC

Re: Not Equals

Postby mousewiz » Fri Oct 03, 2014 8:14 pm UTC

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)

User avatar
ahammel
My Little Cabbage
Posts: 2135
Joined: Mon Jan 30, 2012 12:46 am UTC
Location: Vancouver BC
Contact:

Re: Not Equals

Postby ahammel » Fri Oct 03, 2014 8:26 pm UTC

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.
He/Him/His/Alex
God damn these electric sex pants!

speising
Posts: 2047
Joined: Mon Sep 03, 2012 4:54 pm UTC
Location: wien

Re: Not Equals

Postby speising » Fri Oct 03, 2014 10:08 pm UTC

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.

User avatar
phlip
Restorer of Worlds
Posts: 7542
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Not Equals

Postby phlip » Sat Oct 04, 2014 4:28 am UTC

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.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

mousewiz
Posts: 107
Joined: Wed Oct 26, 2011 6:50 pm UTC

Re: Not Equals

Postby mousewiz » Sat Oct 04, 2014 7:13 pm UTC

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.

shieldforyoureyes
Posts: 339
Joined: Sat Apr 19, 2008 9:00 am UTC
Contact:

Re: Not Equals

Postby shieldforyoureyes » Mon Oct 06, 2014 8:46 pm UTC

Shift-8, duh.

Image

User avatar
Wildcard
Candlestick!
Posts: 251
Joined: Wed Jul 02, 2008 12:42 am UTC
Location: Outside of the box

Re: Not Equals

Postby Wildcard » Thu Jan 07, 2016 10:39 am UTC

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!
There's no such thing as a funny sig.

EvanED
Posts: 4324
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Not Equals

Postby EvanED » Thu Jan 07, 2016 2:41 pm UTC

Wildcard wrote:
shieldforyoureyes wrote:Shift-8, duh.

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

shieldforyoureyes
Posts: 339
Joined: Sat Apr 19, 2008 9:00 am UTC
Contact:

Re: Not Equals

Postby shieldforyoureyes » Sat Jan 09, 2016 9:15 am UTC

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.

User avatar
phlip
Restorer of Worlds
Posts: 7542
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Not Equals

Postby phlip » Sun Jan 10, 2016 9:31 am UTC

Yeah, "mumble mumble APL something something" was basically my guess...

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]


Return to “Religious Wars”

Who is online

Users browsing this forum: No registered users and 4 guests