I drank the Kool-Aid but nothing happened, or what am I missing with go?

blov · · 718 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Over the past two weeks I have been trying out go. My co-workers are of two extremes; either they think go is all hype and no substance or they think go is the second coming and non go programmers are inferior.</p> <p>I have attempted to remain neutral and make my own mind up. On paper I like what go is doing but in practice I have not enjoyed much of my time with go. Development feels like a non stop series of hurdles. I sound bitter and I am, I set out enthusiastic but I can&#39;t find the magic that everyone else claims to have.</p> <p>Starting out the go tour covers things well enough and I have no real issues with any of the conventions and style in go. By the end of it I liked what I was seeing. Anything beyond that is where the pain starts.</p> <p>I quickly found that practically anything I want to achieve no matter how primitive requires trawling github to find a package that does what I need. Concerns about when the author goes awol aside, <strong>if</strong> I am lucky there is a slither of documentation but more likely the &#34;documentation&#34; consists of a one liner shell command to install the package. </p> <p>But I try to keep an open mind, and install the package. If go-plus is behaving I awkwardly navigate through the methods and types in the package to try figure out how the hell it works. In atom this means littering my code with log.Print. There&#39;s liteide which is ugly as hell but it lets me step through things...except...when it doesnt....back to atom.</p> <p>Eventually I manage to get things working. The code is contrived but it works and lets face it there&#39;s no proper examples....git commit -m &#34;yolo&#34;</p> <p>Maybe I have had it too easy with c# and javascript, but wasn&#39;t go supposed to be simple and fast to develop with? For me its been really, really slow. </p> <p>I tried to say neutral compared to my co-workers, what am I missing?</p> <hr/>**评论:**<br/><br/>albatr0s: <pre><p>The magical thing about Go is that it has no magic.</p></pre>ergotayours: <pre><blockquote> <p>I quickly found that practically anything I want to achieve no matter how primitive requires trawling github to find a package that does what I need.</p> </blockquote> <p>I&#39;ve had the opposite experience; I&#39;ve found that everything I want to do is covered by the standard library or is too specific to be covered by any third-party package. What are the things you&#39;re trying to do, and what packages have you tried?</p> <blockquote> <p>Maybe I have had it too easy with c# and javascript, but wasn&#39;t go supposed to be simple and fast to develop with?</p> </blockquote> <p>In my experience, Go isn&#39;t necessarily faster to get a first working example, but it does make refactoring and adding features easier.</p> <blockquote> <p>I tried to say neutral compared to my co-workers, what am I missing?</p> </blockquote> <p>It might not be the language for you. There are definitely a lot of places where Go is awkward or obtuse, and it&#39;s totally understandable that you don&#39;t like it.</p></pre>_player1: <pre><blockquote> <p>it does make refactoring and adding features easier.</p> </blockquote> <p>This is also where I am getting stuck. When I want to refactor something I can&#39;t even see what the types are that I need to pass to my func. I&#39;m used to being able to hover over a variable and instantly see the type.</p></pre>rco8786: <pre><p>You&#39;re complaining more about the IDE here than the language.</p> <p>Going from C# and VS to a not-so-strictly-typed language in an editor without a great intellisense replacement is going to be difficult no matter what. You would have the same experience with a multitude of languages.</p></pre>_player1: <pre><p>Actually you are right. How do I get over it though?</p></pre>rco8786: <pre><p>Just keep going. Two weeks is not enough time to pick up an entirely new style of coding.</p> <p>I was in .NET land for ~3.5 years before switching to a Ruby/Rails shop long ago and the initial shock for me was the same. But you just learn new tricks and will eventually be as fast or faster than you are in C#</p></pre>dinkumator: <pre><p>vim-go and GoSublime are pretty good and integrate with go oracle pretty well. there might be some configuration to do though.</p> <p>Last time I used Atom the Go support was abysmal... not sure what it&#39;s like now, but look for something using go oracle.</p> <p>Still nothing on intellisense though.</p></pre>_player1: <pre><p>Atom has not been great. I will see how Sublime fairs. </p></pre>BoTuLoX: <pre><p>Are you well versed with Vim? Because vim-go and YouCompleteMe work wonders together. While it&#39;s not intellisense, it helps with all you need. If you have more than one monitor you&#39;ll be able to have godoc open too to get all the info you need from the libraries you want to use.</p></pre>_player1: <pre><p>Not at all but I am willing to spend the time on whatever tool(s) will improve my productivity. I posted this thread because I dont want to give up on go and wanted to hear from experienced go users how I can get myself on the right track.</p></pre>BoTuLoX: <pre><p>Oh... I&#39;m not sure wether it&#39;s the brightest idea to pick up Vim and a new language at the same time...</p> <p>Vim is the kind of thing that <a href="https://i.imgur.com/0l9dKNi.png" rel="nofollow">takes a while to learn</a> and years to master.</p> <p>Maybe try out sublime first.</p> <p>But more importantly, I&#39;d recommend you take your time to switch your way of working with code. C#/Visual Studio encourages you to let your editor do all the heavy lifting and hide all the extreme complexity behind it. Go encourages you to keep everything in your head, be able to dive in and out of the code with full knowledge of what you&#39;re dealing with because the language and runtime is very very simple yet elegant.</p> <p>These are very different approaches, and .net/Java developers always seem to have more problems than usual when breaking out of their shell, so if you keep going at it you&#39;ll be able to do it.</p> <p>As a Python programmer, while I was able to work with Go with little study, it really took me a while to &#34;grok&#34; what Go is all about and what simplicity really means.</p></pre>_player1: <pre><p>Haha. I had not thought of it like that, but that is exactly it. I am used to VS doing a lot of the heavy lifting and with go I felt abandoned. I will have to go back and take my time to get used to the new ecosystem before working on the apps I want to develop.</p></pre>ecmdome: <pre><p>+1 for GoSublime since I read you&#39;re not versed in vim... Leave that for another day.</p></pre>dhdfdh: <pre><p>I&#39;m having a problem with that first statement, too. If one is looking for other people&#39;s code to make your Go code work, then I question his methodology for learning Go. </p> <p>Or maybe I misunderstand that. All too often I see people learning programming or something new and their first assignment seems to be to find someone else&#39;s code to do the work for them rather than learning how to write the code themselves.</p> <p>EDIT: Scrolling down a little further, I see he finds &#34;getting up and running quickly&#34; to be important to him but that adds more to what I&#39;m questioning above.</p></pre>_player1: <pre><blockquote> <p>What are the things you&#39;re trying to do, and what packages have you tried?</p> </blockquote> <p>As an example, <a href="https://www.reddit.com/r/golang/comments/3fcabt/question_read_value_from_html_input_tag/" rel="nofollow">question</a> I asked last week.</p></pre>IntellectualReserve: <pre><p>I didn&#39;t see you respond to the suggestions in that thread. Did .FormValue() work for you? If not, why not?</p></pre>_player1: <pre><blockquote> <p>type *http.Response has no field or method FormValue</p> </blockquote> <p>I don&#39;t think my question was read properly. I end up using Goquery which works but is again another package.</p></pre>rco8786: <pre><p>C# doesn&#39;t have an html parser in the stblib to the best of my knowledge either. </p></pre>borring: <pre><p>The FormValue method is for *http.Request</p> <p>Have you gone through the web app code walk? That&#39;s actually where I learned about FormValue().</p> <p><a href="http://golang.org/doc/articles/wiki/" rel="nofollow">http://golang.org/doc/articles/wiki/</a></p></pre>ergotayours: <pre><p>I posted an example using only golang.org libraries.</p></pre>_player1: <pre><p>Thanks I did manage to get it working using Goquery last week but thanks I am keen to see an example with official go libs.</p></pre>dinkumator: <pre><p>parsing html you&#39;d definitely want to find a package for, but if you&#39;re up for regex this is fairly simple w/just the stdlib:</p> <pre><code>package main import ( &#34;fmt&#34; &#34;io/ioutil&#34; &#34;net/http&#34; &#34;regexp&#34; ) func main() { tofind := regexp.MustCompile(&#34;&lt;input[^/]*/&gt;&#34;) resp, _ := http.Get(&#34;https://duckduckgo.com&#34;) content, _ := ioutil.ReadAll(resp.Body) fmt.Println(tofind.FindAllString(string(content), -1)) } </code></pre> <p>I&#39;d want to check all the errors and close resp.Body, etc. but it&#39;s only a few lines of real code.</p></pre>_player1: <pre><p>I started out by googling regex for golang but the first result was a a guy telling someone with the same question as me that using regex for html is a terrible idea</p></pre>dinkumator: <pre><p>yeah that is a classic SO piece :)</p> <p>regex is fine for very simple uses (i.e. one kind of tag w/ no nesting like this) but yeah like I said you&#39;d want a html parsing framework for anything serious. web scraping is definitely not something I&#39;d call primitive though.</p></pre>egonelbre: <pre><p>What was your search query?</p> <p>First result for <code>go regexp</code> for me was <a href="https://golang.org/pkg/regexp/" rel="nofollow">https://golang.org/pkg/regexp/</a>.</p></pre>joushou: <pre><p>Trying to parse practically anything with a regex is almost always a bad idea. Trying to look for content in a dynamically changing blob that doesn&#39;t abide by &#34;nice&#34; rules, is always a bad idea. All your assumptions that you use to search will fail at some point, unless the content is well defined. A HTML parser is definitely more &#34;stable&#34;.</p> <p>... But the fact that it&#39;s a bad idea shouldn&#39;t stop you if you think it is simpler, justified, and can reason about it being &#34;stable&#34; (You&#39;re in control of content, or have clear documentation of it). Getting the job done is sometimes more important than doing it in the most correct way.</p></pre>dinkumator: <pre><p>to echo <a href="/u/ergotayours" rel="nofollow">/u/ergotayours</a> - i find the majority of things I need are in the stdlib. The times I use packages off github are for more complex things I don&#39;t expect there anyway, like oauth, postgres driver, font rendering, etc.</p> <p>the docs and tooling make it much easier to work with than C#/JS in my experience. but it&#39;s definitely more verbose and not necessarily faster.</p> <p>Personally, it took me a good 4-6 months before Go really &#34;clicked&#34; - I could write code just fine, but nothing was really idiomatic or clean until then. I had to get out of my previous code mindset to get to that point though (e.g. I had to structure my code like a Go program, not a python-program-in-Go-syntax).</p> <p>can you provide any specific examples of something primitive you had to scour github to solve?</p></pre>_player1: <pre><blockquote> <p>the docs and tooling make it much easier to work with than C#/JS in my experience</p> </blockquote> <p>Honestly I find MSDN far superior to any of go&#39;s docs.</p> <blockquote> <p>Personally, it took me a good 4-6 months before Go really &#34;clicked&#34; - I could write code just fine, but nothing was really idiomatic or clean until then</p> </blockquote> <p>From the replies so far I will push on and hope things click.</p> <blockquote> <p>can you provide any specific examples of something primitive you had to scour github to solve?</p> </blockquote> <p>I replied to <a href="/u/rgotayours" rel="nofollow">/u/rgotayours</a> with an example.</p></pre>dinkumator: <pre><blockquote> <p>Honestly I find MSDN far superior to any of go&#39;s docks.</p> </blockquote> <p>Haha I&#39;d say the same but in reverse. MSDN for me was crazy when I was first learning C#/.NET</p></pre>_player1: <pre><p>Haha. I suppose to be fair MSDN has come a long way over the years.</p></pre>scoith: <pre><p>Then maybe you should stick with MSDN.</p></pre>calebdoxsey: <pre><p>Currently Go is not conducive to copy-and-paste stack-overflow style development (something you can do with javascript, python or rails). Maybe one day it will be, but part of me hopes it won&#39;t.</p> <p>The documentation is there on the Go website or godoc.org. You&#39;re right that there aren&#39;t enough examples in some packages, but once you get used to the way its setup it&#39;s pretty easy to get around. I mean it&#39;s better than Javascript&#39;s documentation (Javascript documentation consists of out-of-date microsoft docs or out-of-date mozilla docs. Google never even bothered to provide documentation for V8) </p> <p>On the other hand C#&#39;s docs are really good with lots of examples. But the language is very complex and takes a long time to really learn. Assuming you feel pretty comfortable in C#, perhaps you&#39;re just not remembering that initial pain? Generics alone takes most developers months to really grasp.</p> <p>As for the <code>log.Println</code>, that&#39;s not at all unusual. Go definitely doesn&#39;t come with the kind of visual debugging that comes with visual studio. (maybe one day it will) I&#39;ll just mention that once you try debugging multi-threaded programs stepping through the code visually starts to be less helpful - and since Go is designed for concurrency this ends up limiting the utility of a visual debugger.</p> <p>My 2 cents:</p> <p>vs C#: * Simpler * Better concurrency out of the box (C# can go fast, but that example you copy and paste out of MSDN won&#39;t be... whereas Go&#39;s HTTP hello world is already good) * Better cross-platform support * Amenable to command line use (who in their right mind calls csc directly?</p> <p>vs Javascript: * No callback hell * Types * Modules * Real concurrency</p> <p>Anyway if you want some more examples I have a whole bunch here: <a href="https://github.com/golang-book/bootcamp-examples" rel="nofollow">https://github.com/golang-book/bootcamp-examples</a>. One day I&#39;ll get around to putting them in a better form.</p></pre>_player1: <pre><p>To be objective I have years of experience with c#, java, javascript etc and maybe I just have a bad memory but I remember being able to get on with what I wanted to do, with c#/java at least I agree on the js side. </p> <p>I have no intention of &#34;copy and paste development&#34; but I do have actual solutions I want to build not various hello world incantations. .NET has such a fantastic environment for getting up and going quickly. You can build real applications extremely rapidly yes the code might be horrific but you can learn as you progress. </p> <p>With go I feel like I hit a brick wall very quickly. </p></pre>f2f: <pre><p>sounds to me like you haven&#39;t yet discovered <a href="https://godoc.org" rel="nofollow">https://godoc.org</a>. literally every go package in the wild is documented there. some better than others.</p> <p>restrict yourself to the standard library at first. take it easy, no need to write a new OS as your first toe-dipping exercise.</p></pre>_player1: <pre><p>I have spent plenty time on godoc.org, the problem is that for a lot of packages they give you a simple example and beyond that you are on your own.</p></pre>TheMerovius: <pre><p>I almost never look at examples. When I read go documentation, I always do the following:</p> <ul> <li>Look for a type/method/function that seems to do what I want to do</li> <li>If it&#39;s a type, look for a function/method that returns that type (godoc makes that very simple most of the time, as factory-functions get listed immediately adjacent to the type)</li> <li>Write down the Function/Method name in my code</li> <li>For each argument: goto 2. Find a function/method that creates this type</li> </ul> <p>This works pretty well for me and I find it <em>by far</em> better than <em>any</em> other documentation I have seen for <em>any</em> language (given, I&#39;ve never really worked with C#). As types in go are most often quite simple (they are just structs, interfaces or nanive types &#34;rewrapped&#34;), I don&#39;t think extra examples are needed for go. The definition of a type/function will most of the time already unambiguously tell you how to create/use it.</p></pre>f2f: <pre><p>the stdlib is well documented. as i said above, stick with it to learn the language. there&#39;s no point in spending time in chinatown or little italy if you&#39;re trying to learn english.</p></pre>TheMerovius: <pre><p>I don&#39;t think this is good advice, if &#34;I want to write real stuff as quickly as possible&#34; is a requirement. There are a lot of real-world (and quite &#34;simple&#34;) stuff that you might want to do that can&#39;t be done with the stdlib only, e.g. html scraping, configuration, …</p></pre>Yojihito: <pre><p>HTML parsing and getting GET requests from a page are things where Go sucks too.</p></pre>egonelbre: <pre><blockquote> <p>My co-workers are of two extremes; either they think go is all hype and no substance or they think go is the second coming and non go programmers are inferior.</p> </blockquote> <p>I would say both are wrong.</p> <p>First, Go is not hype, it&#39;s already used in production in large scale systems:</p> <ul> <li><a href="https://twitter.com/jamwt/status/629727590782099456" rel="nofollow">https://twitter.com/jamwt/status/629727590782099456</a></li> <li>Docker</li> <li>dl.google.com</li> </ul> <p>But, Go is not a magical bullet that solves all the world problems. You still need to know how to program and use your tools and build your tools.</p> <blockquote> <p>I quickly found that practically anything I want to achieve no matter how primitive requires trawling github to find a package that does what I need.</p> </blockquote> <p>What were the problems you were solving? Basically, there are domains that Go isn&#39;t yet being used (a lot), which means there aren&#39;t that many packages for those places either.</p> <p>Btw. there is <a href="https://github.com/golang/go/wiki/projects" rel="nofollow">https://github.com/golang/go/wiki/projects</a> that provide a good reference list of packages.</p> <blockquote> <p>If go-plus is behaving I awkwardly navigate through the methods and types in the package to try figure out how ...</p> </blockquote> <p>Yup, there isn&#39;t a good debugger, yet. </p> <blockquote> <p>The code is contrived but it works...</p> </blockquote> <p>Can you show it? Maybe it can be improved.</p></pre>TweetsInCommentsBot: <pre><p><a href="https://twitter.com/jamwt/" rel="nofollow"><strong>@jamwt</strong></a></p> <blockquote> <p><a href="https://twitter.com/jamwt/status/629727590782099456" rel="nofollow">2015-08-07 18:55 UTC</a></p> <p>All the #golang excitement on hacker news makes me realize I don’t think people realize how deep @Dropbox is in golang.</p> </blockquote> <hr/> <p><sup>This</sup> <sup>message</sup> <sup>was</sup> <sup>created</sup> <sup>by</sup> <sup>a</sup> <sup>bot</sup></p> <p><a href="http://www.np.reddit.com/message/compose/?to=jasie3k&amp;amp;subject=TweetsInCommentsBot" rel="nofollow"><sup>[Contact</sup> <sup>creator]</sup></a><a href="https://github.com/janpetryk/reddit-bot" rel="nofollow"><sup>[Source</sup> <sup>code]</sup></a></p></pre>alexwhoizzle: <pre><blockquote> <p>Yup, there isn&#39;t a good debugger, yet.</p> </blockquote> <p>Two projects to keep your eye on are <a href="https://github.com/mailgun/godebug" rel="nofollow">Godebug</a> and <a href="https://github.com/derekparker/delve" rel="nofollow">Delve</a>. Both take very different approaches to debugging go programs.</p></pre>_player1: <pre><p>I would like to commend <a href="/r/golang" rel="nofollow">/r/golang</a> for the level-headed replies so far. They have made me re-examine things and I am finding this incredibly helpful.</p> <p>Edit: Well it was fun while it lasted, I see the trolls have come out to downvote everything. It is unfortunate that the neckbeards are so emotionally fragile. Thank you to the helpful and patient redditors.</p></pre>mbrumlow: <pre><blockquote> <p>I quickly found that practically anything I want to achieve no matter how primitive requires trawling github to find a package that does what I need. </p> </blockquote> <p>Not to be a total dick, but I think that is your problem. If your first notion is to go to github and find some code somebody else wrote to do what you want then you are likely barking up the wrong tree. Sometimes you have to write a loop. </p> <p>Here is a link that you should watch, its to the point about including libraries, and people who posted small snips of code in your example question showed you can do it without one as well. </p> <p><a href="https://youtu.be/yi5A3cK1LNA?t=701" rel="nofollow">https://youtu.be/yi5A3cK1LNA?t=701</a></p> <p>But I really think you should watch the entire thing, so here is the link without the time marker set. </p> <p><a href="https://www.youtube.com/watch?v=yi5A3cK1LNA" rel="nofollow">https://www.youtube.com/watch?v=yi5A3cK1LNA</a></p></pre>_player1: <pre><p>That was not my first notion at all. As I mentioned in another comment I originally wanted to use regex which lead me to a go newsgroup discussion which said parsing html with regex is a horrible idea. From there I posted on <a href="/r/golang" rel="nofollow">/r/golang</a> to ask what is the correct way to do it.</p> <p>I take a look at the video you linked.</p></pre>mbrumlow: <pre><p>I am sorry nobody pointed you in a better direction then. </p> <p>The next step would be to think about how any library you would want to use would actually get the job done. </p> <p>What you need is a tokenizer. Writing a HTML tokenizer would be some work but not completely insane. Might take a day or two. The good news is that there are some tools built into go&#39;s standard library that can assist in making a tokenizer suited for anybody&#39;s needs. </p> <p>Sometimes its a good idea to dig into the library you are about to use and understand fully what it is doing under the hood. You would be surprised how often somebody&#39;s attempt to make a library and define a &#34;good&#34; api distract from the core of what is going on. All you might need to do is understand 20 lines of code that has been wrapped in some fluff API. </p></pre>borring: <pre><blockquote> <p>if I am lucky there is a slither of documentation but more likely the &#34;documentation&#34; consists of a one liner shell command to install the package.</p> </blockquote> <p>It doesn&#39;t seem like you&#39;re using all the resources available to you. Go documentation is generated by the Go tools from source code. That&#39;s to say that so long as the author follows Go conventions and properly comment their code, there should be adequate documentation. This is probably why documentation seems so terse for most Go packages. That&#39;s because what you see on github isn&#39;t actually the package documentation.</p> <p>The autogenerated documentation can be found online by browsing <a href="https://godoc.org" rel="nofollow">godoc.org</a>. You can also use <a href="https://godoc.org" rel="nofollow">godoc.org</a> to <em>search</em> for packages and documentation.</p> <p>There&#39;s also a really handy chrome extension (<a href="https://chrome.google.com/webstore/detail/goto-godoc/hdggomenfmfnepgloibbfabpbfenpkhe?utm_source=chrome-ntp-icon" rel="nofollow">goto godoc</a>) that takes you to the corresponding Godoc.org page for the repository you&#39;re currently viewing (github, etc..)</p></pre>arihant5: <pre><p>Since you&#39;ve spent only a couple weeks with it, what you&#39;re missing is patterns. Let me give you an example. Let&#39;s say you&#39;re learning Java, naturally you would find yourself making datatypes, classes, and using inheritance. With Go, you&#39;d find yourself using interfaces in a more functional sense, you will find yourself doing very less inheritance, and more composability.</p> <p>Then, after a few thousand lines of code, you&#39;d find that while you read Java (or Python, Ruby) code like a doubly linked list, you can read Go code as a tree.</p> <p>Separation of concerns is a big Go feature. Concurrency is another, but I believe that&#39;s why people come to language in the first place.</p></pre>ElliottStoneham: <pre><p>I think it&#39;s like buying an annual gym membership. If you don&#39;t &#34;go&#34; regularly, you don&#39;t see any benefit. And it takes a long period of &#34;go&#34;-ing regularly to gain the full transformation you are seeking. </p></pre>scoith: <pre><p>The summary is he is not happy about the quality and documentation of some 3rd party packages on github.</p> <p>While ironically not being able to figure out how to use the well-documented golang.org/x/net/html (to which I can only say RTFM --and yes, the function you used in javascript/c# may not exists in the relevant go package, in which case you have to go through the unbelievable trouble of reading the doc.)</p> <p>And he thinks he is natural while using the phrase &#34;I drank the kool-aid&#34;.</p></pre>_player1: <pre><p>I see you have reading comprehension difficulties.</p></pre>

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

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