Just switched from LESS and found that in SASS all variables in global. And so to define special variable for particular block I need to write something like $words-that-describe-particular-block-padding: 10px;
.
In all reviews authors rendered SASS as more advanced than LESS because of its feature-richness, but actually lack of such simple thing as namespacing kills all experience with it.
Why that design decision was made?
Am I wrong and global-only variables are better by the reason that I am missing?
upd:
SASS:
$var: 1px;
#id1 {
$var: 2px;
width: $var;
}
#id2 {
width: $var;
}
LESS:
@var: 1px;
#id1 {
@var: 2px;
width: @var;
}
#id2 {
width: @var;
}
Try the examples with this online compilers:
That's not exactly true. If you run the following code:
.header {
$color: #000;
background: $color;
}
.footer {
background: $color;
}
You will get
Sass Error: Undefined variable: "$color".
So, the color variable is not global at all. It is available only in the context of its definition.
However, SASS or LESS has a lot of limitations. If you are not happy with the things which they offer I'll suggest to check this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With