The new guy
-
My first look at the new guys code turned this up:
switch(true) { case !decision.released:
And then while copying that to paste here, I noticed this pattern in that same
ifcase block:&& !!decision.viewed
I'm still trying to figure out if it's an extra ! or completely superfluous. Today is going to be a long day.
-
I've seen
!!
in some cases, usually as a poor man's type coercion to boolean. Common in JavaScript.
-
What language is it?
-
It is actually JavaScript, which I have to admit I'm not super familiar with. Point new guy.
-
The
switch (true)
is still an abomination unto Chaos
-
Indeed, though the fact elseif is not actually a construct in JS doesn't help either (you have to use else if, and then rely on the fact that 'the next statement after such a clause is the one that will be executed' unless you want to brace ALL the things)
-
unless you want to brace ALL the things
Which is the proper and correct way to do any conditionals
-
Like this?
if (condition) { // do stuff } else { if (condition) { // do stuff } }
-
well, since you're checking the same condition both times there, you can presumably lose the entire else block
Pendant braces - b
-
if (condition) { // do stuff } else if (condition2) { // do stuff 2 }
-
well, since you're checking the same condition both times there, you can presumably lose the entire else block
You realise that was illustrative rather than definitive. Flagged for whoosh.
-
II was going for pendantry. Deliberately misunderstanding in order too be a dickweed
And although it's pretty nasty, I would be tempted to nest like that if I was forced to work in a language with no elseif semanntics
-
Common in JavaScript.
i use that one myself. but rarely. usually JS only cares if something is "truthy" or "falsy" but when i'm constructing things for serialization (particularly through a webservice) i add that just as a final make sure i can only send true or false to something that will freak out seeing an object where it expects a boolean.
-
-
No, my keyboard did. I correct most random extra characters I see, but some slip through
-
-
Well, I'm thoroughly gobsmacked by the level of purpose-free fucknuttery on this thread so far. Normally on these forums it takes two or three times that many posts to achieve that level. Disgratulations one and all.
-
well, since you're checking the same condition both times there, you can presumably lose the entire else block
Pendant braces - b
A thing of beauty...
-
hmm...... two flags from users and one from the mod that awarded the badge..... i think @boomzilla is liking his new found power. ;-)
-
i think @boomzilla is liking his new found power.
Eh...not that new. Anyways, it's the sort of thing I would have flagged. Now I don't have make someone else clean up afterwards, though.
-
Eh...not that new
no, i know.... but i missed my chance to make that "joke" when you were newly promoted.
-
-
No, my keyboard did. I correct most random extra characters I see, but some slip through
Are you and Blakey sharing the same keyboard?....
-
Are you and Blakey sharing the same keyboard?....
no, but i suspect he might be sharing a keyboard with a certain vixen... ;-)
-
Are you and Blakey sharing the same keyboard?....
There must be an obvious explanation for that…
-
-
I've seen !! in some cases, usually as a poor man's type coercion to boolean. Common in JavaScript.
Common in converting MS BOOL to bool (because warnings are at L4 and always treated as errors - well in my code. The company's, not so much...)
-
Also seen often in C code to convert pointers to bool;
(int)
is illegal and(NULL != ...)
is significantly longer.
-
Common in converting MS BOOL to bool
@PleegWat said:pointers to bool
That does not make it make sense in argument to f'ing logical operator that f'ing coerces it's arguments to f'ing booleans f'ing anyway though.
-
switch(false) { case decision.released:
There you go. Much better
-
Thank you. I'll get that change committed ASAP.
-
That does not make it make sense in argument to f'ing logical operator that f'ing coerces it's arguments to f'ing booleans f'ing anyway though.
Sure it does. Unless you think warning c4800 shouldn't exist...
[code]
void func(bool b) {...}
...
int y = ...
func(y);
[/code]
[code]1>SomeRandomFile.cpp(170): warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)[/code]
-
-
void func(bool b) {...}
I said
argument to f'ing logical operator
and a function ain't one (the original post had the construct like
something && !!that
).And for the record, yes, I do think that c4800 should not exist. In part because avoiding it using
!!
, and that's the only way, looks pretty silly and in part because it's actually pretty common for conversions, even implicit, in C++ to have runtime cost, so conversion tobool
is not special in any way.
-
I've seen
!!
in some cases, usually as a poor man's type coercion to boolean. Common in JavaScript.While reading about how poorly jQuery's [inArray][1] is named, I came across this gem:
Or if you want to get a bit fancy you can use the bitwise not (~) and logical not(!) operators to convert the result of the inArray function to a boolean value.
if(!!~jQuery.inArray("test", myarray)) { console.log("is in array"); } else { console.log("is NOT in array"); } ```</blockquote> http://stackoverflow.com/questions/18867599/jquery-inarray-how-to-use-it-right [1]: http://api.jquery.com/jquery.inarray/
-
If compiler writers aren't perverts, then why do they keep talking about peepholes and sexts?
-
jQuery.inArray(), how to use it right?
Use
.indexOf()
and avoid jQuery dependency? Also, don't be confused about the 0 meaning it's actually in the array?Or is there something magical that
jQuery.inArray()
does that I'm not aware of?
-
Use
.indexOf()
and avoid jQuery dependency? Also, don't be confused about the 0 meaning it's actually in the array?Or is there something magical that
jQuery.inArray()
does that I'm not aware of?Green pasture development would be awesome.
-
-
-
-
Some guy at a (C++) company I used to work at came to ask me what the
!!
operator was and why I was using it. Last I heard, he got promoted...
-
came to ask me what the !! operator was
he got promoted
And here I though there would be a twist...
-
And here I though there would be a twist...
It's possible that he's now no longer a dreadful engineer, it was a few years ago.
##Shyamalan!
-
It's possible that he's now no longer a dreadful engineer
It's possible that he's now a dreadful manager.
-
Who cares about
!!
? I want to know about the‼
operator!
-
‼
Oh hey, you broke left-clicking on links again because of that stupid tracker.
-
@Maciejasjmj - Days Since Last Discourse Bug: 0
-
Curiously, no repro on try.discourse:
http://try.discourse.org/t/http-www-dwarffortresswiki-org/338
-
Curiously, no repro on try.discourse:
Repro elsewhere however. Running on latest (at the time of posting):