News for hackers. Stuff that matters.
Re:Introducing Hooks by schneidmaster on Thursday October 25, 2018 @02:11PM (#18303109)
In the live talk, Sophie also discussed how Javascript classes are difficult for machines: minifiers aren't able to shorten the names of methods (because it's apparently hard to work out all the ways that the method could be invoked), and they cause stability problems with hot code reloading. So there are benefits beyond ease of use for humans.

(Also, I'm pretty fluent in Javascript and I still forget to bind event handlers all the time, which suggests to me that it's a counterintuitive pattern even if I know "how it works" on a technical level. And you either have to put a bunch of "this.handler = this.handler.bind(this)" in the constructor, or rely on class properties which are an unstable syntax feature, both of which are suboptimal.)

Re:Introducing Hooks by adpirz on Thursday October 25, 2018 @04:02PM (#18304105)
It may have been on purpose (came off as a sincere mistake), but Dan Abramov forgets to bind them in this talk while giving an example. It's a very common problem, even for the authors of React itself :)
Re:Introducing Hooks by azangru on Thursday October 25, 2018 @08:31PM (#18305844)
It did come off as a sincere mistake, but remember, they had a dry run of the talks a day or so before. So could have easily been staged. But was hilarious anyway.
Re:Introducing Hooks by codefined on Thursday October 25, 2018 @06:00PM (#18304955)
> because it's apparently hard to work out all the ways that the method could be invoked

Simple example case of a statement that makes it impossible to minify function names:

    class Test { static func() { /* function code */ } }
    test[prompt('function to call')]()
Re:Introducing Hooks by baddox on Thursday October 25, 2018 @11:11PM (#18306465)
Doesn’t that example also make it impossible to minify the names of anything? Perhaps other than JavaScript modules, since AFAIK the popular module builders like Webpack do compile-time module importing (I believe that even the dynamic import function is recognized at compile time and doesn’t support throwing in a prompt).
Re:Introducing Hooks by AgentME on Monday October 29, 2018 @05:17PM (#18331583)
No, that issue is unique to class/object property names. You can't dynamically reference a variable in a scope by name supplied by a variable in the same way (except by using `eval`, which does in fact cause minifiers and javascript engines to disable a bunch of optimizations in the scope it's used).
Re:Introducing Hooks by boubiyeah on Friday October 26, 2018 @02:15AM (#18307135)
Of course it's unintuitive. I see dev veterans make the mistake all the time.

JS was so poorly designed. An implicit (not passed as an arg), dynamic this parameter. You couldn't be more cheeky than that really.

something like console.log.bind(console.log) is beyond silly. It's what we're stuck with but I will minimize the occurences of that kind of crap any single time I can.

Re:Introducing Hooks by Touche on Thursday October 25, 2018 @04:21PM (#18304247)
You can just do `onChange={() => this.handler()}`.
Re:Introducing Hooks by jotaen on Thursday October 25, 2018 @04:44PM (#18304428)
This would create a new inline function on every render though, which potentially might cause rendering performance issues.
Re:Introducing Hooks by Touche on Monday October 29, 2018 @08:50AM (#18327041)
The Hooks way creates a lot of inline functions on every render.
Re:Introducing Hooks by lilactown on Thursday October 25, 2018 @07:45PM (#18305606)
Hardly ever.