3 ms·
Multiple files as an antipattern? Good luck with that. If you use BEM, one of the many React style libraries, or any similar methodology for simulating local s
by acjohnson55 11y ago
Multiple files as an antipattern? Good luck with that.
If you use BEM, one of the many React style libraries, or any similar methodology for simulating local scope, any big problems with multiple files evaporate, and you get to reap the rewards of modularity. Granted, you still inherit styles from parent document elements, breaking modularity a bit, but for my purposes, it's close enough.
As a bonus, almost any perceived need to nest styles is also obviated.
On a side note, I found the tone of the article pretty obnoxious.
- marrs 11y agoI think it's often an anti-pattern. A good acid test for me would be, will modifying a rule written to a selector in one file affect a selector in another. If the answer is yes, then you haven't modularised by definition; you just think you have. This gets more complicated if you are doing SASS-style inheritance between selectors.
- gotchange 11y ago> will modifying a rule written to a selector in one file affect a selector in another. Actually this is how it's supposed to work in terms of code reusability and implicit inheritance. You change a detail in one dependency and that change propagates through the chain to every other dependent object. The trick is whether that change is intentional or not. When intentional, this is a sign of a good architecture and vice versa and the poor performance can be simply dealt with via good encapsulation to avoid future leaks.
- marrs 11y agoThe "good architecture" there is to begin by making things general and then build specialisation on top of that. This is essentially what the author was saying. At that point its an implementation detail if you have your CSS in one file or many. I think what the author is talking about is when you choose a module structure that is orthogonal to that. That is the square peg that he is referring to, by my interpretation.