Live data from Hacker News

JavaScript Pattern Matching Proposal

github.com

251–254 of 254 posts

Re: JavaScript Pattern Matching Proposal

#251

Earlier quoted context omitted.

Well said. Rambling Java code with little to no abstraction is its own kind of nightmare. Some people are just terrified of any new abstractions, I guess, preferring to work with an endless series of tally marks, rather than these obfuscating “multiplication” and “exponent” complications (exaggerating to make a point - abstract != unintelligible).

I think there is probably some middle ground between "no abstraction at all" and "literally anything goes."

LCD?

Alas, that tends to be the steady state for Enterprise development :-(

(I know that’s not literally what you said, but that’s where that “middle ground” attitude leads to: the bottom)

Re: JavaScript Pattern Matching Proposal

#252

Earlier quoted context omitted.

Yes, there are cases when arrow functions are useful: when small functions are used inline, like this: var numbers = [1, 2, 3, 4].map(x => x * x); var bestUsers = users.filter(u => u.getRating() > 100); But for a case when you have a large non-anonymous function, `function` keyword suits better. You don't need to use `const` keyword just becase it is something trendy now. In your example, the code with arrow function…

> A Deferred object is returned by the obsolete Promise.defer() method to provide a new promise along with methods to change its state. > Starting from Gecko 30, this object is obsolete and should not be used anymore. Use the new Promise() constructor instead (or use the above backwards/forwards compatible Deferred function given below). For example, the equivalent of Seems like it's obsolete. [0] If you want to writ…

> Seems like it's obsolete.

Then you can write your own Deferred implementation. I didn't even know it was implemented in browsers.

     const run = async () => { ... }
How to read this? run is a constant that equals the result of calling function async() thas maps to something in curly brackets? This is confusing.

> If you want to write async code, use async / await.

That is a good idea, but it has nothing to do with arrow functions.

> It also allows you to do scope binding in a different manor

`this` binding in JS in classic functions is broken by design, so yes, that is the advantage of arrow functions.

Re: JavaScript Pattern Matching Proposal

#253

Earlier quoted context omitted.

If you mean by method-based pattern matching that you evaluate a function for each 'case'. My lib can do that do: const match = require('pmatch-js') const _ = require('lodash') const fizzbuzz = x => match(x) .when(a => a % 3 == 0 && a % 5 == 0, 'fizzbuzz') .when(a => a % 5 == 0, 'buzz') .when(a => a % 3 == 0, 'fizz') .otherwise(a => a) console.log( _.range(1, 101).map(fizzbuzz).join(' ') ) But maybe you mean somethin…

Wow, importing the whole lodash to use just one function? There’s es6 way of getting an array with a range of numbers: [...Array(100).keys()].map(v=>v+1) A little bit longer but no dependencies.

Although this method is pretty, I see 4 loops in this small line. a better way would be to only import the range method from lodash like so :

    import _range from "lodash/range";

Re: JavaScript Pattern Matching Proposal

#254

Leaving aside syntax preferences or other superficial concerns, I find it discouraging that "Motivating Examples" for a proposal include direct references to particular libraries, or particular libraries' examples. I mean, that one (of two) motivations for adding a feature to a language is "Terser, more functional handling of Redux reducers", just feels wrong and casual.

Well, think about the @ operator in python. It's aimed solely at people who use numpy.
Post reply on HN