<p>Hi Gophers, I've been wondering what makes code syntax in one programming language more readable / fun to write than others.</p>
<p>I wrote two ToDo apps in pseudo-code here: <a href="https://gist.github.com/everdev/275c8562e356b7f30c52" rel="nofollow">https://gist.github.com/everdev/275c8562e356b7f30c52</a></p>
<p>Would love your thoughts on which one feels more readable and would be more enjoyable to read/write and why. Thanks!</p>
<hr/>**评论:**<br/><br/>nstratos: <pre><blockquote>
<p>Hi Gophers, I've been wondering what makes code syntax in one programming language more readable / fun to write than others.</p>
</blockquote>
<p>Not directly answering your question but <a href="https://www.youtube.com/watch?v=5kj5ApnhPAE" rel="nofollow">this</a> is a very interesting talk from Rob Pike that explains what lead to the creation of Go, contrasting the unread-ability and verbosity of languages like C++ and Java. </p></pre>everdev: <pre><p>Cool, thanks! Which version do you prefer personally?</p></pre>thockin: <pre><p>Am I the only one that loathes "go watch this video" references? I don't have an hour to watch people talk about stuff. Where's a transcript? Where are the slides?</p></pre>nstratos: <pre><blockquote>
<p>I don't have an hour to watch people talk about stuff. </p>
</blockquote>
<p>That's exactly the reason why I linked a 10-ish minutes talk instead.</p></pre>thockin: <pre><p>I don't have any minutes to watch a video, period. I can read a transcript or slides while in the car (wife driving) or in the crapper or while my kids are playing. Videos are a very poor way to publish one's thoughts on a subject.</p></pre>dericofilho: <pre><p>Go talks from Go's team usually have their slides available at talks.golang.org </p></pre>neoasterisk: <pre><blockquote>
<p>Would love your thoughts on which one feels more readable and would be more enjoyable to read/write and why. </p>
</blockquote>
<p>I think people will have different opinions depending on their background. Someone that comes from a C family background might prefer the second. People who come from a dynamic language background, especially Python, might prefer the first.</p>
<p>I believe that while the first one might be indeed more enjoyable to read, when you have to consider the syntax of a programming language and also writing and editing the code, then there are practical reasons why curly brackets are superior to using indentation. Rob Pike seems to <a href="https://www.youtube.com/watch?v=VoS7DsT1rdM&t=21m9s" rel="nofollow">agree</a> on this.</p>
<p>P.S. Here is the <a href="https://github.com/kickstarter/confreaks-translations/blob/master/2014-gophercon/GopherCon%202014%20Opening%20Keynote%20by%20Rob%20Pike.srt" rel="nofollow">transcript</a> for people that don't have enough time to watch (but apparently have enough time to complain).</p></pre>everdev: <pre><p>Awesome, thanks!</p></pre>semi-: <pre><p>I would say #2. The brackets make it so your indentation is not syntatically relevant, which is good as indentation is formatting and formatting should not be syntax, formatting should be something you can freely change in your editor to suit your personal preference or editing environment. Someone on an 80x25 terminal might want to set their ts=2, someone editing in a web based IDE might want to have hard tabs represented by a pretty indent.png or whatever they want..it shouldn't change the functionality of the code.</p>
<p>You can also freely re-order the bracketed code without having to manually fix the indentation. For that matter, you could just not indent it at all and rely on <del>gofmt</del> pseudocodefmt to indent it all for you.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传