Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Writing styles in javascript is a very natural consequence of web applications becoming more and more dynamic. It is unfortunate that they are not more mainstream.

We have pushed CSS pre-processors to the extent that they now have variables, loops, modules, interpolation, conditions etc. which have always been present in javascript.

It makes a lot more sense to just fully embrace all these features from standard javascript instead of building entire ecosystems of css pre-processors with superficial syntactical differences.



> Writing styles in javascript is a very natural consequence of web applications becoming more and more dynamic. It is unfortunate that they are not more mainstream.

It's ironic that graphic tool kits for desktop or mobile apps are adopting CSS and declarative approach, when the front-end is desperately pushing for javascript everywhere.


It's a natural consequence of the former being typically written by more experienced developers than the latter.


Well it is true that CSS preprocessers are getting all these JavaScript like features they are still compiled down to plain old CSS. The fact that users can disable js and ruin most if not all of your styles is just a little off putting to me. Seems like a cool idea though and I agree with most your points but I think pre processers fill a need for people who want just normal CSS on their sites.


Agreed — I've always admired how extensive Sass/LESS have become, but I do think having advanced logic inside your stylesheets makes no sense. Not necessarily because of separation of concerns, but because Javascript does a much better job at this (and already has the remaining logic of the application), so there's really no need to reinvent a slightly less functional version of the wheel here.

That said, the main advantage for writing CSS in JS is being able to rewrite styles in runtime, where changing values in Javascript automatically reflects in style changes. The most direct way to do this today is setting variables as data-attributes in a DOM node and targeting specific true/false values for that attribute in your stylesheet.

Native CSS Variables will make life much easier in this respect, but it will still take a couple of years before all major browsers implement it.


Like you, I see this like a natural evolution. Instead of adding stuff to CSS to become it more like a true programming language, we adapt a programming language to do the job of CSS. The only problem that i see to this particular situation, is that I don't see a way to generate static CSS files like does Less/Sass . This like calling less.js on production...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: