Please Give Feedback on My First Project

agolangf · · 605 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m starting a new development position after the first of the year, and the stack I&#39;ll be using consists of Go and MongoDB. I&#39;m coming from Ruby, so I&#39;m fairly new, and grasping some of the differences (coming from an object-oriented language) has been challenging but fun.</p> <p>I&#39;ve had experience making GroupMe bots before (<a href="https://web.groupme.com">groupme.com</a>), so I wanted to try my hand at making a library in Go that would easily allow one to make &#34;handlers&#34; for bot commands posted to GroupMe groups. I&#39;d love your critique on literally anything about the project. The project can be found at <a href="https://github.com/sha1sum/golang_groupme_bot">https://github.com/sha1sum/golang_groupme_bot</a></p> <p>You can take a look at the linked samples repo (<a href="https://github.com/sha1sum/distinguished_taste_society_bots">sha1sum/distinguished_taste_society_bots</a>) for examples on usage. The googlenews package is the simplest working bot sample out of the two in the repo. In case you see my [horrid] MongoDB stuff in the adultpoints package, just know that since I made it I&#39;ve learned quite a bit more about Mongo and have yet to rewrite the Mongo stuff.</p> <p>Thanks for your time :)</p> <hr/>**评论:**<br/><br/>Midnightblues: <pre><p>This isn&#39;t so much a Go thing as it is a programming thing, but you comment far too much at times. For things like...</p> <pre><code>// Attachments is a list of attachments added on to the GroupMe post Attachments []Attachment `json:&#34;attachments&#34;` </code></pre> <p>Is the comment really necessary? It can be pretty easily inferred, as you&#39;ve named your variables very well, and the additional comment is just unneeded extra noise. Compare something like this to your block in listener.go...</p> <pre><code>if strings.Contains(strings.ToLower(post.Text), strings.ToLower(t)) { term = strings.Replace(strings.ToLower(post.Text), &#34; &#34;+t+&#34; &#34;, &#34;&#34;, -1) term = strings.Replace(term, t+&#34; &#34;, &#34;&#34;, -1) term = strings.Replace(term, &#34; &#34;+t, &#34;&#34;, -1) go handle(strings.Trim(term, &#34; &#34;), c, post) h := &amp;c v := reflect.ValueOf(h.Handler).Elem() v.Set(reflect.Zero(v.Type())) } </code></pre> <p>A block like this, to someone who&#39;s not familiar with the problem domain, is extremely hard to decipher, and some well placed comments could really help out, or better yet refactoring the code into another function. I&#39;d try to go through and determine which comments are <em>really</em> necessary. </p> <p>The Go specific stuff (i.e refactoring the Bot into a struct and allowing for multiple to be used at a time) I think has already been covered well. Hope you&#39;re enjoying Go! :D </p></pre>RalphCorderoy: <pre><p>For <code>go doc</code> the OP is correct in commenting things like Attachments as it starts with a capital. That said, the stdlib gives a good guide to the terse style, and that they&#39;re sentences and should end with a full stop. &#34;triggers will be lowercased when matching so are case insensitive&#34; is too verbose, for example. The user just needs to know that &#34;Triggers is a +case-insensitive+ list of terms...&#34;.</p> <p>The comments use a mix of styles: &#34;will take a&#34; v. &#34;takes a&#34;. handle() has a comment describing search, not handle.</p> <p>It&#39;s unusual to see strings added together for Print*(). Instead, pick a more suitable function, e.g. this could use Print, with the \n being explicit.</p> <pre><code>fmt.Println(&#34;Handling term \&#34;&#34; + term + &#34;\&#34;.&#34;) </code></pre> <p>Does PostMessage have to convert to string? Could bytes.NewReader be used instead?</p></pre>Fwippy: <pre><p>Just on a quick read-through of <code>bot.go</code>, it seems a little weird to have BotID as a package variable. I would expect either a <code>bot.New()</code> function that returns something with a <code>PostMessage</code> method (though I might just rename to <code>Send()</code>), or for postmessage to take BotID as a parameter. That way, code using the library could act as more than one bot if they wanted to.</p> <p>Haven&#39;t looked at the listener yet.</p></pre>anthonyatkinson: <pre><p>Excellent point. I originally had the handlers from the distinguished_taste_society_bots repo built into the main repo and was serving the bots on Heroku, then decided to make the project more generic so others could build their own bots using the library, and the BotID was one of the leftovers from that. I&#39;ve just pushed up some changes based on your recommendation. Thanks!</p></pre>

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

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