Is there something like this fo Go beginners?

agolangf · · 359 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>for every C/C++ Beginner</p> <p>Step 1 - add *</p> <p>Step 2 - add &amp;</p> <p>Step 3 - switch place for &amp; and *</p> <p>Step 4 - Add in a second *</p> <p>Step 5 - look up pointers online</p> <p>Step 6 - delete all the pointers</p> <p>Step 7 - go look at that code that worked right once</p> <p>Step 8 - look up videos to explain pointers</p> <p>Step 9 - delete all the *&#39;s and &amp;&#39;s</p> <p>Step 10 - add *</p> <p>original post link: <a href="https://www.reddit.com/r/ProgrammerHumor/comments/7k9ft4/every_cc_beginner/" rel="nofollow">https://www.reddit.com/r/ProgrammerHumor/comments/7k9ft4/every_cc_beginner/</a></p> <hr/>**评论:**<br/><br/>Sythe2o0: <pre><p>The joke doesn&#39;t really work as well in my experience, as focus on good error messages has improved since C/C++.</p></pre>twizmwazin: <pre><p>I disliked the <a href="/r/ProgrammerHumor" rel="nofollow">r/ProgrammerHumor</a> post. Honestly, understanding pointers only takes a couple of minutes, and anyone who is a career programmer should be able to explain them, along with other memory-management basics easily.</p> <p>With that said, newer languages like Go tend to look at what struggles programmers have had with past languages, and try to remedy those issues.</p></pre>jerf: <pre><p>Language communities form their own terminology, so Go has &#34;pointers&#34;, because that&#39;s what the Go standard says. I don&#39;t fight community&#39;s terminology because that&#39;s an uphill battle.</p> <p>But as I know quite a few languages, I also have a sort of generalized terminology I use. Nobody else uses it, because the vast majority of programmers seem to find one community they like and then mistake their chosen community&#39;s vocabulary as the One True Computer Science Vocabulary. But in my personal terminology that I use in my head, the difference between a Pointer and a Reference is that you can do arithmetic on a pointer. That is the key attribute that makes them so hard to understand, and such a security and quality catastrophe.</p> <p>In my terminology, what Go has are only <em>references</em>. You can pass a &#34;reference&#34; to a function, but it isn&#39;t allowed (modulo <code>unsafe</code>) to then start rooting around in memory with that pointer; it can only get at the referenced object. This is much easier to deal with. You&#39;ll also find that because of this, it is fairly rare in Go to have a double-pointer, since in C/C++ the double pointer is usually so a function can perform pointer arithmetic on the referenced pointer, and I&#39;ve never seen or written a triple pointer in Go, whereas you will definitely encounter them in C. (C++, it depends on how &#34;idiomatic&#34; it is; idiomatic modern C++ has little use for a triple pointer (at least, one that is user-visible as a literal <code>***</code> in the type system), but older code may have it, and you may always have some crazy guy doing crazy things in the system &#34;because it&#39;s faster than STL&#34; or something.)</p> <p>Consequently, no, there really isn&#39;t an equivalent in Go, because Go pointers lack the essential elements of complexity that confuse people in C/C++.</p> <p>(You don&#39;t have to use my personal terminology, or even think it&#39;s got a hold of the correct/best distinction... but you <em>should</em> understand that &#34;C pointers&#34; and &#34;Go pointers&#34; are very different beasts.)</p></pre>vorg: <pre><p>Go pointer syntax is more confusing than in C/C++ because of Go&#39;s decision to adopt &#34;C statements but Pascal declarations&#34; without changing the unary symbols used. When we read</p> <pre><code>*A //pointer to type A *a //that pointed to by variable a &amp;a //pointer to variable a </code></pre> <p>whenever we see a unary <code>*</code>, we must ask ourselves whether what follows is a variable or type. If it&#39;s a type, <code>*</code> means &#34;pointer to&#34;, otherwise it means the opposite, i.e. &#34;that pointed to by&#34;.</p> <p>Perhaps Go should have used <code>&amp;</code> instead of <code>*</code> in type declarations, i.e.</p> <pre><code>&amp;A //pointer to type A </code></pre> <p>to be more consistent and thus readable for newcomers. But it&#39;s too late to change it now.</p></pre>

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

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