What if go had something like Java's Annotation Processor for code generation?

polaris · · 491 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I think go generate is awesome, specially when combined of other toolkit goodnesses, like build tags, awesome community tools and external build tools. </p> <p>But it has its drawbacks, and it imposes some workflow restrictions that make it not always a desirable solution. </p> <p>The main problem being it doesn&#39;t &#34;run automatically&#34; when you go get packages, so you have to do this, and that, and that. </p> <p>What if go had something like go generate that runs automagically in every step of the process? We could use go to &#34;deal with&#34; our go code, and then we could use go to generate go code! Go is fast, it would be fast. Go is awesome, it would be awesome. I think it could even help with generics, since it would be basically free to generate typed code. We could have real ORMs! </p> <p>I mean, look at <a href="https://github.com/google/auto/tree/master/value" rel="nofollow">AutoValue</a>, isn&#39;t that a beautiful solution to some stupid problems? Why can&#39;t we have that? </p> <hr/>**评论:**<br/><br/>: <pre><p>[deleted]</p></pre>comrade_donkey: <pre><blockquote> <p>** I would love to provide some citation on this, but I&#39;ll have to go and find it.</p> </blockquote> <p><a href="https://blog.golang.org/generate" rel="nofollow">blog post</a></p> <blockquote> <p>Just keep in mind that it is for package authors, not clients, if only for the reason that the program it invokes might not be available on the target machine. Also, if the containing package is intended for import by go get, once the file is generated (and tested!) it must be checked into the source code repository to be available to clients.</p> </blockquote></pre>thockin: <pre><p>The hoops that kubernetes has to jump through are incredibly unfortunate, but the truth is that we have to codegen a bunch for performance reasons. The generated code is our #1 cause of merge conflicts and rebases across contributors. Moving to just-in-time codegen is what we want, but we t requires horrible, ridiculous &#39;makefile&#39; hacks.</p> <p>Something better would be wonderful.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

491 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传