4 ms·
> And if we look at Javascript, it is even worse than Ruby. How do you call Javascript if PHP is "garbage"? I think JS is better than PHP, at least when it com
by vatotemking 10y ago
> And if we look at Javascript, it is even worse than Ruby. How do you call Javascript if PHP is "garbage"?
I think JS is better than PHP, at least when it comes to: 1.) consistency of std lib and 2.) type casting. There are many surprises with PHP's type casting. See /r/lolphp sorted from top all-time: https://www.reddit.com/r/lolphp/top/?sort=top&t=all https://www.reddit.com/r/lolphp/top/?sort=top&t=all
- codedokode 10y agoTry console.log([] * {}) and be surprised. At least in PHP you cannot multiply array by object. Type casting in PHP gets fixed gradually: https://wiki.php.net/rfc/invalid_strings_in_arithmetic https://wiki.php.net/rfc/invalid_strings_in_arithmetic .
- oliverkyss 10y agoWhy would that be surprising? NaN as a result definitely means that you cannot multiply array by object in JS either. JavaScript uses IEEE 754 special values, not exceptions on arithmetic errors (eg 1/0 returns Infinity instead of throwing). If you bother to learn the language, it doesn't surprise you.
- happyslobro 10y agoThe problems start when you notice that your untyped key-value store has a bunch of NaNs where you were expecting a number. At this point, all you can do is pray that those numbers weren't very important, in the grand scheme of things.
- oliverkyss 10y agoSo when you do calculations with important numbers, you just push the results to the store without checking them and hope for the best? NaNs can happen in any language with floats, it's just that some languages also use exceptions in some situations.
- codedokode 10y agoYou can check the result of every operation manually but it saves you time when the language does it.
- kccqzy 10y agoOr compare [] + {} and {} + [] The first one is "[object Object]" and the second one is 0.