SASS 是否有像 C 预处理器那样的陷阱?

发布于 2024-11-05 16:43:25 字数 355 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寻找一个思念的角度 2024-11-12 16:43:25

由于 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文