TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Go’s hidden pragmas

221 pointsby spaceyover 7 years ago

9 comments

pcwaltonover 7 years ago
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 未加载
bla2over 7 years ago
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 未加载
tidwallover 7 years ago
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 未加载
jonathanstrangeover 7 years ago
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 未加载
yokohummer7over 7 years ago
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 未加载
tapirlover 7 years ago
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 未加载
nerdponxover 7 years ago
This seems like one arugment to be made in favor of giving the language first-class access to the compiler, à la Lisp.
评论 #16098023 未加载
评论 #16098328 未加载
saagarjhaover 7 years ago
&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 未加载
cjslepover 7 years ago
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>