<p>Did you see how the width of Go code is small ? I mean the indentation is often less than other languages.
For example, a method of a struct start on the left when in other language it start at one indentation. The handle of error doesn't need an indentation like with try/except.
It make it easier to read, like column of a newspaper, and let place for tagbar or explorer on the side. I wonder if it was a decision of the authors or just a side effect of simplicity ?</p>
<hr/>**评论:**<br/><br/>dilap: <pre><p>deliberate i'm sure. i love not having instance fns be indented a level, and also that you can put them anywhere you want -- no forced grouping into a single file is great.</p></pre>sseth: <pre><p><a href="https://www.youtube.com/watch?v=5kj5ApnhPAE">dear god, make it stop</a></p></pre>swimmer91: <pre><p>I think it's because Go was designed in part to encourage good style. I can't be bothered to look up any sources on this. Maybe it was just a nice little bonus from Go's simplicity and object composition.</p>
<p>If your code in other languages has many levels of indentation, you may be able to clean it up a bit (probably by using helper methods with simpler functions). This would give you some of the readability and simplicity you're seeing in your Go code.</p>
<p>This is all just guesswork on my part though.</p></pre>TheMerovius: <pre><p>One of the main reasons is the convention of short (mostly one-letter) identifiers (e.g. variable names), I think. It improves readability by making the code narrower and dissecting expressions and statements easier, as counter intuitive as that sounds to Java or C++ programmers.</p></pre>geodel: <pre><p>Yeah compare to Java at least Go code is lot more vertical than horizontal.</p></pre>zackkitzmiller: <pre><p>I don't really understand why you're saying here. </p></pre>WellAdjustedOutlaw: <pre><p>Lots of curly-brace languages don't need to be indented like Python. But my real question is are you programming on a mobile device? How narrow is your screen that being limited to 80 chars (PEP8) is sensible?</p>
<p>Also, most languages have the notion of line continuation. So you could conceivably make lines almost as narrow as you like. This is just one of those nonsense things programmers love to compare for no real reason. <em>shrug</em></p></pre>eikenberry: <pre><p>Humans find long lines hard to read. Tons of research has been put into this and 2-3 inches is about optimal. 80 chars is actually probably to wide, depending on the font size.</p></pre>WellAdjustedOutlaw: <pre><p>...but we're developers. Humans find lots of stuff hard to do. :)</p></pre>guillermooo: <pre><p><a href="http://baymard.com/blog/line-length-readability">http://baymard.com/blog/line-length-readability</a></p></pre>XANi_: <pre><p>I like my code to be narrow enough to fit on half of full hd display, altho 80 is a bit too small</p></pre>WellAdjustedOutlaw: <pre><p>I feel pretty much the same. Or the entire width of a full HD display turned 90 degrees to portrait. Not huge, but certainly larger than 80.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传