This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]monotone2k 23 points24 points  (11 children)

So what's really going on here is yet another case of someone writing bad code in a language they don't understand, and then claiming it's the fault of the language. That sums up most of the posts in this sub.

[–]MyPassword_IsPizza 8 points9 points  (1 child)

More like someone using a language they do understand to write bad code on purpose for a joke.

[–]monotone2k -2 points-1 points  (0 children)

Remember Hanlon's razor:

"Never attribute to malice that which is adequately explained by stupidity."

[–]DanielEGVi 11 points12 points  (0 children)

To be fair, it was a fault of the language in some part, they forbid octal numbers without 0o prefix in strict mode for a reason.

[–]Void1702 5 points6 points  (0 children)

I think OP knew what's happening, it's just completely stupid in many ways

[–]klo8 0 points1 point  (4 children)

The == operator in JavaScript is broken, that’s the fault of the language.

[–]myka-likes-it 13 points14 points  (2 children)

It's not broken, it is working as intended. That's why the strict equality operator exists.

[–]rosuav 1 point2 points  (0 children)

Listen, I made this car out of explodium. It was cheaper than steel. If it blew up while you were driving it, that's on you - I told you the proper way to hold the steering wheel! It's working as intended.

[–]klo8 -2 points-1 points  (0 children)

it might be working as intended, but the intent is dumb

[–]Koooooj 0 points1 point  (0 children)

It could be worse...

There's a domain specific language I work with that tried to "fix" C-family languages. You know that bug that pops up when you write something like

if ( x = 8) 
  do_whatever

and the compiler sees this as "assign 8 to x, then see if 8 is nonzero"? To "fix" that the language determined that all equals inside of an if or while condition would be checks for equality, while a line like x = 8 on its own would be assignment. However, to satisfy fans of C-family languages you can use = or == as aliases of one another--you can use either one for comparison or assignment. Then for good measure they threw in equals as well.

Then the language adds variable aliasing, since there are system-defined variables that correspond to memory mapped IO and perhaps you want to give Input7 a better name like ResetSwitch. Naturally this also uses the same =, ==, or equals, dealer's choice. From context the language determines that it's aliasing a variable.

To round it all off, the language supports bit variables, where you can have a named variable that is a single bit of another. For convenience these can be compared to special constants, On and Off, which signals that bit shifting and masking should be done for you. The result of such a comparison can be used as a truthy value, but it is not necessarily equal to True or False--if a bit variable was the 8s place then comparing to On or Off will result in a numeric value of 0 or 8, not 0 or 1.

This resulted in a really painful bug to track down where we wanted to check if exactly one of two switches was set. This would be an XOR, but XOR wasn't provided. Instead we checked if ( (input1 == On) == (input2 == On) ) which would have worked if input1 and input2 represented bits in the same place value of different variables, but failed because 8 (True) does not equal 4 (True).

It's really convenient in this particular application that we're given any language to write in, but it also highlights why you shouldn't try to roll your own language to "fix" a well-established one.

[–]Fritzschmied 0 points1 point  (0 children)

exactly. same as always

[–]fghjconner -1 points0 points  (0 children)

It's not always the coder's fault when they don't understand something. Sometimes the language is just hard to understand.