tc39 / proposal-structs

JavaScript Structs: Fixed Layout Objects
http://tc39.es/proposal-structs/
627 stars 11 forks source link

Different syntax compared to classes. - Take inspiration from rust #43

Open Jordan-Hall opened 1 month ago

Jordan-Hall commented 1 month ago

Some developers prefer not to constantly use this in classes, as classes in general can lead to larger files and complicate code splitting. They much prefer a functional approach. I believe it would be a good idea, considering memory and parallel processing, to examine the syntax available.

Suggestion: Make structs more like Rust, as many JavaScript tools are leaning towards Rust, taking into account proposals like JSSugar/JS0, where tooling becomes first-class. If type annotations become a reality, it would make sense to adopt Rust syntax for structs, traits (type annotations), and impl for implementation rather than extension.

This would eliminate the limitations surrounding multiple inheritance, which is still restricted to mixins and thus not safe for parallel processing. It also offers a good middle ground between classes and functions, facilitating code splitting. I don't believe it would be good idea to allow structs to be extended like classes if we looking for good memory management

I don’t want to derail the feature, but I have been thinking long-term about an additional proposal. It would be misguided to impose restrictions based on features or syntax that has already been implemented.

bakkot commented 1 month ago

The "type annotations" proposal is not adding types to the language, just new syntax for comments. The rest of the Rust stuff doesn't make sense unless the types actually have semantics, which they won't in JS.

Jordan-Hall commented 1 month ago

i thought that was just the first version. i dont think extending struct is a good idea. Structs will become too heavy