How many idioms did I break.

agolangf · 2017-12-24 07:30:22 · 611 次点击    
这是一个分享于 2017-12-24 07:30:22 的资源,其中的信息可能已经有所发展或是发生改变。

https://github.com/project-empower/randomart-image

It's a first stab at anything Go. I'm from C++. Would like a kind hearted soul to tell me how horrible it is...constructively :stuck_out_tongue_winking_eye:

Edit: Thanks for the input! I applied corrections based on input, including gomalinter


评论:

jehaby:

You might want to take a look at https://github.com/alecthomas/gometalinter

Crazy__Eddie:

This is great! Thanks!

tclineks:

Looks pretty good but there are some things to improve:

  • snake case is not idiomatic for function names
  • you aren't checking https://godoc.org/bufio#Scanner.Err
  • the use of a channel for the scanner is IMO suspect
  • you're not returning a non-zero exit code on line 70
  • you're ignoring the possible error from png.Encode (errcheck linter should tell you this)
  • it looks like the code hasn't been run through gofmt/goimports (some whitespace oddities)
  • you have some commented out code in there
  • the output filename should be a parameter (and probably default to stdout -- https://godoc.org/github.com/campoy/tools/imgcat could be a fun addition!)

that's a mix of idiom, error handling, tooling, and style nits -- I hope helpful and gently enough delivered! Welcome to go!

Crazy__Eddie:

the use of a channel for the scanner is IMO suspect

Yeah, that was not necessary. I was playing with the idea of "reactive" and my little bit of knowledge there is "functional reactive programming". Channels seemed like Go's react like crap. It's definitely overkill.

Thanks for the feedback!

0xjnml:

Quite good for a first stab. Please use gofmt before committing.

:

[deleted]

Crazy__Eddie:

Ooh. Forgot about that thing. I saw it and meant to use it. Thanks!


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

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