SASS 是否有像 C 预处理器那样的陷阱?
SASS,第一印象似乎是一个C-预处理器风格的工具,用于各种生产 CSS 附带的代码味道(如大量复制和粘贴)。
我将 SASS 解释为 C 的预处理器,这提出了一个问题。 C 预处理器有一些非常好的用途:也许定义常量,或者包含头文件。但也有一些东西“被认为是有害的”,特别是使用预处理器作为完成函数工作的工具,同时避免使用函数的开销。预处理器占有重要地位,但如果您可以选择通过预处理器宏实现某些内容还是将其实现为函数,那么您很可能应该使用函数,而不是预处理器。
使用 SASS 是否有类似的问题?
SASS, on first impression, seems to be a C-preprocessor-style tool for various code smells (like lots of copying and pasting) that come with production CSS.
I was explaining SASS as being like C's preprocessor, and that raised a question. The C preprocessor has some very good uses: defining constants, perhaps, or including header files. But there are also certain things that are "considered harmful", in particular using the preprocessor as a tool to do the work of a function whilst sidestepping the overhead of using a function. The preprocessor has an important place, but if you have a choice between implementing something via preprocessor macros and implementing it as a function, chances are you should be using a function, not the preprocessor.
Are there any gotchas like that for using SASS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 SASS(实际上是任何此类工具)提供了与基本 CSS 正交的功能,我认为与 C 预处理器相比,危险要少得多。
例如,可以使 C 宏看起来与 C 函数完全相同。您无法在源代码中区分它们之间的区别,但它们的语义非常不同。在 SASS 中,情况并非如此,因为变量、混合等具有明显不是 CSS 的特殊语法。
Since SASS (and indeed any such tool) provides functionality that is orthogonal to that of basic CSS I think the dangers are much reduced in comparison to the C pre-processor.
For example a C macro can be made to look exactly like a C function. You can't tell the difference between them in the source code but their semantics are very different. In SASS this is not the case because variables, mixins etc. have special syntax that is clearly not CSS.