Live data from Hacker News

JS1k demo: “Highway at Night”

js1k.com

81–90 of 100 posts

Re: JS1k demo: “Highway at Night”

#81

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.

It's not a stress test for the JS engine. This benchmark is not JS-bound.

Re: JS1k demo: “Highway at Night”

#83
post #62
post #58

I 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…

~x.indexOf(…) would be “starts with” rather than “contains”, for negative numbers such as -2 (from ~1) are truthy.

Re: JS1k demo: “Highway at Night”

#84

this 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.

Huh? Of course it is art. Look at all the random graphics and movement coming together to form a 3D street animation.

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”

#85
post #43
post #42

I 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?!

Me too. Since it crashed without showing the Crash Reporter dialog, I think it probably ran out of RAM or texture memory or something similar.

Re: JS1k demo: “Highway at Night”

#86
post #62

Earlier 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.

> ~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”

#87
post #64
post #62

Earlier 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.

No kidding, "clever" stuff like that drives me nuts.

Re: JS1k demo: “Highway at Night”

#88
post #77

Earlier 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…

Nobody needs this correction, I hope, but to be clear, it's !== -1 that we're replacing with ~. Then again, maybe this stands as a valid reason to be explicit in the first place. ;-)

Re: JS1k demo: “Highway at Night”

#89
post #78
post #58

I 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

Everyone I know uses the + operator, I rarely see others. Funny that I'm not seeing + here.

Re: JS1k demo: “Highway at Night”

#90
post #62

Earlier 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.

indexOf will only return -1, 0, or a positive integer
Post reply on HN