Code Review

polaris · · 359 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hello all, I have been slowly taking some time playing with GO to try to pick it up and have down a couple small programs to get me started. If I am looking for code review is that something I could post here and get feedback? Any critique is honestly great, no matter how small or big. I come from a background of mostly strict web development so its been nice to try my hand at some newer type of exercises while picking up GO.</p> <p>I wrote one program for just working with user input: <a href="https://github.com/justinrsmith/Decision-Maker" rel="nofollow">https://github.com/justinrsmith/Decision-Maker</a></p> <p>Then I wrote a small tcp client/server since I&#39;ve never done anything like that: <a href="https://github.com/justinrsmith/tcp_go" rel="nofollow">https://github.com/justinrsmith/tcp_go</a></p> <p>Thank you in advance!</p> <hr/>**评论:**<br/><br/>peterbourgon: <pre><p>I&#39;ve just looked at the TCP client/server and gotta say, this is great first code. You&#39;re doing pretty much everything right, and good job for reaching to package bufio to handle the reads and writes on the connection. </p> <p>A few small things</p> <ul> <li>Constants don&#39;t get the ALLCAPS treatment in Go; they&#39;d just be <code>host</code> and <code>port</code></li> <li>Better to avoid globals and have those defined in <code>func main</code>, or, better yet, taken as flags. </li> <li>In the <code>if err != nil { log.Fatal }</code> block, better drop the <code>else</code> clause</li> <li>Can you find a way to read in handleConnection that doesn&#39;t require allocating a fixed buffer?</li> </ul></pre>driusan: <pre><p>On the note of Fatal, you probably also don&#39;t want to call it from the server&#39;s main event loop since it has a side-effect of quitting the program.</p></pre>lancevo3: <pre><p>Thank you for the feedback! Your last point is something I actually was wondering about myself? Would it make use <code>Scanner</code> to read the input? I&#39;m still working on understand the difference between <code>Reader</code> and <code>Scanner</code> and when to use what.</p> <p>Also, for your second point (taken as flags), do you mean passed in via the command line when running the program? </p> <p>Thanks!</p></pre>

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

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