运行时的Golang实验

huangapple go评论82阅读模式
英文:

golang experimentation at runtime

问题

通常在编码时,我喜欢查看代码库中特定区域的工作方式或某些表达式的结果。

大多数其他编程语言都提供了在运行时评估新的自定义表达式的工具。目前,Golang似乎还没有提供这样的工具,或者至少我使用的工具(如sublime、goclipse)没有提供。

目前,我通过使用Println或重新创建一个小的测试环境来解决这个问题,该环境只设置了我需要运行一些即时表达式所需的内容,但我认为一定有更好的方法...

我可以使用类似play.golang.org的工具,但通常我有很多依赖项,或者需要大量复制和粘贴才能使我的简单试错代码正常工作。

英文:

Often when I'm coding I like to see how things work or what certain expressions yield at a specific area in my code base.

Most other languages provide tools to evaluate new custom expressions at runtime. Golang doesn't seem to provide this yet, or at least with the tools I've used (sublime, goclipse).

Currently I'm solving this by using Println or recreating a small test environment that sets up just what I need to run some on the fly expressions, but I'm figuring there must be a better way...

I could use something like play.golang.org, but often I have a lot of dependencies or it would require a lot of copy and pasting to make my simple trial-and-error code work.

答案1

得分: 1

你已经尝试过 https://github.com/motemen/gore 项目了吗?

英文:

Have you already tried https://github.com/motemen/gore project?

答案2

得分: 1

很可能你正在寻找一个调试器(用于插入断点,在断点处停止并开始操作变量)。

其中一个调试器是 https://github.com/mailgun/godebug,你可以在这篇博文中了解更多如何使用它。

英文:

Most probably you are looking for a debugger (to insert breakpoints, stop at them and start playing with variables there).

One of the debuggers is https://github.com/mailgun/godebug and you can read more how to use it in this blogpost.

答案3

得分: 0

Sublime和VIM现在支持Go插件,但使用方法有点晦涩。

JetBrains的IdeaJ社区版IDE与Go调试插件非常好用。话虽如此,在刚开始时,使用go runfmt.Println进行快速调试的价值不可低估。

英文:

Sublime and VIM now support the go plugin but the usage is a little esoteric.

The JetBrains IdeaJ community IDE with the go debug plugin has worked really, really well for me. That said, starting out, the value of a quick go run with fmt.Println can't be overstated.

huangapple
  • 本文由 发表于 2015年11月24日 05:41:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/33881238.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定