Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【讨论】代码生成器 #409

Closed
KippaZou opened this issue Jun 15, 2019 · 4 comments
Closed

【讨论】代码生成器 #409

KippaZou opened this issue Jun 15, 2019 · 4 comments
Labels
日常问答 Go 夜读问答:遇到的问题,疑问。

Comments

@KippaZou
Copy link
Contributor

KippaZou commented Jun 15, 2019

代码生成器

  • 用于日常生成各种基础架构和业务逻辑框架代码,减少 copy and change;
  • 抽象出通用的代码逻辑以便自动化生成代码,如查询缓存、rpc调用、数据库查询、日志打点等,为 coding 减负。

参考项目

讨论

  • 欢迎大家推荐更多代码生成工具,讨论更多适用自动化生成代码的场景。
@chaoshong
Copy link

代码生成器有规范的设计原则么?
近期是否会有代码生成器的分享?
谢谢

@KippaZou
Copy link
Contributor Author

代码生成器有规范的设计原则么?
近期是否会有代码生成器的分享?
谢谢

为什么需要/有代码生成器?

  • Don't repeat yourself!

当我们在写重复的代码或者用重复逻辑的时候,就应该考虑能够用代码生成器来做这一件事;

设计原则?

  • 抽象出通用的代码逻辑 or 业务逻辑比生成器本身更重要。
  • 生成规则可扩展。

这一点能帮助我们在遇到新的重复逻辑 or 重复的代码结构时可以很容易将它加入生成器套餐中来。

  • 项目结构信息可配置。

如果代码生成器和项目结构耦合太多,可能不利于在其他项目中使用,有时候我们为了方便可能需要代码直接生成到项目的指定位置,那么这个信息应当是可配置的。

  • 尽可能少的手动调整和配置。

过多的手动调整和配置会带来额外的工作负担和学些成本。

近期是否会有代码生成器的分享?

  • 近期会有这方面的分享。

@yangwenmai yangwenmai pinned this issue Jun 17, 2019
@clearcodecn
Copy link

今天看到的,既然是谷歌开源的推荐一下

https://github.com/google/wire

@acynothia
Copy link

请教一个问题。用标准库 ast 获取到结构体类型的 Expr 之后有没有办法能够判断他是不是某个 Interface 的实现。比如,得到一个结构体的 Expr 之后我想知道他是不是一个 fmt.Stringer 类型。或者能不能用 reflect 根据 Expr 生成一个 reflect.Value 或 reflect.Type ?

@yangwenmai yangwenmai unpinned this issue Aug 12, 2019
@yangwenmai yangwenmai added 日常问答 Go 夜读问答:遇到的问题,疑问。 and removed discuss labels Sep 19, 2019
@changkun changkun added this to Backlog in Go 夜读分享计划 Mar 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
日常问答 Go 夜读问答:遇到的问题,疑问。
Projects
Development

No branches or pull requests

5 participants