Earlier quoted context omitted.
Other than the fact we have BigInts now, we also have * tensorflowjs, which runs on GPUs https://www.tensorflow.org/js and * danfo, which aims to be a pandas equivalent for JS: https://danfo.jsdata.org/ Given the powerful interactive visualisation capabilities available in JS, its only a matter of time until JS becomes a serious contender IMO.
> Other than the fact we have BigInts now performance-wise, BigInts are terrible. Tried to use them, made things about a hundred times slower.
JavaScript for Data Science
51–60 of 83 posts
Re: JavaScript for Data Science
#52Earlier quoted context omitted.
> Numbers are 64bit floats only - no integers, no big numbers. That is not true. BigInt has been available for a bit already. MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... Availability: https://caniuse.com/bigint I don't want to argue for or against using JS for "data science" (I myself used R for that but I use JS a lot for other things), just a clarification on this one concrete claim.
> That is not true. BigInt has been available for a bit already. performance-wise, BigInts are terrible. Tried to use them, made things about a hundred times slower. What JS needs are 64 bit integer types, and some form of typing system that allows differentiating between various number types.
Re: JavaScript for Data Science
#53Earlier quoted context omitted.
> Numbers are 64bit floats only - no integers, no big numbers. That is not true. BigInt has been available for a bit already. MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... Availability: https://caniuse.com/bigint I don't want to argue for or against using JS for "data science" (I myself used R for that but I use JS a lot for other things), just a clarification on this one concrete claim.
> That is not true. BigInt has been available for a bit already. performance-wise, BigInts are terrible. Tried to use them, made things about a hundred times slower. What JS needs are 64 bit integer types, and some form of typing system that allows differentiating between various number types.
Re: JavaScript for Data Science
#54I don’t want to repeat the old and tired JavaScript hate, but this just isn’t a great idea. I’d suggest that there are 3 important primitives for data science: flexible numeric types, fast math/algorithm libraries, and data manipulation being easy. JavaScript doesn’t really have any of these. Numbers are 64bit floats only - no integers, no big numbers. There aren’t equivalents to Numpy/Pandas/Scikit Learn, and the la…
JavaScript does have integers (e.g. `Uint8Array`) and it also has big numbers (e.g. `BigInt`). It's true that there's not yet an equivalent to Numpy/Pandas/Scikit yet, but POCs show that it will be possible to create such a thing and that we will be able to use the WebGPU API to access higher performance than is available using Python [2].
I'm not saying that it will definitely happen, but why not?
[1] http://benschmidt.org/post/2020-01-15/2020-01-15-webgpu/
Re: JavaScript for Data Science
#55Data scientists are the new webmasters.
Re: JavaScript for Data Science
#56Re: JavaScript for Data Science
#57I don’t want to repeat the old and tired JavaScript hate, but this just isn’t a great idea. I’d suggest that there are 3 important primitives for data science: flexible numeric types, fast math/algorithm libraries, and data manipulation being easy. JavaScript doesn’t really have any of these. Numbers are 64bit floats only - no integers, no big numbers. There aren’t equivalents to Numpy/Pandas/Scikit Learn, and the la…
On point 3 - I had to implement a logistic regression model in js recently and implementing all of the required math methods (eg dot product, transpose, vectorized addition, etc.) were actually super easy with js’s functional array utilities.
Re: JavaScript for Data Science
#58Earlier quoted context omitted.
Not changing `this` is a huge benefit that shouldn't be ignored. Especially when you're programming in a more functional style, it makes sense to default to arrow functions because you never want to engage in `this` shenanigans anyway. So, yes, I'd say it's a pretty common idiom in the JS community to replace "normal" function declarations.
I agree that inheriting the `this` for arrow functions is beneficial. To me it seems like you would want to use the normal syntax for global functions for hoisting and to prevent unintentional re-definitions, the arrow functions where you would use lambda functions in other languages, and the class method syntax for methods. side-note: Most of my JS experience is writing userscripts for myself, so I definitely do my…
Take the following example, which is a normal class method:
> alertSum() { alert(this.a + this.b); }
And here we have an arrow function used to create an instance method (just an arrow function assigned to a property on the instance):
> alertSum = () => { alert(this.a + this.b); }
Then let's say we want to pass the method directly as callback:
> this.button.addEventListener('click', this.alertSum)
The first example (class method syntax) won't have the necessary `this` context unless it has its context bound to the instance through `Function.prototype.bind`. There are other patterns to avoid this (e.g. wrapping all callbacks in arrow functions when passing them), but it's useful to consider that classes methods can easily create confusion because that's _exactly where_ someone more used to a different language may assume the `this` context is bound lexically.
Re: JavaScript for Data Science
#59Earlier quoted context omitted.
I agree that inheriting the `this` for arrow functions is beneficial. To me it seems like you would want to use the normal syntax for global functions for hoisting and to prevent unintentional re-definitions, the arrow functions where you would use lambda functions in other languages, and the class method syntax for methods. side-note: Most of my JS experience is writing userscripts for myself, so I definitely do my…
As a heads up since you mentioned "class method syntax", methods are one of the most important places to have lexical `this` binding in many scenarios. Take the following example, which is a normal class method: > alertSum() { alert(this.a + this.b); } And here we have an arrow function used to create an instance method (just an arrow function assigned to a property on the instance): > alertSum = () => { alert(this.a…
Edit: I was confused about how this could work, so I dug through [1] for a bit. It appears that for each object of that class created, an arrow function will be created on that object and its this will indeed be bound to the same scope that the constructor function is bound to. This is really cleaver and I applaud whoever thought it up!
It is interesting to note that this creates a new arrow function on each object as opposed to the normal definitions which create a single function which is stored in the prototype of the class. (its easier to check this in a browser's dev console then it is to decode the spec)
This would suggest that one should use different approaches for different types of objects: It makes sense to use arrow functions for "resource" or "actor" objects, of which there are few but they may have callback functions. It makes sense to use normal method definitions for "plain old data", of which there may be many, (which would make the arrow functions too expensive) but they should not have callback functions.
Re: JavaScript for Data Science
#60Earlier quoted context omitted.
> That is not true. BigInt has been available for a bit already. performance-wise, BigInts are terrible. Tried to use them, made things about a hundred times slower. What JS needs are 64 bit integer types, and some form of typing system that allows differentiating between various number types.
Genuine question: I imagine most data science things involve arrays of numbers, not just single numbers. JS has UInt8Array, i.e. it does kinda have integers if you want them in an array anyway. Can that speed things up?