WTF Bites
-
@Gąska: how else would you handle a return value of FILE_NOT_FOUND?
-
@Gąska Could be worse. Could be this:
if (!(foo(bar) != false)) {
-
@Gąska Could be worse. Could be this:
if (!(foo(bar) != false)) {
if ((!(foo(bar) == true)) == true) {
-
@topspin The best/worst part about that is that it actually happens.
-
@Gąska Could be worse. Could be this:
if (!(foo(bar) != false)) {
if ((!(foo(bar) == true)) == true) {
There are some cases where
if foo() {
is an error butif foo() == true {
is not. Nullable booleans and storing booleans in the equivalent ofjava.lang.Object
spring to mind.
-
@ben_lubar I assure you it's a plain old primitive boolean.
-
@ben_lubar I assure you it's a plain old primitive boolean.
Java?
Edit: INB4 "no thanks, I've already had my coffee".
-
@ben_lubar said in WTF Bites:
@Gąska Could be worse. Could be this:
if (!(foo(bar) != false)) {
if ((!(foo(bar) == true)) == true) {
There are some cases where
if foo() {
is an error butif foo() == true {
is not. Nullable booleans and storing booleans in the equivalent ofjava.lang.Object
spring to mind.Ah, yes, the good old billion dollar mistake.
-
@Zecc actually the original language is outside C family. I've rewritten it in C-like syntax for anonymization purposes. TBF, conditions in this language must have equality comparison, so it's not that wrong - but negating the result of comparison against boolean literal is still WTF.
Whatever. It's funnier this way.
-
@cvi Look at where the map thinks the sidewalks are. That's the best route with the data it has. It's just missing a sidewalk.
-
I bought a SATA cable and it has a hair in it.
Yes, the plastic connector has a single, thick human hair melted right into the plastic, going from side to side .
-
@anonymous234 So man-up, cut it off, and plug the cable in.
-
@Polygeekery said in WTF Bites:
Someone remind me this week and I will tell the story. It's a pretty good one.
This is your friendly reminder service. It's Monday morning.
Thank you, the bill is in the mail.
-
@TimeBandit said in WTF Bites:
@Polygeekery said in WTF Bites:
Someone remind me this week and I will tell the story. It's a pretty good one.
This is your friendly reminder service. It's Monday morning.
Thank you, the bill is in the mail.
Try Wednesday. Until then you can expect me to write up my call to the local power utility and my discussion with the blithering idiot with a malfunctioning headset on her phone.
-
@anonymous234 said in WTF Bites:
I bought a SATA cable and it has a hair in it.
Yes, the plastic connector has a single, thick human hair melted right into the plastic, going from side to side .
You sure it's human?
-
@Zerosquare said in WTF Bites:
A friend just pointed out that they actually do this on purpose:
2.7.1 Integer Promotions
ISO mandates that all arithmetic be performed at int precision or greater. By default, MPLAB C18 will perform arithmetic at the size of the largest operand, even if both operands are smaller than an int.
The ISO mandated behavior can be instated via the -Oi command-line option.
(...)
Note that this divergence also applies to constant literals. The chosen type for constant literals is the first one from the appropriate group that can represent the value of the constant without overflow.
For example:
#define A 0x10 /* A will be considered a char unless -Oi specified */
#define B 0x10 /* B will be considered a char unless -Oi specified */
#define C (A) * (B)
unsigned i;
i = C; /* ISO requires that i == 0x100, but in C18 i == 0 */There should at least be a warning when a math error occurs in compile-time calculations with constants (overflow, underflow, division by zero).
-
@Gąska Could be worse. Could be this:
if (!(foo(bar) != false)) {
if (!(foo(bar) == true) && !(foo(bar) != false)) {
Bonus points if
foo
has side effects that could result in it not returning the same thing on the second call.
-
TBF, conditions in this language must have equality comparison, so it's not that wrong
So the designer of that language has the same weird brain bug as all the people who write
if (some_bool_val == true)
?
-
@topspin nope, it's because it's not an imperative language.
-
@topspin It's called consistency and readability
if(person.name == "Smith")
if(person.age == 43)
if(person.married == true)
-
@anonymous234 Ew, unaligned.
-
@anonymous234 It's been identified as a brain bug, as well - the "curse of small minds", I think it was described as most poetically. Of course they all claim theirs isn't foolish.
-
@anonymous234 said in WTF Bites:
@topspin It's called consistency and readability
if (person.name == "Smith")
if (person.age == 43)
if (person.married == true)
FTFY.
-
conditions in this language must have equality comparison
The person who created that needs to be introduced to a cluebat. With rusty nails in it.
-
@anotherusername said in WTF Bites:
@Gąska Could be worse. Could be this:
if (!(foo(bar) != false)) {
if (!(foo(bar) == true) && !(foo(bar) != false)) {
Bonus points if
foo
has side effects that could result in it not returning the same thing on the second call.I was just thinking about going more Enterprisey…
BooleanFactoryBuilder.getInstance().getFactory().getLogicalTrueValue()
…
-
@dkf .
AbstractFactoryBuilder.getInstanceForClass(Boolean.class).build().getReferenceValue(Values.TRUE)
is more general-purpose.
-
@anonymous234 said in WTF Bites:
@topspin It's called consistency and readability
if(person.name == "Smith")
if(person.age == 43)
if(person.married == true)
Ewwe, get lost.
It'sif (person.isMarried)
Otherwise, go all in and do
if ((person.name == "Smith") == true)
if ((person.age == 43) == true)
if ((person.married == true) == true)
-
all in and do
if ( (person.name == "Smith") == true) if ( (person.age == 43) == true) if ( (person.married == true) == true)
if you're literally trying to win a beauty contest@PleegWat">.
-
@Gribnit That's over the top. And I'm not generally a fan of
== true
. I shudder whenever I see things like this in our code:$bIncludeFrobbed = true; $bSomeConditionIsTrue = $objSomeManager->IsSomeConditionTrue( $bIncludeFrobbed ); if ( true == $bSomeConditionIsTrue ) { // Actual code // }
And no,
$bIncludeFrobbed
is never used again in this file. Variable and function names may have been shortened during anonymization.
-
all the people who write if (some_bool_val == true)?
Clearly they should write
if (true == some_bool_val)
to avoid accidentally writing assignments.
-
if ((person.name == "Smith") == true) { if ((person.age == 43) == true) { if ((person.married == true) == true)
-
if ( person.name == "Smith" )
if ( person.age == 43 )
if ( person.married == true )
FTFY
Edit: ’d and iPhone fucks with spaces, wo’d a’ thunk.
-
@loopback0 Bonus points for inconsistent brace placement!
-
@topspin Why are we special casing code for 43 year old Mr or Mrs Smith anyway?
-
all in and do
if ( (person.name == "Smith") == true) if ( (person.age == 43) == true) if ( (person.married == true) == true)
if you're literally trying to win a beauty contest@PleegWat">.
I worked with people that wrote code like that. Some functions even had superfluous parameters to make header files more symmetric.
-
@PleegWat In case they start to shoot up the place.
-
The code itself is obviously to enforce a contract in a P.J. Wodehouse story. Nothing odd about that.
-
@PleegWat A fun thing about this kind of crap is that it inflates the line count with the kind of low-complexity expressions that code quality analyzers reward.
-
all the people who write if (some_bool_val == true)?
Clearly they should write
if (true == some_bool_val)
to avoid accidentally writing assignments.There is a (fairly) clean way for a language to stop such nonsense: disallow assignment in test-expressions.
-
@dkf But what about idiomatic loops for block io won't someone think of the idiomatic loops for block io
-
all the people who write if (some_bool_val == true)?
Clearly they should write
if (true == some_bool_val)
to avoid accidentally writing assignments.There is a (fairly) clean way for a language to stop such nonsense: disallow assignment in test-expressions.
Also, what's the point of parentheses around the condition? Just require braces.
-
val x: Boolean? = getSomeNullableBool(); // invalid: // if (x) { if (x == true) {
-
@pie_flavor TDEMSYR. What were you going for here?
-
Avoid accidentally writing assignments to,
if (true == some_bool_val)
clearly they should write.FTFY
-
@Gribnit I gather that you have neither used Kotlin nor read any of the above posts.
-
There is a (fairly) clean way for a language to stop such nonsense: disallow assignment in test-expressions.
Or ... don't bother, because it's such an uncommon error in practice? (Or warn about it and require an extra set of parentheses to silence the warning. Anything other than specially restricting certain expressions in the language unnecessarily.)
-
all the people who write if (some_bool_val == true)?
Clearly they should write
if (true == some_bool_val)
to avoid accidentally writing assignments.There is a (fairly) clean way for a language to stop such nonsense: disallow assignment in test-expressions.
But I am a fan of
if ( (foo = getfoo(bar)) )
With the extra set of braces checked by gcc.
-
Yesterday's job candidate brought dog to a technical interview. HR lady says, "they worked together on the task".
They gave up after an hour.
-
@dkf But what about idiomatic loops for block io won't someone think of the idiomatic loops for block io
Make a different idiom, e.g., define the IO objects to be able to yield a sequence of read items (lines, blocks, etc.)
-
@cartman82 said in WTF Bites:
Yesterday's job candidate brought dog to a technical interview. HR lady says, "they worked together on the task".
They gave up after an hour.Hire the dog. Just the dog.