<p>I recently gave Go a try. I primarily used PHP before for writing not too complex API for my front-end apps. Since I started using Go for some minor dev things I find it a bit awkward because I'm very used to JS variables and scope rules etc. Oddly this never bothered me with PHP.
Anyone else having a hard time?</p>
<hr/>**评论:**<br/><br/>brokedown: <pre><p>Go brings a level of structure that is completely optional in php or JavaScript. It slightly raises the bar of effort for trivial size code, but really pays off as soon as the program size gets above a page. Most of what you need to do is considered good practice regardless of language, but ignored by tinkerers and languages that appeal to them.</p></pre>igroz777: <pre><p>I see. I think I will get used to it with more practice then. Thing that trips me up most is pointers. Haven't used C extensively before or any other language that gives access to pointers so half the time I spend several minutes wondering if I should use a pointer, and why</p></pre>RalphCorderoy: <pre><p>You are using <code>:=</code> happily? If you've a particular example of the quandary over whether to use a pointer, ask that.</p></pre>igroz777: <pre><p>My extent of pointer comprehension is knowing that a function that receives a pointer as argument will modify the object instead of creating a copy if the object to work with. Is there anything else I should know?</p></pre>RalphCorderoy: <pre><p>No, that's the essence, but it sounds like you are uncertain when that's a good thing, e.g. for efficiency, and when it's better to stick with the more simple non-pointer parameter.</p></pre>igroz777: <pre><p>Yes. Assuming a have a function that adds all the elements of an array and returns a long string. If my array has billions of values it would be better to use a pointer instead of creating a copy of such a big object. Is that what u mean by efficiency or are there other cases?</p></pre>jocull: <pre><p>Have you ever tried TypeScript? It's my happy medium - the safety of types when you want them with the flexibility of JavaScript. Love it!</p></pre>igroz777: <pre><p>I dont find Go hard to work with because of loose vs strict typing.</p></pre>bmurphy1976: <pre><p>Just keep at it. I switch between C#, Go, and Python daily. Practice makes perfect.</p></pre>mwholt: <pre><p>Yes, I still catch myself writing <code>fmt.Println(...)</code> in JS and <code>console.log()</code> in Go...</p></pre>cmgriffing: <pre><p>With a couple wrappers in the respective languages, you could use them that way :P</p></pre>sh41: <pre><p>Not very difficult, but definitely awkward. But I'm much more comfortable with Go than JS.</p>
<p>Have you tried using Go itself in the browser, so there's no need to switch back and forth? I'm curious how you'd find that compared to JS in the browser.</p></pre>Pagedpuddle65: <pre><p>What makes this possible?</p></pre>cmgriffing: <pre><p>I'm guessing they are referring to using this: <a href="https://github.com/gopherjs/gopherjs" rel="nofollow">https://github.com/gopherjs/gopherjs</a></p></pre>junajted: <pre><p>I had a hard time with Go maybe fist couple of months. Go was my reintoduction to statically typed languages (i started with java in school, than moved to c, php, python, js). I think it didnt bother me stuff like you a describing but syntax. Once I conquered syntax, I abandoned nodejs as my fav backend language (platform, if you are pedantic) with delight. Also discovered that I could write small program (400 LOC) correctly in first try.</p></pre>mcvoid1: <pre><p>I write ES6, where let, const, etc give block scoping. The new idiomatic JS is converging toward more traditional languages. Sometimes I with Javascript has multiple return values (though object literals are fine) or wish Go's type system made some functional things like map/reduce or monads a little less awkward. Also, promises don't help mitigate callback hell as well as channels do.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传