Do not compare Strings
-
Dude, C's had a boolean type for over 15 years now!
-
I'm sure the maintenance programmers will relish the challenge that bitwise boolean logic introduces too.
If you've ever wondered why C has
&&
and||
operators, but no^^
operator, that's because 'logical XOR' is spelled!=
.For bool operands, ^ computes the logical exclusive-or of its operand
-
https://msdn.microsoft.com/en-us/library/zkacc7k1.aspx
For bool operands, ^ computes the logical exclusive-or of its operand
But what about the short-circuiting version,
^^
?
-
But what about the short-circuiting version,
^^
?Or, y'know, why not just use
!=
like every other programmer?
-
https://msdn.microsoft.com/en-us/library/zkacc7k1.aspx
I've been using C# for several years; never knew that was an operator… never had to
-
That one doesn't short circuit…
-
True, but the
^
version doesn't either...
-
Because XOR cannot be short-circuitted, of course. I'm not seeing the big problem, however. Bitwise comparisons are not that complicated.
And if you're unable to understand code because of that then you have bigger problems.
-
Given
bool A, B
.You're honestly saying that
if(!A ^ !B)
is as idiomatic and easy to understand asif(A != B)
?
-
Isn't
if(!A ^ !B)
the same asif(A ^ B)
? I'd still useif(A != B)
anyway.
-
Given
bool A, B
.You're honestly saying that
if(!A ^ !B)
is as idiomatic and easy to understand asif(A != B)
?That's like asking "You're sure that 'Jacke' is as easy to understand as 'Hose'?"
Either you know the operator or you don't. And if you don't then you learn something new and not especially complicated. That's called 'life', I think.
-
Isn't
if(!A ^ !B)
the same asif(A ^ B)
?Well, yes, but you need the
!
s there to coerce the whole operation into a boolean, otherwise it might do a bitwise XOR ...I'd still use
if(A != B)
anyway.Agreed, unless you know 100% for sure that you hate the maintainer of the code.
-
Agreed, unless you know 100% for sure that you hate the maintainer of the code.
Drama much? Seriously, you whine as much as my pupils when I introduce tell them that they certainly won't die from this 5 minutes of homework.
-
Drama much? Seriously, you whine as much as my pupils when I introduce tell them that they certainly won't die from this 5 minutes of homework.
Not really, as I'd simply replace it with the idiomatic as soon as I took ownership of the code.
-
Not really, as I'd simply replace it with the idiomatic as soon as I took ownership of the code.
Oh, right, the "my way is the only correct way" which is so productive. Do you also OCD on tabs and whitespace?
-
-
-
That was my line.
I think you've stated your opinion on the matter perfectly clearly, there's not really anything left for me to say at this point.The bikeshed should be green though.
-
!=
is correct in this case since it best expresses the intent of the comparison, that it's a validation error if the existence of the first name field isn't the same as the existence of the last name field.Other cases? 🍦 🍡
-
-
Oh, right, the "my way is the only correct way" which is so productive.
There are multiple correct ways, beyond doubt. There are also incorrect ways: Those that proliferate bugs and maintenance misunderstandings.
I much prefer correct code and strive to achieve it as much as I can (and fail often enough even so). One of my biggest ongoing headaches is due to programmers who will not strive for correct code; for whom "any old shortcut is good enough."
I do a lot of software maintenance, and I estimate that 80% of my maintenance is due to those programmers. I don't care what your correct method is, but if you want be sloppy, if you're too undisciplined to learn to do it a correct way, save me from your code.
Because if you don't, I will post it here.
-
Here's the thing: The ^-operator is explicitly meant for XOR. I'm not exactly sure why some people insist on screaming that this is the wrong way to do it just because they're unfamiliar with the concept.
I mean it's neither rocket science nor is it a triple-nested ternary.
-
I can't think of many scenarios where you'd use it though
-
I can't think of many scenarios where you'd use it though
It's useful in hash functions; those are really common, even if you're not usually explicitly aware of them…
-
-
Would be a nice disgruntled bomb, if it actually worked.
Alas I am pretty sure ^ is not allowed in a macro name.
-
Alas I am pretty sure ^ is not allowed in a macro name.
It's not :(
onyx : ~ $ cat xortroll.c #include <stdio.h> #define ^ != int main(void) { printf("Will it compile?\n"); return 0; } onyx : ~ $ gcc -o xortroll xortroll.c xortroll.c:3:9: error: macro names must be identifiers #define ^ != ^
-
Hashing and unsetting flags
-
Toggling flags. You use
&=~
for unsetting.
-
&^=
is an operator in Go.
-
.... what
-
...what!?
They did the
&^=
operator so they didn't have to waste time writinga&=^b
. (There's a non-assignment version of the operator,&^
so they don't have to writea&^b
. Nice ambiguity in this one by the way, since they also have a unary^
operator: isa&^b
the same asa &^ b
or is ita & (^b)
. Yes, the result would be the same either way.)Strikes me as an unhealthy focus on operators for the sake of operators.
-
Ooooohh,
^
is unary bitwise NOT and binary bitwise XOR, and &^ is the "bit clear" operator.Guess I haven't read the full spec...
-
&^= is an operator in Go.
Surprisingly, according to
perlop(1)
, it’s not a valid operator in Perl.
-
Surprisingly, according to
perlop(1)
, it’s not a valid operator in Perl.I'm amazed that there's anything that's not a valid operator in Perl. Have you checked with Perl6 too…?
-
Does Perl have emoji support? I'd like having 🖔 as an operator...
Shit, won't render, at least with my fonts. Image:
-
Reverse victory hand
I have a buddy who immigrated from Ireland. He told me that was considered rather offensive across the pond, much like flipping the bird at someone here in the US. Was he just pulling my leg, or is that really a thing over there?
-
I have a buddy who immigrated from Ireland. He told me that was considered rather offensive across the pond, much like flipping the bird at someone here in the US. Was he just pulling my leg, or is that really a thing over there?
Flicking the V? Yeah, it's an offensive gesture; it literally means 'fuck off'
-
Flicking the V? Yeah, it's an offensive gesture; it literally means 'fuck off'
Ok, so about the same as giving someone the bird, then.
Use with care, @Onyx. ;)
-
He told me that was considered rather offensive across the pond, much like flipping the bird at someone here in the US.
Why do you think I suggested it?
Still don't know what you'd use it for though... Maybe setting a value of a variable to
null
(equivalent)?
Filed under: Fuck off value, nobody wanted you anyway
-
How about U+1F574?
-
Maybe setting a value of a variable to
null
(equivalent)?
Like🖔 oThingy;
? Which would be the equivalent ofoThingy = null;
.Yes, I know the character doesn't render. But my dress is awesome, so I don't care
-
Flicking the V? Yeah, it's an offensive gesture; it literally means 'fuck off'
hmm... then the meaning has either changed or i was misinformed.
I always knew it as "showing your bowfingers" basically telling the other person that they should watch out because you were coming after them.
As i heard it it derived from mideival times where it was common to cut the first and second fingers off the hands of captured enemy archers (thereby making it so they couldn't use a bow anymore)
-
As i heard it it derived from mideival times where it was common to cut the first and second fingers off the hands of captured enemy archers (thereby making it so they couldn't use a bow anymore)
Nope, urban legend; the gesture is a lot newer ;)
-
hu-uh.
TIL, i was wrong about the origin of the V-sign
neat.
-
Don't know if you can get it in the United States of Whatever, but I'm very fond of this show: has all sorts of weird and wonderful stuff that is, funnily enough, quite interesting ;)
-
as i just got finished telling @abarker the only TV i've watched in the last ten years has been the food network.
so i'm rather rusty on the whole pop culture thing.
-
Looks like you're about to get QI, if not already:
http://screenrant.com/stephen-fry-quiz-show-qi-bbc-america/
And, for once, it won't be some Americanised version; you're getting the real deal!The only things I really watch on TV nowadays are QI, Top Gear, Doctor Who, F1, and the BTCC. And Charlie Brooker's Weekly Wipe
-
good to know.... now do i get BBC america over the air? cause i don't have cab le anymore
/me goes looking at local listings
-
If you can find a suitable UK proxy, you may be able to get the real BBC. Which means you'd also get iPlayer, so you could watch whenever you like