Earlier quoted context omitted.
As a Firefox-user (on Linux!) who don't feel like installing Google's closed-source spyware-browser, would you be shocked to hear me chip in and say: I don't care. I don't need my browser to drive full-screen 3D games & demos on my current-laptop hardware. That's not what I (or anyone else) is currently using their browser for. Maybe 5 years from now things will have changed. Maybe then truly everything will be in th…
Think of this like a stress-test for the JS engine though. It's probably still useful to work out edge cases and odd performance issues. It's much better in 35.0a2 and that's good for everyone.
JS1k demo: “Highway at Night”
81–90 of 100 posts
Re: JS1k demo: “Highway at Night”
#82It's really impressive and he posted the explanation: http://birdgames.nl/2014/04/js1k-post-mortem-minecraft/
Re: JS1k demo: “Highway at Night”
#83I saw the double tilde (~~) in the code and wondered what it was. Of course, single tilde is the bitwise not operator. Googling finds that double tilde is a faster Math.floor(). http://stackoverflow.com/questions/5971645/what-is-the-doubl...
Learning about bitwise operators (and everything they entail - so binary in general, endianness, etc) was without a doubt the most beneficial thing I've ever done for my programming abilities. It was a complete eye opener to how computers work on a far more fundamental level than any other aspect of programming had previously revealed to me. For anyone without a traditional CS educational background, if you don't kno…
Re: JS1k demo: “Highway at Night”
#84this was really beautiful. I almost blurted out it was art but then I was forced to remember we can't call computer generated things art by some hidden rule.
1.) people can take away a lot from the code and animation which makes it a great example of a new art form. The street scene in oarticular conjures up emotions.
2.) just because a group of the Internet does not understand or appreciate art in all its forms, doesn't mean anything at all except they are ignorant when it comes to identifying artwork.
Re: JS1k demo: “Highway at Night”
#85I am impressed how smooth many oft the demos run in Firefox for Android
On my Android phone it ran really smooth, but after like 2 minutes Firefox crashed?!
Re: JS1k demo: “Highway at Night”
#86Earlier quoted context omitted.
Learning about bitwise operators (and everything they entail - so binary in general, endianness, etc) was without a doubt the most beneficial thing I've ever done for my programming abilities. It was a complete eye opener to how computers work on a far more fundamental level than any other aspect of programming had previously revealed to me. For anyone without a traditional CS educational background, if you don't kno…
~x.indexOf(…) would be “starts with” rather than “contains”, for negative numbers such as -2 (from ~1) are truthy.
Nope, here's an example you can run it run in your console:
function contains(needle, haystack) {
return Boolean(~haystack.indexOf(needle));
}
var haystack = "The quick brown fox jumps over the lazy dog";
console.log(contains("The", haystack));
console.log(contains("dog", haystack));
console.log(contains("brown fox jumps", haystack));
Here are three potential cases: haystack.indexOf('dog') = 40 -> truthy
~40 = -41 -> truthy
haystack.indexOf('The') = 0 -> falsey (WRONG)
~0 = -1 -> truthy (FIXED)
haystack.indexOf('nope') = -1 -> truthy (WRONG)
~-1 = 0 -> falsey (FIXED)Re: JS1k demo: “Highway at Night”
#87Earlier quoted context omitted.
Learning about bitwise operators (and everything they entail - so binary in general, endianness, etc) was without a doubt the most beneficial thing I've ever done for my programming abilities. It was a complete eye opener to how computers work on a far more fundamental level than any other aspect of programming had previously revealed to me. For anyone without a traditional CS educational background, if you don't kno…
I would probably hate you for not writing plain “!=-1” instead.
Re: JS1k demo: “Highway at Night”
#88Earlier quoted context omitted.
You definitely should learn bitwise operators, but if other people have to work with your code I'm not generally in favor of applying them in clever ways where there's a slightly more verbose but much more readable solution (e.x. "~x.indexOf(y)" vs "x.indexOf(y) !== 0"... just type the extra 3 characters)
As a rule of thumb, when ever one thinks that "wow, this code I just wrote is really clever", it should be a sign to sit back, take another approach and rewrite that code. Clever code almost always means that in hindsight it's terrible and will introduce bugs. In my opinion "x.indexOf(y) !== 0" is a lot more clearer and will immediately tells other developers what is happening. No point in saving space code, that's w…
Re: JS1k demo: “Highway at Night”
#89I saw the double tilde (~~) in the code and wondered what it was. Of course, single tilde is the bitwise not operator. Googling finds that double tilde is a faster Math.floor(). http://stackoverflow.com/questions/5971645/what-is-the-doubl...
It's a bit more than that. It can also be used to convert strings (containing numeric values) to Numbers. More commonly seen than the prefix "~~" is "|0", because of it's low order precedence. > '15' '15' > ~~'15' 15 > '15'|0 15 > 15.99|0 15 > ~~15 * 1.3 19.5 > 15 * 1.3 | 0 19
Re: JS1k demo: “Highway at Night”
#90Earlier quoted context omitted.
Learning about bitwise operators (and everything they entail - so binary in general, endianness, etc) was without a doubt the most beneficial thing I've ever done for my programming abilities. It was a complete eye opener to how computers work on a far more fundamental level than any other aspect of programming had previously revealed to me. For anyone without a traditional CS educational background, if you don't kno…
~x.indexOf(…) would be “starts with” rather than “contains”, for negative numbers such as -2 (from ~1) are truthy.