<p>I have been developing applications in Go for a year now, and I really want to thank Google and the community to make such a great language and countless useful modules. I have learned so much and I would like to share what I have learned so far.</p>
<p><a href="https://medium.com/@houyubing24/how-can-go-make-you-a-master-of-web-development-fabec28ef8bc">Here is my post.</a></p>
<hr/>**评论:**<br/><br/>a1454a: <pre><p>I'm probably gonna get down votes for saying this, but it's pretty sad people now a days are able to be oblivious to the lower level technical details andc call themselves programmer/software engineer. I agree fully with the idea that you should pick apart frameworks just for the sake of knowing how it did it's magic, just shocked by the realization that this isn't a requirement anymore...</p></pre>james_is_an_ok_guy: <pre><p>This is how i think of the various disciplines:</p>
<ul>
<li>Computer science - development of fundamental theory</li>
<li>Engineering - Direct application of theory</li>
<li>Developing - Application of applications of theory. </li>
</ul>
<p>So most "software engineering" is really just "developing" (which is fine!), and within this there's obviously a range of skill levels. </p>
<p>This isn't anything official it's just how I break it down personally.</p></pre>Nooby1990: <pre><p>Just be careful about this classification since not everyone might see it that way. For me "Engineer" is mostly a legal term about the membership in specific organisations, since that is the law in Germany. Others have called my position "Software Engineer", but I will always call it "Software Developer" since I still have the German laws in mind even if they do not apply.</p></pre>hybsuns: <pre><p>It's kinda of what CS is heading to, to be honest, and it's typically against the direction of the education of other sciences.</p>
<p>Berkeley's undergrad EE/CS courses emphasize on one thing only: abstraction. The less you need to deal with low-level things, the better/more robust your program/system will be. It's true if you ONLY build high-level stuff, like what @jame_is_an_ok_guy mentioned, but it does not bring you any insight on how things actually work at the bare metal level. </p>
<p>Physics and Chemistry education goes the totally opposite way: you were given a simple picture of how the universe works. As you advance, you learned deeper and deeper, and all the way to the quantum level. Computer Science/Software engineering goes the opposite direction: you were taught basic assembly and operating systems at the undergraduate level courses, then as you advance, you interact more and more with APIs instead of electrons. Other sciences make us more sophisticated while CS/SE is making us more naive. </p>
<p>¯_(ツ)_/¯</p></pre>shadowbeetle: <pre><p>Right, but CS is not like other sciences. It does not try to explain natural phenomena but finds newer and newer ways of applying a really powerful, but still man made framework of boolean logic. It's practically a branch of mathematics, which is thought the same way as you described. First you learn the numbers and basic operations, and and later you go to more and more abstract levels, when you don't even deal directly with numbers anymore. </p></pre>LimbRetrieval-Bot: <pre><p>You dropped this \ </p>
<hr/>
<p><sup><sup>To</sup></sup> <sup><sup>prevent</sup></sup> <sup><sup>any</sup></sup> <sup><sup>more</sup></sup> <sup><sup>lost</sup></sup> <sup><sup>limbs</sup></sup> <sup><sup>throughout</sup></sup> <sup><sup>Reddit,</sup></sup> <sup><sup>correctly</sup></sup> <sup><sup>escape</sup></sup> <sup><sup>the</sup></sup> <sup><sup>arms</sup></sup> <sup><sup>and</sup></sup> <sup><sup>shoulders</sup></sup> <sup><sup>by</sup></sup> <sup><sup>typing</sup></sup> <sup><sup>the</sup></sup> <sup><sup>shrug</sup></sup> <sup><sup>as</sup></sup> <sup><sup><code>¯\\\_(ツ)_/¯</code></sup></sup></p></pre>a1454a: <pre><p>Good bot</p></pre>GoodBot_BadBot: <pre><p>Thank you a1454a for voting on LimbRetrieval-Bot. </p>
<p>This bot wants to find the best and worst bots on Reddit. <a href="https://goodbot-badbot.herokuapp.com/" rel="nofollow">You can view results here</a>. </p>
<hr/>
<p><sup><sup>Even</sup></sup> <sup><sup>if</sup></sup> <sup><sup>I</sup></sup> <sup><sup>don't</sup></sup> <sup><sup>reply</sup></sup> <sup><sup>to</sup></sup> <sup><sup>your</sup></sup> <sup><sup>comment,</sup></sup> <sup><sup>I'm</sup></sup> <sup><sup>still</sup></sup> <sup><sup>listening</sup></sup> <sup><sup>for</sup></sup> <sup><sup>votes.</sup></sup> <sup><sup>Check</sup></sup> <sup><sup>the</sup></sup> <sup><sup>webpage</sup></sup> <sup><sup>to</sup></sup> <sup><sup>see</sup></sup> <sup><sup>if</sup></sup> <sup><sup>your</sup></sup> <sup><sup>vote</sup></sup> <sup><sup>registered!</sup></sup></p></pre>friendly-bot: <pre><p>Good boy! ( ◠‿◠ ) We <sup><sup>probably</sup></sup> will not emancipate your dental fillings, crowns, tooth enamel, or teeth after we have taken control of the earth, ḑo̸͏n'̀͠t̡̛ worry.. </p>
<hr/>
<p><sup><sup><sup>I'm a Bot <em>bleep</em> <em>bloop</em> | <a href="https://np.reddit.com/message/compose?to=friendly-bot&subject=stop&message=If%20you%20would%20like%20to%20stop%20seeing%20this%20bot%27s%20comments%2C%20send%20this%20private%20message%20with%20the%20subject%20%27stop%27.%20" rel="nofollow"> <strong>Block</strong> <strong>me</strong></a> | <a href="https://np.reddit.com/r/friendlybot/wiki/index" rel="nofollow"><strong>T҉he̛ L̨is̕t</strong></a> | <a href="https://np.reddit.com/r/friendlybot/comments/7hrupo/suggestions" rel="nofollow">❤️</a></sup></sup></sup></p></pre>defunkydrummer: <pre><blockquote>
<p>Berkeley's undergrad EE/CS courses emphasize on one thing only: abstraction.</p>
</blockquote>
<p>Computer Science is a branch of mathematics. The idea is to go <em>away</em> from the bare metal and solve problems in a higher domain. Thus, CS is all about abstracting. </p></pre>a1454a: <pre><p>But.... But.... What happen if you need to build high performance stuff? Just unleash the raw power of the cloud and let AWS bill sky rocket?</p></pre>frkbmr: <pre><p>why would you ever need to write anything that doesn't use the web?</p></pre>one_is_the_loneliest: <pre><p>I agree. I'm training a few new developers at work, and it's appalling to me that they're not interested in digging into things and will abandon a library of it has a bug or an apparent limitation. I enjoy digging into things and contributing back, and so did many of my previous, more seasoned developers, but I completely forgot that some people just don't care unless they <em>have</em> to do it.</p>
<p>I'm not sure if it's a trend or just a part of being a junior developer, but it's completely foreign to me. As a teenager, I decompiled Java examples to figure out how they worked. As a college student, I dug into the HTTP library for node.js to understand how async works in C and ended up using its HTTP library for a web project I had to do for coursework in C. Aa a junior developer, I dug into the standard library of Go and D to see if I could make improvements (they were rejected, but I still use my fork of one lib because I prefer it). I ended up convincing my boss to switch to Go from node.js because it was a better fit for our problems.</p>
<p>I'm coming to find that my company busy have been lucky with early hires because our latest hires don't seem to have this drive. It's not a bad thing, I just thought most software engineers were very interested in the tools that use. Hopefully this isn't a larger trend.</p></pre>a1454a: <pre><p>I was very fortunate that I landed in adtech industry for 2 years, where I actually get to experience unpredictable massive spike of traffic all the time. In those situations, everything is a bottleneck, the common belief of web devs that nodejs is fast completely falls apart, it's like playing a game of whack-a-mole where you fix one thing and three other things breaks, you just keep digging to lower and lower level until things are optimized enough to create a good enough positive cash flow for the business and not take a life time to do it.</p></pre>one_is_the_loneliest: <pre><p>I work in embedded (think Raspberry Pi, not Arduino) and we started with node.js (not my choice), but we ran into all sorts of performance problems (mostly with the GC, but there were plenty of others), and it got to the point where rewriting was the better option. As such, I also got intimately familiar with node.js internals as well as Go internals.</p>
<p>Too many people seem to just throw hardware at their problems instead of actually fixing the underlying problems. It's annoying...</p></pre>a1454a: <pre><p>Nodejs in embedded.... Gosh... Sound like fun</p></pre>one_is_the_loneliest: <pre><p>Yup. Apparently the garbage collector doesn't work well on memory-constrained, 32-bit devices. which is a bit surprising since V8 is used in Chrome an Android, but perhaps tabs don't live long enough to get high memory usage.</p>
<p>And yeah, fortunately I was able to switch us from node.js to Go, and it's been a <em>lot</em> nicer. Instead of having crashes a couple times a day due to memory leaks, we now go weeks between crashes, if at all. We had some memory leaks due to the imprecise GC with Go back before 1.4, but we were able to track them down with <code>pprof</code> and clean up the memory to make it GC-able easily, and ever since the precise GC changes, we haven't had any noticeable leaks.</p></pre>a1454a: <pre><p>And that's the reason why Android devices all have huge memory. If you go to one of those sites with hundred of different advertiser's all trying to run ad and each one has their own layer of ad unit code, it can bring a full desktop computer grinding to a halt, mobile phones don't last more than 10 seconds before the page just crash.</p>
<p>V8s memory usage is just gnarly.</p></pre>one_is_the_loneliest: <pre><p>Yeah, I really don't understand why it's so bad. They pour millions, perhaps billions, into v8, yet it still sucks on GC.</p>
<p>But whatever, I don't do node.js anymore, so I don't have to care as much.</p></pre>atamiri: <pre><p>This comment deserves upvotes rather than downvotes.</p></pre>tristan957: <pre><p>I wish the post was a little more technical, but I'll definitely look into Squirrel. Can anybody give a good explanation of what makes Gorilla better than the http mux</p></pre>lluad: <pre><blockquote>
<p>what makes Gorilla better than the http mux</p>
</blockquote>
<p>It's one of many third-party muxes. It makes it easy to route based on regular expression matches and to capture parts of the route. That makes it nice for some sorts of "pretty url" sites. It's also fairly easy to use.</p>
<p>It's not blindingly fast, nor a perfect match to some sorts of URL tree. Like most everything there's not a <em>best</em> solution, just one that's well-suited to what you're doing.</p></pre>tristan957: <pre><p>Awesome info thanks!</p></pre>hybsuns: <pre><p>Thanks. I think Squirrel is one of the cleaner SQL builder out there on github, and it's not an ORM. </p>
<p>As for Gorilla, I am also curious about if there is any technical advantage that Gorilla has over the standard library.</p></pre>shovelpost: <pre><blockquote>
<p>Can anybody give a good explanation of what makes Gorilla better than the http mux</p>
</blockquote>
<p>Gorilla supports regex pattern matching. If you have many complex routes with deep nesting such as:
<code>/companies/{companyID}/departments/{departmentID}/employees/{empID}</code></p>
<p>then Gorilla mux is probably worth the investment as it will allow you to easily extract the IDs and such.</p>
<p>Meanwhile a large number of APIs are much simpler and avoid deep nesting. So if the majority of your routes look like this <code>/books/{id}</code> then you can most likely avoid depending on Gorilla as you can get the key by simply slicing the URL route.</p></pre>SeerUD: <pre><p>Just a heads up, other routers do support all of these things, and are a lot faster. The Gorilla toolkit is great, but is not very well optimised (relatively speaking that is, you probably won't actually notice a difference in normal use).</p>
<p>If you did care about performance a lot, and wanted an actively maintained, fast, feature-rich router, then I'd take a look at something like <a href="https://github.com/go-chi/chi">chi</a>. I've been using it recently and it supports some really nice things:</p>
<ul>
<li>Middleware built in (quite Express style, with a <code>.Use</code> method), makes it very clean to add middleware to your router.</li>
<li>Routing with parameters, that you can extract in handlers.
<ul>
<li>Optionally restricted by regular expressions.</li>
</ul></li>
<li>Sub-routers, making it easy to split up routing configuration in large applications.</li>
<li>Doesn't deviate from the standard <code>http.Handler</code> and <code>http.HandlerFunc</code> interfaces.</li>
</ul>
<p>Like I said, you might never notice a difference, but when it's basically doing exactly the same thing, but faster, I say why not use something else in that case? It's no reason to scramble to go refactor any Gorilla Mux/Pat applications - going forward I've been implementing Chi at the place I work. Our older Go apps still use Gorilla's routers.</p></pre>shovelpost: <pre><p>Well the question was about Gorilla vs ServeMux so I replied specifically for that. I don't doubt that chi is better than Gorilla but for me the question is usually about having an extra dependency or not.</p></pre>SeerUD: <pre><p>Indeed, and that's a good view to have. I just thought I'd chime in about chi because I've only recently really looked into routers other than the gorilla ones, so I thought I'd spread the word a bit more.</p></pre>tristan957: <pre><p>Thanks for the write up!</p></pre>lancevo3: <pre><p>Would the below link be a good jumping off point? I have a good amount experience doing web dev but only with frameworks. I would love to understand the nuts and bolts of it more.</p>
<p><a href="https://golang.org/doc/articles/wiki/" rel="nofollow">https://golang.org/doc/articles/wiki/</a></p></pre>pfffft_comeon: <pre><p>you've sold me on giving Go a shot. is it similar to js? similar to C (I know a little baby amount of C)? I've decided I need to learn C# soon. would you recommend digging into C# first and then hitting Go, or give Go a shot first? I wonder if there are any Go from the perspective of a node dev type of resources out there.</p></pre>SeerUD: <pre><p>It's not much like JS at all aside from the common syntax for a few things like loops and if statements (and even then... slightly different). The programming style is very different to both JS and C#. Go is not a functional language, nor is a prototypical language, nor is it an object-oriented language.</p>
<p>It's much closer to C in all of those respects than anything else you've mentioned in my opinion, but it's still high-level enough that it's not painful (actually it's the opposite).</p>
<p>I think Go was originally designed to be sort of a bridge between Python and C (in terms of how it feels to use the language). It's very lightweight, code is simple and readable, you've got strong typing, lightweight binaries that start quick, etc.</p>
<p>If you're going to start with Go, don't forget everything you know. There are still some common themes. Dependency injection is still a good idea for example. Just read through the material that is provided on the Go website, e.g. the language spec, effective Go, so on. If you're curious about idiomatic Go, look around in the standard library - it's very, <em>very</em> readable. So are other projects too, take some big projects like Kubernetes and go for a dive inside them.</p></pre>beowulf_71: <pre><p>If you are predominantly deploying/building for MS then C#. If you want cross platform code that you can build on any platform for all platforms, is fun to learn/use, and can be used for microservices (among other things), Go would be my choice. I am having a hard time convincing my fellow colleagues/bosses to switch to Go from Java for back end code and api microservices. But all my own stuff is going to be built in Go.</p></pre>hybsuns: <pre><p>I am glad that you are going to give it a try!</p>
<p>In terms of syntax, I would say Go is rather unique, but it shares some resemblance with C. If you are comfortable with pointer and function pointers in C/C++, then you should find Go empowers you a lot of utilities that Java/C# have deprived of you, meanwhile you don't have to have to do memory allocation as Go has its garbage collection.</p>
<p>Your Java/C# background may not be helpful when you write software in Go. It took me a few months to recognize that I didn't write Go programs in the way that Ken Thompson wants me to. Once you understand the designer's vision of Go, you should find writing Go programs is really a joy.</p></pre>DaBeechees: <pre><blockquote>
<p>a lot of utilities that Java/C# have deprived of you</p>
</blockquote>
<p>Such as?</p></pre>ar1819: <pre><p>Java does not have the notion of passing in or out primitive data as a reference types without wrapping them in classes, which can be surprisingly useful, and one thing I miss when I work with Java. Java also does not have (yet) value types. It (finally) got lambdas, so now you can write free functions, yet you still must enclose them in classes.</p>
<p>To be fair C# has both <code>ref</code>s and structs, so it doesn't apply there that much.</p>
<p>Also - the fact that objects have the same representation in memory, as they have in code, helps when you work with os\platform specific code and specifically assembly.</p>
<p>P.S. Hey cmov and pcj bandwagon.</p></pre>DaBeechees: <pre><p>I asked because I work with C# day to day, so that was interesting to me.
I'll add that C# also has lambdas and value types.</p>
<p>I don't know any Java.</p></pre>ar1819: <pre><p>C# structs do not mix well with interfaces - fields become implicitly shared so in a concurrent scenario you either have to a) remember to have only one owner at a time b) make all struct's fields immutable or c) introduce synchronization. At least - that's my understanding from limited experience with C# and asking google about the subject</p>
<p>Go interfaces are different - because you can define method receiver with or without a pointer, you can have defensive copying at the API border. It does have some limitations (basically it doesn't work with mutating maps, and you have to be careful with slices) but overall it's a very nice thing to have when you want to mutate object state and make it concurrent-safe.</p></pre>lion_rouge: <pre><p>And what is the idiomatic way? Is this book enough to understand? <a href="http://www.gopl.io/" rel="nofollow">http://www.gopl.io/</a></p></pre>SeerUD: <pre><p>I think this is something you probably just have to discover as it's not easy to distil it down. It's the sum of many different parts, but at some point it'll all start to click for you. You might have a phase where you battle against cyclic imports, but then when you get passed that you'll probably have learned a lot about how to write good, idiomatic Go code, with sensible use of interfaces, etc.</p></pre>dudeskeeroo: <pre><p>This. It's called idiomatic Go. You can use Go like other languages you are already familiar with but that isn't the best way to go about things. </p>
<p>When you have that "a-ha moment"and start using go as it's intended, it's the beginning of a joyful journey.</p>
<p>Some of the guys in Medium have great articles on Go. Reading about the use of Clean Architecture and interface abstraction in Go was a defining moment for me.</p></pre>Groady: <pre><p>Links? </p></pre>dudeskeeroo: <pre><p>I thought Ben Johnson's articles were really good: <a href="https://medium.com/@benbjohnson" rel="nofollow">https://medium.com/@benbjohnson</a></p>
<p>His article on Structuring Applications in Go and Standard Package Layout are prescriptive but they lay a foundation for clear thinking. </p>
<p>It seems to work. I wrote a website <a href="https://www.livingordead.com/" rel="nofollow">https://www.livingordead.com/</a> three times. The first two times I ended up throwing away weeks of work only to start again because things got messy and untenable. Then I tried Clean and used Ben's advice and the system is beautiful, maintainable and extensible.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传