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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Go’s hidden pragmas

221 点作者 spacey超过 7 年前

9 条评论

pcwalton超过 7 年前
For once, I&#x27;m gonna be the one sticking up for Go here. :) Pragmas or annotations are kind of unavoidable, and I don&#x27;t think that it was a mistake to include them. I wouldn&#x27;t have used comment syntax, but whatever; that&#x27;s a minor quibble.<p>Actually, I wish Rust had done one thing that Go did: namespacing the pragmas. That would have been a more future-proof thing to do, because macros effectively give us user-definable pragmas, and once you have user-definable pragmas you have name collision problems. Kudos to the Go team for being forward-thinking there. I suspect we&#x27;ll have to figure out some kind of solution here, but it won&#x27;t be as pleasant as if we had just used namespaces in the first place.
评论 #16100243 未加载
评论 #16098451 未加载
评论 #16099583 未加载
bla2超过 7 年前
Poor Rob Pike. He always tries to make things simple, and over they time entropy always does its thing. You can hear his frustration in his cited comment.
评论 #16098107 未加载
评论 #16097049 未加载
评论 #16097157 未加载
评论 #16097659 未加载
tidwall超过 7 年前
The page is missing the best one of them all &#x2F;&#x2F;go:linkname, which allows for linking in private functions from other packages. Including the Go runtime. For example: <a href="https:&#x2F;&#x2F;github.com&#x2F;tidwall&#x2F;algo&#x2F;blob&#x2F;master&#x2F;algo.go" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tidwall&#x2F;algo&#x2F;blob&#x2F;master&#x2F;algo.go</a>
评论 #16099832 未加载
jonathanstrange超过 7 年前
Pragmas are always a bad idea. The Ada community has learned that the hard way. Whatever the pragma does, it should be part of the language standard and never be implementation-dependent.<p>It&#x27;s time that language designers include <i>language pragmatics</i> in the core language. That includes for example big O information about data structures, packing of structures, alignment properties, memory access information, etc. Currently, in most if not all languages this information is spread all over levels, from nonstandardized compiler flags over pragmas up to the core language. It&#x27;s a huge mess.
评论 #16098925 未加载
评论 #16098556 未加载
评论 #16099124 未加载
yokohummer7超过 7 年前
I hated the idea of using comments as directives when Go 1.4 introduced &#x2F;&#x2F;go:generate. But, holy, they were there from the beginning?<p>They bring back my painful memories of the old days when I had to use conditional comments to support IE6...
评论 #16098013 未加载
评论 #16098172 未加载
评论 #16098021 未加载
评论 #16098163 未加载
tapirl超过 7 年前
The pragmas in Go are not intended to be used in general user code. They should be only used in Go runtime implementation and standard packages. The pragmas in Go are just some hints for compilers. Compilers will ignore many of the pragmas used in custom user code.
评论 #16098060 未加载
评论 #16098520 未加载
nerdponx超过 7 年前
This seems like one arugment to be made in favor of giving the language first-class access to the compiler, à la Lisp.
评论 #16098023 未加载
评论 #16098328 未加载
saagarjha超过 7 年前
&gt; Given the race detector has no known false positives, there should be very little reason to exclude a function from its scope.<p>Performance, maybe?
评论 #16097150 未加载
cjslep超过 7 年前
Go&#x27;s &quot;pragmas&quot; are already exposed to the developer via go generate [0].<p>Edit: Granted, this is not a directive for the compiler though.<p>[0] <a href="https:&#x2F;&#x2F;blog.golang.org&#x2F;generate" rel="nofollow">https:&#x2F;&#x2F;blog.golang.org&#x2F;generate</a>