Re:HTML5 Deck of Cards
by takeda on Thursday September 03, 2015 @11:34AM
(#10165497)
If you're referring to |0 then I would disagree. It shows how horrible JavaScript is. This is very confusing if you're not familiar with this trick or strange behavior of the language.
Are much easier to understand for someone not familiar with the code.
[ Parent
| on HN ]
Re:HTML5 Deck of Cards
by TazeTSchnitzel on Thursday September 03, 2015 @11:37AM
(#10165519)
The behaviour of JavaScript's bitwise operators isn't that unreasonable, but the excessive use of this trick for tiny performance gains at the expense of readability is a shame.
Re:HTML5 Deck of Cards
by riebschlager on Thursday September 03, 2015 @11:47AM
(#10165583)
I take your point, but that's some crazy non-JS typecasting in your first two examples :)
Languages are what they are, and if you're going to use one you might as well use it idiomatically. Maybe it's just me, but I see "|0" all the time in JS, not as some kind of crazy performance hack, but used idiomatically to mean "truncate".
And on the flip side with JS's lack of number types, any code that looks like it's doing type casts (rather than math) looks out of place. If one must mess around with JS number types then all you can really do is give hints to the optimizing compiler, in which case "|0" is the standard way to hint that you want a small int.
Obviously what looks clean is a matter of opinion, but FWIW.
Re:HTML5 Deck of Cards
by adamkochanowicz on Thursday September 03, 2015 @12:53PM
(#10166006)
suit = Integer(i / 13)
suit = Math.floor(i / 13)