TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Project for bringing macros to Scala

39 点作者 mike_esspe超过 13 年前

4 条评论

nwjsmith超过 13 年前
I'm not that familiar with Scala, but the examples aren't very convincing. Why must `printf` be defined as a macro? Why not a plain old function? What are the benefits to the second example?<p>The other thing that bothers me is the empty 'Use cases' page. Scala macros might be a solution to a problem nobody has. A problem that people _do_ have is the breadth of Scala language, and macros will add to the conceptual dog pile.
评论 #3215845 未加载
评论 #3216202 未加载
评论 #3215605 未加载
评论 #3216081 未加载
评论 #3222707 未加载
wbhart超过 13 年前
This is a significant breakthrough. Scala is once again showing the way forward. Instead of having ad hoc macros (which everyone knows are bad), Scala macros don't change the syntax of the language. Thus they are no more difficult to come to terms with than an API for a well-written library. In this sense ordinary API's are going to start looking like crippled Scala.<p>The other nice thing about these is that you don't need to lose type safety to use macros. That's really where the innovation is here.<p>I don't yet fully understand how this all works at the type-theoretic level. I'm imagining that expressions (as opposed to the values they represent) are thought of as belonging to higher kinded types. The macros then reject expression which aren't of the right kind.<p>I have to say, I am absolutely flawed by the comments so far about this. I think this is going to have an absolutely pivotal effect on future programming languages. This is how macros should always have been. I don't know of any other language which does this. It's a totally new area in language theory to explore.
评论 #3217105 未加载
bborud超过 13 年前
Macros are bad, but in order to understand why they are bad it helps if you are not a language nut. Most language nuts have one shortcoming: they do not understand their consumer.<p>If you want proof you only need to look at the error messages generated by most compilers. They probably make perfect sense to someone who is trying to debug the compiler, but they usually leave the consumer, ie the programmer using the compiler, somewhat confused.<p>Macros are bad because they redefine the language. The point of having a language in the first place is to make it easy to communicate. This is only possible if the semantics are understood. If you do good language design the semantics are clear. If you do sloppy language design people have to look things up all the time.<p>Now, if everyone gets to extend the language in arbitrary ways, you have suddenly unloaded a massive burden onto your programmers. It is no longer enough to say that you know language X. In order to understand the software you have to understand the specific dialects (plural) of language X -- because for a non-trivial project with lots of people extending the language in various ways, you will end up with multiple dialects.<p>When you can no longer bring up a piece of code in your editor and see what it does without having to reference dozens of other files that may modify the semantics of the language (sometimes in non-obvious ways), you are going to be a lot less productive.<p>I think Joshua Bloch was absolutely right when he said that one of the really good decisions of Java was to NOT have macros. He made some of the same points I made above.<p>Now I understand that people think macros can lead to elegant code, but that code <i>only</i> has value if other people can understand it. If you need to re-learn the language, in big or small ways, to understand it, its value is very limited.<p>And again: what excites language nuts and what has real value is not always the same thing.
评论 #3216893 未加载
评论 #3216628 未加载
评论 #3216401 未加载
HnNoPassMailer超过 13 年前
I am an average programmer, I know C#, Java and dart. Can anyone explain macro's? Wikipedia/internet is not very helpfull because of ambiguity. Thanks!
评论 #3215726 未加载
评论 #3216664 未加载
评论 #3215734 未加载
评论 #3216269 未加载
评论 #3222755 未加载
评论 #3216086 未加载