3 ms·
Representing styles as executable code is a very poor idea. Suddenly you go from data you can inspect and play with to something you can just execute and take
by JimDabell 11y ago
Representing styles as executable code is a very poor idea. Suddenly you go from data you can inspect and play with to something you can just execute and take what you are given.
The principle of least power is an incredibly important axiom of the web's architecture, and when people break it, lots of things become more difficult or impossible. If you don't like CSS, then by all means, propose a replacement – but please don't propose replacing it with executable code.
See:
Rule of Least Power – https://en.wikipedia.org/wiki/Rule_of_least_power https://en.wikipedia.org/wiki/Rule_of_least_power
Principle of Least Power – http://c2.com/cgi/wiki?PrincipleOfLeastPower http://c2.com/cgi/wiki?PrincipleOfLeastPower
- hollerith 11y ago>Representing styles as executable code is a very poor idea. Suddenly you go from data you can inspect and play with to something you can just execute and take what you are given. Continues to be true if we replace "styles" with "documents".
- matchu 11y agoCheck out the format for an inline style: { background: "red", fontWeight: "bold" } It's just a Javascript mapping from strings to strings. That's a very un-powerful language, and that's what React consumes. Sure, you could generate this mapping with all sorts of arbitrary code, just like how you could generate CSS with all sorts of arbitrary code. But that doesn't make the style declaration itself any more powerful, much less an arbitrary executable.
- davidkpiano 11y agoThere is a difference, though. The above code is still executable in that it renders the proper styling via JS at run-time, rather than at "compile" time (i.e. when it is preprocessed).
- matchu 11y agoThat's true, but I don't feel like it's relevant. React's inline styles API satisfies the principle of least power: you can only pass to it a mapping from string keys to string/number values. It's possible that the input data might be compiled from some other more powerful format, and it's possible to argue that this compilation step is a violation of the principle of least power, but that feels like a separate issue. It's very possible to use inline styles without adding unnecessary power to the declaration language - heck, you could declare them in JSON and load them during the build step if you want. How you use inline styles is your decision.