Hacker News new | ask | show | jobs
by codedokode 237 days ago
I don't like the style of code in the article, with weird functions like "useState" and "useSignal". Looks ugly to me.

Also, it seems that with signals you must use immutable values only. Imagine if you have, let's say, a text document model, and you need to create a new copy every time the user types a letter. That's not going to work fast. And there will be no granular updates, because the signal only tracks the value (whole document), not its components (a single paragraph).

Also the article mentions rarely used preact and doesn't mention Vue. Vue can track mutable object graphs (for example, text document model). But Vue uses JS proxies that have lot of own issues (cannot access private fields, having to deal with mixing proxies and real values when adding them to a set, browser APIs break when a proxy is passed).

Also I don't like that React requires installing Node and compilation tools, this is a waste of time when making a quick prototype. Vue can be used without Node.

6 comments

Immutable does not mean you have to copy the whole structure. You can store only the changes. This is how immutable data structures work in functional languages such as Haskell.
I know about different data structures but they are all more complicated than mutable data structures. For example, if you "store only changes", it will take more time to access the data, and you need to flatten your changes once in a while.

Also, for nested data structures you need to either do path copying, or use "modification boxes" [1].

[1] https://en.wikipedia.org/wiki/Persistent_data_structure#Tech...

  > Also I don't like that React requires installing Node and compilation tools, this is a waste of time when making a quick prototype. Vue can be used without Node.
React can be used without Node too, and this has always been the case to the best of my knowledge. You can check out this gist which is linked from the official docs[1]: https://gist.githubusercontent.com/gaearon/0275b1e1518599bbe...

[1] https://react.dev/learn/installation#try-react

  Vue can be used without Node.
You lose a lot though! You don't get minification and tree shaking, single file components, or hot module reloading. In practice, HMR outweighs the cost of setting up a Node/Deno/Bun environment.
> it seems that with signals you must use immutable values only. Imagine if you have, let's say, a text document model, and you need to create a new copy every time the user types a letter.

Too small. Imagine if you have a 2GB mutable file. Each keystroke in the middle of the file has to move the whole 2nd gigabyte backward.

Immutable representations of large buffers aren't flat arrays. The most obvious abstract semantics that we're depending on here is a map from indexes to byte segments. Immutably rearranging indexes can be made very fast.
> Imagine if you have, let's say, a text document model, and you need to create a new copy every time the user types a letter. That's not going to work fast. And there will be no granular updates, because the signal only tracks the value (whole document), not its components (a single paragraph).

Funnily enough, back when storage was slow enough that saving a text document involved a progress bar, one of the big advantages Word had over competitors was lightning fast saves, which they accomplished by switching to an immutable data structure. That is, while others would update and save the data, Word would leave it untouched and just append a patch, skipping lots of time spent rewriting things that an in-place edit would shift.

The “copy everything” mental model of immutable programming is really about as wrong as a “rewrite everything” mental model of mutable programming. If it happens it’s bad code or a degenerate case, not the way it’s supposed to happen or usually happens. Correctly anticipating performance requires getting into a lot more detail.

React is crazy because someone thought this was too complicated for developers:

    event.listenTo(render);
    event.emit();
And that we should do this instead:

    property.listenTo(render);
    property.set([property.get()[0]]);