4 ms·
I agree that frameworks might be a challenge. I would consider learning full-blown frameworks (e.g. React) pretty much like learning a new language, especially
by axiosgunnar 5y ago
I agree that frameworks might be a challenge. I would consider learning full-blown frameworks (e.g. React) pretty much like learning a new language, especially since JSX is a new syntax (albeit it's pretty much HTML).
Regarding React, I consider the "hooks" coding style to be INCREDIBLY ergonomic and have been wondering sometimes if React-like "hooks" could be used elsewhere, esp in other programming languages. Or does that only make sense with UIs?
- joshum97 5y agoI think React hooks would fit nicely anywhere you need incremental computation, and a compiler is the first thing that comes to mind. They’re made for efficiently updating the output (DOM) in response to small changes in the input (sum of past user actions). If you can format your problem like that, based on a component structure, a similar API might be a good fit.
- moshmosh 5y agoHooks are class-declaration except your properties and methods are read FIFO in declaration order, rather than by a lookup table. Unless you really like the FIFO part of it, OO languages all have that already.
- axiosgunnar 5y agoBut what I meant that I liked about hooks is the "automatic rerender" in React, the reason this feature is called "hooks". I'm not sure simply declaring a method on a class would be the same?
- moshmosh 5y agoIf you operate under the same restrictions as React (single-threaded, you must call a setter method to modify properties rather than accessing them directly, code outside your class is responsible for deciding whether to call its "render" method) then yes, it's the same. Change any of those and it gets harder in basically the same way it would for Hooks if any of those changed.
- dragonwriter 5y ago> Hooks are class-declaration except your properties and methods are read FIFO in declaration order, rather than by a lookup table. React Hooks are equivalent to React class components all of whose state management is done through setState, but with the difference you describe. Personally, I find hooks more natural than classes whose state management is done exclusively through setState, but that’s obviously a big YMMV.