News for hackers. Stuff that matters.
Re:Stepping Away from Sass by statictype on Thursday April 25, 2019 @07:49PM (#19753624)
Does a preprocessor really complicate the workflow?

Variables are still new and not fully supported.

Being able to nest css selectors is major win for me.

Reusable mixins is another.

I just don’t see a compelling enough use case today to switch to pure css for non trivial applications.

Re:Stepping Away from Sass by marcus_holmes on Thursday April 25, 2019 @10:09PM (#19754260)
>>Does a preprocessor really complicate the workflow?

I've just spent yesterday getting sass to work with my Golang project.

I used to have a nice simple makefile task, that compiled the project (in a split second) and launched it on localhost so I could find out where the problems were. My only dependency was the Go compiler. If I changed the css, the next page refresh sorted it.

Now I have a "sass watch" task, which compiles the scss to css. But that requires node.js, and npm (there are golang scss compilers, but all of them are either not being maintained, or have problems, or only support older versions of scss). I have to run this in a separate terminal so I can stop it when I need to.

I've deliberately not looked at my global node_modules directory. If I don't look, I don't have to worry about how many js libraries just got installed on my machine, and I don't have to think about who's maintaining them, and if they're now malicious. As long as sass only touches the css files, and css isn't Turing-complete (yet), then I don't need to audit any of that, and I can assume that it's not injecting malicious code into my application.

Though there are possible attacks on my site that could originate with code injection from a $malicious_left_pad js library, even via css, but it's enough of a stretch that my paranoia can live with it. I can check out the compressed css every now and again and see that it's not importing anything it shouldn't, and be reasonably sure that I haven't just compromised all my users' security.

So yeah, it's not so much that a preprocessor is a complication, it's that a preprocessor allows a malicious package to compile whatever it likes into files that I will then serve from my domain to my users, who trust that I'm not serving them malicious files. That's policed not at all by npm, or any of the package managers, who cheerfully assume that all javascript developers are honest.

Re:Stepping Away from Sass by stephenr on Thursday April 25, 2019 @11:02PM (#19754493)
Use sassc and call it from your makefile.
Re:Stepping Away from Sass by jayshua on Thursday April 25, 2019 @11:29PM (#19754615)
Not sure what it's like today, but last time I tried to use sassc it was a nightmare. The official repo was just the library with no CLI. I couldn't find a CLI that didn't also require me to compile it myself. Very frustrating.
Re:Stepping Away from Sass by wutwut5521 on Thursday April 25, 2019 @11:33PM (#19754633)
You might be thinking of libsass. sassc is dead simple and solves all of this users issues.
Re:Stepping Away from Sass by jayshua on Thursday April 25, 2019 @11:44PM (#19754674)
Correct me if I'm wrong, but doesn't sassc require the user to compile it?
Re:Stepping Away from Sass by wutwut5521 on Friday April 26, 2019 @10:48AM (#19758082)
You have to compile it, just like this poster has to compile their go code. There are usually packages and formulas for it in most std repos.
Re:Stepping Away from Sass by tangue on Friday April 26, 2019 @12:13AM (#19754818)
You're right, on OSX you can brew install sassc
Re:Stepping Away from Sass by marcus_holmes on Friday April 26, 2019 @01:25AM (#19755051)
there's a Debian package :) thanks for the tip :)
Re:Stepping Away from Sass by marcus_holmes on Friday April 26, 2019 @06:17AM (#19756046)
just got this working with fswatch and sassc, thought I'd feed back that this is perfect, thanks :)
Re:Stepping Away from Sass by wutwut5521 on Friday April 26, 2019 @10:46AM (#19758067)
Heh, I just woke up and read this and thought “well thats enough problem solving for today” :) Glad we could help you avoid the hell that is adding npm to a non-node project!
Re:Stepping Away from Sass by mercer on Saturday April 27, 2019 @04:48PM (#19767540)
Another thank you from here! I've had to use node just for sass in the past and this is a much nicer solution.
Re:Stepping Away from Sass by sureaboutthis on Friday April 26, 2019 @08:18AM (#19756652)
So a tool to fix the tool that's supposed to make things better.
Re:Stepping Away from Sass by stephenr on Friday April 26, 2019 @02:03PM (#19760235)
Huh?

SassC is just a cli tool that uses the C-language SASS library. It's an alternative to using whatever ridiculous NodeJS solution was/is being used.

Re:Stepping Away from Sass by speleding on Friday April 26, 2019 @04:46AM (#19755723)
I've been using the ruby Sass gem instead of the NPM version (https://sass-lang.com/ruby-sass). That prevents having to do the whole node thing. I know they say the ruby version is in maintenance mode, but for 99% of the use cases that's fine, it's been battle tested for years and Sass doesn't change that often anymore.
Re:Stepping Away from Sass by yawaramin on Thursday April 25, 2019 @11:35PM (#19754638)
> I can assume that it's not injecting malicious code into my application.

You don't need to assume, npm has an audit command that helps figure out if any of your package dependencies have reported vulnerabilities: https://docs.npmjs.com/cli/audit

Does Go?

Re:Stepping Away from Sass by marcus_holmes on Friday April 26, 2019 @01:18AM (#19755029)
useful, I didn't know about this. Thanks. How does the reporting of vulnerabilities work for npm?

No, Golang doesn't, but then it doesn't have a registry like npm in the first place. Gophers tend not to use third-party libraries if at all possible.

Re:Stepping Away from Sass by justinclift on Friday April 26, 2019 @03:29AM (#19755473)
> Gophers tend not to use third-party libraries if at all possible.

That sounds weird to me. It's pretty rare (almost never?) for applications to do useful things without third party libraries. eg any database access, input validation, making sure HTML output isn't malicious, etc.

Maybe that's just me though?

Re:Stepping Away from Sass by marcus_holmes on Friday April 26, 2019 @06:25AM (#19756078)
Go has an awesome standard library that does most stuff.

There's also a set of "semi-official" libraries for things like crypto that can't be written by amateurs ;)

There are some other libraries that are commonly used, but you can count them on one hand.

I'm a massive convert to this. Instead of spending my time working out how to get two 3rd-party libraries to talk to each other, I spend my time writing domain-specific code. and my debugging time is spent in repo's that I have a hope of understanding because I wrote them ;)

It doesn't suit everyone, and there are frequent rants on golang forums about people not importing dependencies. But every gopher seems to go through the same journey, and end up at a place where they just write their own code rather than importing it.

Re:Stepping Away from Sass by jcr1488 on Saturday April 27, 2019 @11:17PM (#19769112)
What's even more weird is making every 10 line function a "library" and the average program having 500+ dependencies. JS people are so hung up on "re-usability" that they completely miss the concept of dependency hygiene.
Re:Stepping Away from Sass by yawaramin on Friday April 26, 2019 @06:40PM (#19762372)
Re:Stepping Away from Sass by thecatspaw on Friday April 26, 2019 @03:01AM (#19755377)
isnt it very common to use github repositories as a library? I seem to recall that this was the way to get libraries, though it has been a few years since I looked into go
Re:Stepping Away from Sass by marcus_holmes on Friday April 26, 2019 @06:20AM (#19756064)
yes, but there's not an actual "registry" as such. Just a bunch of sites that have "useful go library" links.
Re:Stepping Away from Sass by type0 on Friday April 26, 2019 @05:11AM (#19755817)
I find that https://github.com/wellington/go-libsass is usually good enough for Go projects.
Re:Stepping Away from Sass by marcus_holmes on Friday April 26, 2019 @06:19AM (#19756061)
yeah, I looked at that, but a few things put me off (unmaintained, old version of scss, some caveats in the readme, etc).

Just got sassc working instead, so happy again hehe

Re:Stepping Away from Sass by baddox on Thursday April 25, 2019 @09:47PM (#19754157)
Don't forget that SASS lets you use sane single-line comments prefixed by a double-slash. Heck, I'd use it just to avoid the laughably terrible /* CSS comment syntax */.
Re:Stepping Away from Sass by tobr on Friday April 26, 2019 @03:11AM (#19755414)
It works in practice though, because there’s no CSS syntax that uses //, so you can basically turn off any line that way by causing a syntax error. CSS fault tolerance makes it just ignore the line. Not sure if it’s wise to do this, but it works.
Re:Stepping Away from Sass by baddox on Friday April 26, 2019 @07:14AM (#19756287)
That’s a valid point. I’ve never actually tried it, because my editor always tells that it’s wrong. I suppose I could edit raw CSS with my editor in SCSS mode and just be careful to not use any incompatible features. :)
Re:Stepping Away from Sass by rhizome on Thursday April 25, 2019 @08:18PM (#19753762)
Nesting is by far the biggest driver for me. I can do vanilla CSS in my sleep, but it's such a cognitive drag.
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.
Re:Stepping Away from Sass by jorgesborges on Thursday April 25, 2019 @10:06PM (#19754246)
Nesting is only an asset with thoughtful consistency. There are so many different ways to organize a stylesheet with nesting it can easily become unruly. But I like it now because I've found a method that works for me while also cleaning up my html.

In some cases I can preclude the necessity of having to declare class names.

section {

  h1 {},

  p {},

  img {},
}

In other cases I have an index with easy-to-find classes.

.hero {

  .gradient {},

  .description {},

  .signup {},
}

EDIT: I meant to reply to a different comment but oh well.

Re:Stepping Away from Sass by sureaboutthis on Friday April 26, 2019 @08:20AM (#19756662)
> vanilla CSS

Is there another kind of CSS?

Re:Stepping Away from Sass by rhizome on Friday April 26, 2019 @04:11PM (#19761336)
You know what I mean, Sheldon.
Re:Stepping Away from Sass by sureaboutthis on Saturday April 27, 2019 @09:12AM (#19765321)
My point is, one need not apply an adjective to something that does not need qualifying. Just like "vanilla" JavaScript. You are either using JavaScript or you're not but people have been doing that for years and now I see posts asking for definitions or differences between "vanilla" and other flavors of js.

Terminology is important but I see it's not important among some people and other hobbyists online.

Re:Stepping Away from Sass by goddtriffin on Saturday April 27, 2019 @11:22AM (#19765972)
I can't speak for the others, but when I use the terms 'vanilla JavaScript' and 'vanilla CSS', the distinction I'm trying to make is that I'm not using any libraries or frameworks.

There is a meme within the community about 'vanilla JavaScript' called VanillaJS:

http://vanilla-js.com/

https://stackoverflow.com/questions/20435653/what-is-vanilla...

Re:Stepping Away from Sass by sureaboutthis on Saturday April 27, 2019 @11:38AM (#19766041)
Saying I'm using JavaScript is sufficient. Or stating "I'm not using any libraries or frameworks" works, too.
Re:Stepping Away from Sass by mercer on Saturday April 27, 2019 @04:59PM (#19767586)
This is a weird thing to argue about.

The overwhelming majority of front-end projects and developers that I encounter use some kind of library, framework, or compilation/build tool. It's common enough to basically be the default.

If you use 'plain' or 'vanilla' javascript (or CSS), you're doing something less common, at the very least around these parts, and so qualifying this makes sense. The mere fact that many people clearly seem to feel a need to point this out makes it so. Why would they otherwise?

Judging by your comment history, the vast majority of your contributions here boil down to some kind of dig at how 'people these days' are 'doing it wrong', and how obviously you are superior to that and how you don't see the need for any of this new-fangled stuff. I'm honestly curious whether that's just role-playing, or if that kind of superiority about being older and wiser is somehow important to you.

I'd very much prefer it if you shared the wisdom you've accrued in a more constructive way, because as far as I can tell you're not actually wrong about a lot of this stuff.

Older and wiser curmudgeons have played a valuable role in my development, but your approach strikes me as self-serving and somewhat poisonous to the/any community. But of course you're free to do as you please.

Re:Stepping Away from Sass by rhizome on Saturday April 27, 2019 @11:49AM (#19766087)
I don't care if you didn't need it, because it's helpful for clarity regardless.

https://stackoverflow.com/a/40115909/135845

Unfortunately, I see that "The Ubuntu Web Team" decided to shit the bed and steal the name for the CSS framework they created. So fsck me I guess.

Re:Stepping Away from Sass by namelosw on Thursday April 25, 2019 @10:00PM (#19754211)
Nesting is bad, because moving any element would break your style. And there's also performance impact.

I found scoped css like component or BEM just make sense, which only encourage you nest one level in block namespace.

Re:Stepping Away from Sass by dmitriid on Friday April 26, 2019 @02:17AM (#19755228)
BEM is just an awkward workaround for the lack of nesting.

You’re manually creating nesting hierarchies and naming them (something a computer should be doing).

And yes, the moment you move something, everything breaks. Because instead of moving/renaming just the parent selector you have to move/rename all the related child selectors.

Re:Stepping Away from Sass by namelosw on Friday April 26, 2019 @07:01AM (#19756222)
No what I mean by move something I mean adjust HTML structure, and deeply nested stylesheet means less flexible code. You can move anything within a BEM block without breaking style, instead of couple the CSS and HTML structure, which doubles every change.

And BEM is a workaround of names pace, not nesting. Nesting is not what CSS lack of. Instead what CSS really lack for is basic abstraction like function (same as function component in react to HTML). Given CSS is basically similar to key value pair (data), a first class function model would solve most of the problems - reusing, encapsulation, abstraction etc.

Re:Stepping Away from Sass by psychometry on Thursday April 25, 2019 @11:15PM (#19754547)
There's no performance impact. Styles are precompiled locally before deployment.
Re:Stepping Away from Sass by namelosw on Thursday April 25, 2019 @11:20PM (#19754568)
There is, at runtime browser needs to do extra matching.

https://stackoverflow.com/questions/13829959/nested-selector...

It's about Less but the same rule applies to CSS and Sass.

Re:Stepping Away from Sass by steveax on Friday April 26, 2019 @02:02AM (#19755169)
Note the date on that. It’s my understanding that with modern browsers, except in pathological cases, selector performance is pretty much a non issue.
Re:Stepping Away from Sass by Raphmedia on Friday April 26, 2019 @09:35AM (#19757260)
When we are talking about nesting we are not talking about generating `.page #left-section .box .button {}`... This would be bad. Nesting used properly is something like `.myWidget .button, .myWidget .title, .myWidget .main-section {}`. You can then move .myWidget anywhere you want and the styles would follow.
Re:Stepping Away from Sass by wwweston on Thursday April 25, 2019 @08:07PM (#19753707)
I still use less & sass on most projects, but it's occurred to me that:

* Duplicating the effect of mixins by just... having another css class for the mixed-in stuff works well enough for many cases (though this hurts most where you're trying for semantic selector naming conventions, with mixins adding in rulesets behind the scenes).

* Nesting selectors save thinking and some typing regarding where styles cascade out to, but... tbh, yanking a high-resolution selector into the buffer and chucking it out onto another line was never a burdensome part of my pre- processor workflow.

* Pretty sure free-use of nested selectors and mixins is trading larger CSS files for developer attention (which may or may not be a valid trade).

* Variables... yeah, they're handy. Search-and-replace only goes so far. IE seems to be the holdup.

For small or disciplined teams with the freedom & skill to really think about their CSS starting from a style-guide-first perspective rather than every-page-a-custom-layout perspective, I can see making the choice to do without. Especially if you've already ditched IE 11 support for other reasons.

Re:Stepping Away from Sass by nine_k on Thursday April 25, 2019 @09:03PM (#19753982)
Writing pure CSS and copy-pasting things here and there is easy when you start.

Where SASS shines is when you need to do a coordinated change, e.g. these things become gray instead of black. You have a ton of black things so no search and replace. And once you've painstakingly determined and edited the classes, the hard part is to be sure that you only changed what you had to, and nothing unrelated.

SASS preserves semantics which plain CSS is unable to express. It's like C vs assembly.

Re:Stepping Away from Sass by lugg on Thursday April 25, 2019 @09:40PM (#19754134)
You mean variables?

Because I've seen sass refactors go just as badly.

Re:Stepping Away from Sass by daxterspeed on Friday April 26, 2019 @08:34AM (#19756753)
Nested CSS selectors should be counted as a major win for everyone - to the point where there's proposals to support it in native CSS: https://github.com/w3c/csswg-drafts/issues/2701

My personal solution to avoid running watchers is to have a run-on-save task in VSCode that automatically compiles any "root" .scss file (eg */index.scss) into a .css file with an accompanying .css.map file.

Re:Stepping Away from Sass by simplify on Thursday April 25, 2019 @10:14PM (#19754285)
CSS variables are actually superior to SASS variables because you can change them at runtime via JS.
Re:Stepping Away from Sass by kowdermeister on Friday April 26, 2019 @03:02AM (#19755384)
It does not. With Parcel for example it works out of the box and it even installs the dependencies automatically for you.

I still love SASS since it solves many existing problems at once like you mentioned.

Re:Stepping Away from Sass by baroffoos on Thursday April 25, 2019 @08:12PM (#19753732)
I just looked it up and css variables are available on all current version browsers and have been available since about 2016/2017
Re:Stepping Away from Sass by nkozyra on Thursday April 25, 2019 @08:19PM (#19753769)
90% of users, which is a bit low for a lot of organizations.

They also aren't a full sass/less replacement, just one aspect

Re:Stepping Away from Sass by mo1ok on Friday April 26, 2019 @07:32AM (#19756381)
in isolation, no, but the problem I've seen is that literal dozens of preprocessing steps for a javascript project, and these add significant cost over time.

In a corporate environment, too, you need to proxy many of these, and set an environmental variable in the shell for SASS to install properly. Over time, this adds significant cost, pain, and stress to the install process.