News for hackers. Stuff that matters.
Re:Stepping Away from Sass by gitgud on Thursday April 25, 2019 @09:37PM (#19754122)
I feel that yes SASS requires less source code, but the nesting is kind of an anti-pattern and encourages complex hierarchies of styles which are hard to follow and maintain.
Re:Stepping Away from Sass by rhizome on Thursday April 25, 2019 @10:22PM (#19754325)
How come I haven't experienced these downsides?
Re:Stepping Away from Sass by andykx on Thursday April 25, 2019 @10:41PM (#19754411)
I'm with you. My SCSS is really just CSS with nesting. My CSS is cleaner without any downside. I've never experienced issues with maintainability, even in large CSS files.
Re:Stepping Away from Sass by pixelbash on Thursday April 25, 2019 @10:42PM (#19754416)
That's where I am on this. Before nesting I had to take great care to avoid conflicts. I guess this is what BEM set out to solve, but it seems to have limitations.
Re:Stepping Away from Sass by BigJono on Thursday April 25, 2019 @11:32PM (#19754631)
Why would sass have any effect on whether or not you have conflicts? You can just do things in plain CSS with descendant (' ') selectors, same as if they were nested in sass.
Re:Stepping Away from Sass by mercer on Friday April 26, 2019 @03:54AM (#19755558)
Sure, but that's a bit like arguing that you don't need 'scope' for your variables and you can just prepend the function name (or multiple nested function names). Or that you don't need modules but can just put all your code in one file.

At the very least support of nesting is a huge convenience, but in practice I've also found that it saves me from all sorts mistakes, whether it's because I'm being stupid, or refactoring things.

That said, overusing nested selectors can be a problem too. I generally try to limit myself to two levels of nesting (component -> element), and then a third for pseudo-classes (:hover, :selected, etc.) and pseudo-elements (:before, etc.).

Re:Stepping Away from Sass by gitgud on Friday April 26, 2019 @08:53AM (#19756902)
Probably for the same reason some people don't see the downsides of C++ or Java... you tend not to see the downsides, if you're good at it.

I just feel that nesting (which Sass encourages) leads to complexity and fragility.

Re:Stepping Away from Sass by stickfigure on Friday April 26, 2019 @09:10AM (#19757023)
Hi, you seem to be the leading critic of nesting on this page, so I have a question for you.

Assuming you're using a component framework like React, Vue, or Angular (and not a shadow dom based system like Polymer), how do you isolate your component CSS?

When I make a component 'MyComponent', I give it the className 'MyComponent'. Then I can create a SCSS file and scope its entire contents:

    .MyComponent {
        // all the css specific to MyComponent
    }
Without nesting, how do you keep your component-specific CSS from polluting the rest of your app? Do you scope every rule every time? Isn't that tedious?
Re:Stepping Away from Sass by gitgud on Friday April 26, 2019 @09:29AM (#19757210)
Thank you, I'll wear the title of: leading critic of nesting proudly! disclaimer I'm not a hugely experienced programmer, but have done a few open source projects in Vue, React and am currently working on a series of Angular applications with a team at work.

In Vue and Angular component styles are automatically encapsulated at the component level by scoping (I think) so nesting isn't really necessary to target specific components. Angular also recently deprecated a method of breaking out of component styling and soon it will be completely removed from the framework.

Although I'm a critic I'm not totally against nesting, I just feel that SASS encourages it, so without discipline things can get very complex and fragile. One level of nesting is OK with me though I suppose...

Re:Stepping Away from Sass by rhizome on Friday April 26, 2019 @06:52PM (#19762459)
without discipline things can get very complex and fragile

In what way(s) is SASS different than anything else in this regard?

Re:Stepping Away from Sass by gitgud on Friday April 26, 2019 @08:54PM (#19763040)
True, this could be said for any system, but in this case SASS makes it easy to create nested relationships, whereas CSS makes it hard.
Re:Stepping Away from Sass by riz_ on Friday April 26, 2019 @09:35AM (#19757267)
Not OP, but you could use CSS modules, styled components or styled-jsx, all of which auto-generate unique classnames (styled-jsx uses a HTML attribute for it, I think).
Re:Stepping Away from Sass by stickfigure on Friday April 26, 2019 @03:10PM (#19760862)
I see.

These solutions all seem quite a lot more complicated than nested scopes! And at least for styled components (angular, I presume) and styled-jsx (react), they're framework-specific. Why are these solutions better?

Re:Stepping Away from Sass by type0 on Friday April 26, 2019 @05:15AM (#19755839)
As with everything, don't overdo it and you'll be fine.
Re:Stepping Away from Sass by GordonS on Friday April 26, 2019 @06:57AM (#19756206)
I generally stick to only 1 level of nesting - I still find that really beneficial.