Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
balte23207y@electronix agreed. when you evaluate this thoroughly and consider order of precedence this is totally how it should behave. perhaps one of the few times js does what it's supposed to do🙃
-
blem1410667y@balte you tell me it evaluates it like this?
(2<=0)<=9
false<=9
true
If it is like that... I'll stay with Python... -
blem1410667y@Krokoklemme in Python it does. It is also mathematically incorrect to evaluate it step by step.
-
@blem14 from an implementors point of view though, it's a LOOOOOT easier
And pretty much every programmer is aware of order-of-evaluation and knows what to expect -
balte23207y@blem14 I think this code should have never been written this way, and I can argue why.
in a sane environment, you have to prove that your code works for 100%, even if you're doing a solo project you should be able to make a proof. if you can do that, you'll be able to greatly reduce logically induced errors. by writing these two logical propositions as one, it becomes less clear what it actually means. (cast Boolean to integer evaluate as or, or evaluate as and, or just always return false?) even though it doesn't become impossible to prove your code working, it should be considered best practise to make your code as clear as an academic proof should be.
the language is just a tool, the programmer is the scientist.
then if we follow this principle, the rest of it becomes a discussion on how to implement bad behaviour. under that assumption, sounds a lot more trivial right? -
blem1410667y@balte I don't think it is less logical if you put these in one line, but it is up to language how it is interpreted. Here it does some not specified operations (as you said casting bool to int), it is also done in Python, but I have never met with errors caused just by that.
I agree it is cleaner to understand by devs if we put them in separate equations, but if we go with this concept further - isn't <= abbreviation for == or <?
JS makes things the way it is shown here, so you should be aware of it while using it.
Python IDEs (i.e. PyCharm) even warns you that 2<=x and x<=9 should be put together, since it will be evaluated the same.
But again, Python is made to be easiest language it could be, and this is more intuitive for people that never coded, having only mathematical approach. -
balte23207y@blem14 the unclarity arises from the ambiguity, which is not an issue in a >=. greater or equal is in fact quite clearly defined as such in any logical system.
I come from a computer science background, so maybe that's why I'm more focused on the logical correctness and saneness than the mathematical side.
ps: I actually wrote a rant on how important it is to know a language before you should judge it.
Related Rants
veri gud
undefined
gud
js