各编程语言对「宏」的支持是怎样的?

“宏”的概念不解释了,问大家,有哪些编程语言支持“宏”,例如C,比较弱的宏支持,虽然可以通过扩展增加可用性,再如python、lisp,对宏的支持就很精巧。大家能否也评价一下其他语言中对宏的支持以及大家对宏的应用的看法。 在我的团队中尽量避免了宏的使用,一个是怕影响代码可读性,二是宏使顺手后很容易上瘾,虽然有可能会将自己的开发效率及bug数量降低,但项目中仍会担心人员变动带来的风险(先不考虑这是否对团队人员有…
关注者
89
被浏览
5,669
举一个目前还不支持宏的例子。

Swift 3 不支持宏。理由很有趣:

Hygienic Macros and Compile-Time Evaluation: A first-class macro system, or support for compile-time code execution in general, is something we may consider in future releases. We don't want the existence of a macro system to be a workaround that reduces the incentive for making the core language great.

From: Swift Evolution

翻译一下,大意就是:我们不希望用宏系统来解决语言本身缺陷。

在 Swift Mailing List 里面 Core Team 对宏的评价:

A macro system isn't a "slight" compromise. It's a major feature whose existence would forever change the way libraries are written in Swift. It's not a feature to be taken lightly. The C preprocessor is the single worst part of the C language from a tooling perspective, and even very well-designed macro systems (e.g., Scala's macro system is fairly interesting) have taken numerous iterations.

From: Swift Evolution Mailing List

宏本身是很有用的功能,但是更重要的是程序员会怎样去使用宏。