Is Go a good language to begin back-end development with?

polaris · · 840 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m somewhat new to web development (not so much programming) and I&#39;m wondering if starting my back-end career with Go would be a good idea. Are there any obvious disadvantages to getting into back-end development starting with Go?</p> <hr/>**评论:**<br/><br/>weberc2: <pre><p>No disadvantages that I can think of. In fact I think Go is the best language for backend web development for almost any application, and especially for beginners (I rarely use absolutes like &#34;best&#34;, but I think anything less would be an understatement--only in the rarest niche cases would I use a different language). Most languages have a steep learning curve, either because the language is complex or the tooling is. Go makes both easy (to build a Go project, just run &#34;go build&#34; anywhere in the project tree--no Makefiles, maven files, setup.py, project.json, etc required). Further, most languages require an external web server process to invoke your web application; these tend to be complex to set up and deploy--Go&#39;s web server is just a module in the standard library, and it&#39;s dead simple to use. Go also makes deployment super simple--everything compiles into a single executable file, so deployment is as easy as copying that file onto the target machine; almost every other web language will require you to install a runtime (e.g., the Python interpreter, Node, or Java or .Net virtual machines) and all of your third party libraries; this typically also means configuring the environment so your application&#39;s runtime can actually find those libraries in the file system.</p> <p>This is really just scratching the surface of what makes Go a great web language--there are many other reasons (Go is among the fastest, it&#39;s easy to learn, expansive standard library, etc). Let me know if you have any questions.</p></pre>DanChm: <pre><p>This is really helpful, I was under the impression that Go is more difficult to learn. My current situation is that I&#39;m finishing my computer science undergraduate degree this year and I&#39;m focusing on web development as my future career. I know PHP, HTML, CSS and some JS from uni projects but nothing major. The impression I get is that in web development it&#39;s best to stick to the newest technologies. Go seems very attractive since I&#39;ve done some C and C++ projects in the past and really liked it. </p> <p>I have setup my development server and I&#39;m ready to start creating some websites and web apps. The only thing left for me to decide on is the back-end language. From what you describe Go seems like the best choice. That said I did have some people tell me:</p> <p>&#39;PHP is a better place to start since it&#39;s mature and most CMSs use PHP&#39;</p> <p>&#39;Node.js is better than Go if I want to focus mainly on simple apps and websites as opposed to large scalable systems.&#39;</p> <p>&#39;Go doesn&#39;t have as many libraries and frameworks as other languages and you will find yourself reinventing the wheel and writing things from scratch&#39;</p> <p>How much of this is true?</p></pre>weberc2: <pre><p>Go bests PHP and JS when it comes to performance, tooling, deployment, and language ergonomics. I&#39;m not aware of any web libraries that are available in Node and PHP but not in Go. Go tends to be in the ballpark of 100 times faster than PHP and 10 times faster than JS in straight-line execution, but Go also has a better concurrency model than either JS or PHP (so it is able to make more efficient use of system resources).</p> <blockquote> <p>Node.js is better than Go if I want to focus mainly on simple apps and websites as opposed to large scalable systems.</p> </blockquote> <p>I don&#39;t think there&#39;s any truth here. In particular, deploying Node is painful due to dependency management (again, deploying Go is just copying a binary to your host--there is no Node/PHP interpreter nor runtime libraries).</p> <p>All this said, any of these options are well-suited for a low traffic personal web app, though Go will help you get off the ground faster and you&#39;ll be picking up a useful language for a potential job where performance and scalability will likely matter.</p> <p>If you do end up picking Go, feel free to come back here for help getting started. Here&#39;s the HTTP hello world (if you had Go installed, you could download this and run <code>go run &lt;file.go&gt;</code> and then point your web browser to http://localhost:8080):</p> <pre><code>package main import ( &#34;fmt&#34; &#34;log&#34; &#34;net/http&#34; ) func main() { http.HandleFunc(&#34;/&#34;, func(w http.ResponseWriter, r *http.Request) { log.Println(r.Method, r.URL.Path) fmt.Fprintln(w, &#34;Hello, world!&#34;) }) log.Println(&#34;Listening on port 8080&#34;) if err := http.ListenAndServe(&#34;:8080&#34;, nil); err != nil { log.Fatalln(err) } } </code></pre></pre>DanChm: <pre><p>This is again really useful, I&#39;ll take some time to play around on the server and see how far I can go with this.</p></pre>ConfuciusBateman: <pre><p>Hey there, not OP but your comments were really helpful and interesting. I&#39;ve been looking for a new language to learn for a while, and Go really struck the right note for some reason and I&#39;ve been getting into it for the past couple days. One question I have, however, is in what contexts would Go&#39;s concurrency model be used in web development? I&#39;m sure there are tons of examples, but do you know of any interesting use cases? Is concurrency something used commonly in web development? It doesn&#39;t seem like it for some reason, maybe it just doesn&#39;t get talked about too much. I find concurrency very interesting conceptually, so it&#39;d be cool to learn about ways to apply it in a web context.</p></pre>weberc2: <pre><p>First of all, it&#39;s often useful to handle multiple requests simultaneously. For example, a Python web server can only handle one request at a time, even if the first request is just blocking on I/O (leaving the CPU otherwise free to do work). There are myriad solutions to this problem in Python-land, but none are as friendly or scalable as Go (or probably even Node). There&#39;s also intra-request concurrency, where you might have some CPU task to do while also waiting on the result of some database query. Recent versions of Python introduced async, but it&#39;s tricky to use correctly, and you have to take care not to call any blocking I/O. This problem doesn&#39;t exist in Go because there is no blocking I/O; the CPU can do the CPU task while the scheduler waits for the database result to come back.</p></pre>Astra108: <pre><p>How is Go a replacement for JS? Asking as a noob here. Is it a replacement for node or can it do a lot of front end UI tasks much like a templated framework like Python&#39;s Django?</p></pre>weberc2: <pre><p>The context of the conversation is programming language for backend applications, so its competition would be Node and Python.</p> <p>I&#39;m not especially familiar with Django, but I suspect that Go has a lot of the same components (HTML templating, JSON support, HTTP support, etc), but perhaps less integrated since Go is much more general-purpose than Django. The Gorilla project in particular might be a better analogy for Django since it&#39;s a framework for building web applications in Go instead of a loose collection of single-purpose libraries (e.g., Go&#39;s std lib).</p> <p>Go can also compile to JavaScript by way of GopherJS, but I don&#39;t believe this is actually used in production anywhere.</p> <p>Hopefully I answered your question?</p></pre>Astra108: <pre><p>Ah, thanks, I will check out the html templating and the Gorilla library. It seems like what I want to use, where I can get button responses and such without having to write a bunch of JS. </p></pre>weberc2: <pre><p>I don&#39;t know much about Gorilla, but I doubt it will give you JS UI components.</p></pre>PaluMacil: <pre><p>Part of the &#34;not as many libraries&#34; comment seems to come from the a lot of Node libraries use tons of dependencies where Gophers tend to try to inline simple functionality that doesn&#39;t need to be hidden away in a library for no fantastic reason.</p></pre>sh41: <pre><p>I highly recommend this talk by Audrey Lim, as it gives the answer to question better and more convincingly than I could. <a href="https://www.youtube.com/watch?v=fZh8uCInEfw">https://www.youtube.com/watch?v=fZh8uCInEfw</a> (Spoiler: I think it&#39;s fantastic choice as a first backend language.)</p></pre>MEAT_FIST: <pre><p>I like Go because there isn&#39;t a ton of &#34;magic&#34; that goes on between libraries (if you use the right libraries). My experience with Java was very dissimilar, there was always a ton of &#34;just trust this library and call this method&#34;; I had not a great grasp upon what was actually happening through builds/execution. With Go, between the standard library and almost all of the 3rd party tools I&#39;ve worked with, the APIs are simple, there isn&#39;t a ton of magic, and the library code is easy to read/reason about.</p> <p>I also very much enjoy the fact that they&#39;ve really paired down the OO principles they implement. Again, in Java, the abstractions and design principles implemented rarely created cleaner, more efficient code. I forget who said it, but &#34;The best code is the code I didn&#39;t have to write&#34; is a quote that I very much agree with, and I think falls very much in line with the design principles in Go.</p></pre>ultra_brite: <pre><p>If you can get pass the limited type system and &#34;type juggling&#34; then Go has many advantages over Java, Ruby, Python, Node.JS, PHP and co when it comes to writing &#34;backends&#34; especially highly concurrent applications. When it comes to the ecosystem, no question both Java and Python have way more libraries. I wouldn&#39;t do data crunching or data science in Go , but it&#39;s something you can put on a worker queue and let Go handle all the networking aspect of your backend. I had to integrate with a legacy SOAP system the other day, it was a pain in the ass with Go, done in 30 minutes in Python.</p></pre>iends: <pre><p>Go is great but the job market is thin (but growing rapidly). If you are working by yourself and/or time to market is priority number one, then stacks like rails or nodejs might be better tools given this constraint. If you&#39;re on a team of 3+ people trying to build something to scale your choices are basically C#, Java, and Go. Go is the most fun of these three. </p></pre>DanChm: <pre><p>So would you say that working as a freelancer for example, mainly creating small business websites and working in a small team (1-3 people) or alone, I&#39;m better off with Node.js as opposed to Go?</p></pre>MrCowPie: <pre><p>for small business websites as a freelancer, clients don&#39;t really care what you use as long as you get things done. Furthermore it&#39;s unlikely you&#39;ll have to be concerned with performance unless you did something really wrong in the code. The most practical language is and will be PHP at least for the next 5-10 years (yes I know wrong sub). For example, there&#39;ll be times when hosting is already picked out and paid for before you get to it. And most likely it&#39;s shared hosting like godaddy, in which case you&#39;ll have to use PHP. If your business grows and you have to find help, will you have an easier time finding PHP developer? or node developer?</p></pre>DanChm: <pre><p>So If I wanted to work with the major CMSs I would need some PHP knowledge right? Does that mean that even if I learnt Go I would still find myself learning PHP anyway? Or is it a viable strategy to ignore Wordpress/Drupal and focus just on customised solutions for clients. At the end of the day, 1 job is all I need.</p></pre>MrCowPie: <pre><p>PHP runs something like 80% of all website. it is most definitely you&#39;ll come across it if you create websites for a living. </p> <p>I&#39;m more of an enterprise developer and only do website for lunch money. So far I have not had to deal with wordpress/drupal. I think you should post in <a href="/r/webdev" rel="nofollow">/r/webdev</a> to get a better answer. Either way, don&#39;t stop with just PHP. I have been a developer for 15+ years and am still learning new stuff.</p></pre>PaluMacil: <pre><p>freelance and small teams won&#39;t care what language you use to accomplish a task typically. I would recommend Go for the simple reason that it&#39;s a fantastic language and the places it excels best are possibly being easy to learn, being easy to understand others&#39; code, and being easy to keep up reason about. For me, it is the fifth most used tool after C#, JavaScript, Python, and TypeScript because of my employer. I still love to work with Go because I feel like I can be great at Go with only a little effort now and then. The opposite is true with C#. It has so much in the framework and so many handy shortcut adding keywords and libraries that I don&#39;t know that I&#39;d be an expert if I only used it on hobbies. As far as Node and PHP go, I would discourage them. You&#39;ll learn enough JavaScript and TypeScript over time (if you&#39;re doing web) that you&#39;ll probably wind up adding Node to your toolkit anyway, and Node is a LOT of layers of JS to learn at first. For PHP, it isn&#39;t the future. There is plenty of work there, and there might be forever, but PHP developers seem to make a lot less money overall, and they get teased a lot (unfairly--people shouldn&#39;t really be so opinionated about languages) by other developers for using a language that makes a lot of clunky decisions about syntax that don&#39;t match any other languages. You can write fantastic PHP, but it has a bad reputation, and I have never felt the need to add it to my career.</p></pre>iends: <pre><p>I think so. The job market just isn&#39;t there that I can see. If you&#39;re extremely good and well known in the Go community maybe you can more easily find Go freelancing jobs but the market seems pretty saturated based on the availability of open positions. (A somewhat related and interesting read: <a href="https://news.ycombinator.com/item?id=12759064" rel="nofollow">https://news.ycombinator.com/item?id=12759064</a>)</p> <p>The other point is that most small businesses don&#39;t need the performance and scaling ability that Go affords, so by giving some of that up you can usually ship faster with other ecosystems.</p></pre>DanChm: <pre><p>Nice thread link, thanks, I&#39;ll read into it.</p></pre>sheepdog69: <pre><p>It depends on what you are going to be doing. Go is a great language and does very well in the &#34;back-end&#34; but it&#39;s not the one-tool-to-rule-them-all (no tool is - regardless of what the fanboys say)</p> <p>That said, you could do a lot worse than Go. But the one main disadvantage I currently see for Go is the job market. If you want to learn it to be generally employable, I&#39;d move on to python, Java, or php.</p> <p>Good luck.</p></pre>drvd: <pre><p>The question is more: What else could you (seriously) consider? Java? C++? Haskell? Node.JS? Python? (Painful, very painful, well ..., please, slow)</p></pre>ITSecMedia: <pre><p>I love Go, but for a solid base of understanding, I&#39;d start with C or C++.</p></pre>rmanolis: <pre><p>If the project becomes too big, then you will see duplication because of the lack of generics.</p></pre>

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

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