<p>I'm somewhat new to web development (not so much programming) and I'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 "best", 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 "go build" 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's web server is just a module in the standard library, and it'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'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'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'm finishing my computer science undergraduate degree this year and I'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's best to stick to the newest technologies. Go seems very attractive since I've done some C and C++ projects in the past and really liked it. </p>
<p>I have setup my development server and I'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>'PHP is a better place to start since it's mature and most CMSs use PHP'</p>
<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>
<p>'Go doesn't have as many libraries and frameworks as other languages and you will find yourself reinventing the wheel and writing things from scratch'</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'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't think there'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'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's the HTTP hello world (if you had Go installed, you could download this and run <code>go run <file.go></code> and then point your web browser to http://localhost:8080):</p>
<pre><code>package main
import (
"fmt"
"log"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
log.Println(r.Method, r.URL.Path)
fmt.Fprintln(w, "Hello, world!")
})
log.Println("Listening on port 8080")
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatalln(err)
}
}
</code></pre></pre>DanChm: <pre><p>This is again really useful, I'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've been looking for a new language to learn for a while, and Go really struck the right note for some reason and I've been getting into it for the past couple days. One question I have, however, is in what contexts would Go's concurrency model be used in web development? I'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't seem like it for some reason, maybe it just doesn't get talked about too much. I find concurrency very interesting conceptually, so it'd be cool to learn about ways to apply it in a web context.</p></pre>weberc2: <pre><p>First of all, it'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'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's tricky to use correctly, and you have to take care not to call any blocking I/O. This problem doesn'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'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'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's a framework for building web applications in Go instead of a loose collection of single-purpose libraries (e.g., Go's std lib).</p>
<p>Go can also compile to JavaScript by way of GopherJS, but I don'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't know much about Gorilla, but I doubt it will give you JS UI components.</p></pre>PaluMacil: <pre><p>Part of the "not as many libraries" 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'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's fantastic choice as a first backend language.)</p></pre>MEAT_FIST: <pre><p>I like Go because there isn't a ton of "magic" that goes on between libraries (if you use the right libraries). My experience with Java was very dissimilar, there was always a ton of "just trust this library and call this method"; 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've worked with, the APIs are simple, there isn'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'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 "The best code is the code I didn't have to write" 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 "type juggling" then Go has many advantages over Java, Ruby, Python, Node.JS, PHP and co when it comes to writing "backends" especially highly concurrent applications. When it comes to the ecosystem, no question both Java and Python have way more libraries. I wouldn't do data crunching or data science in Go , but it'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'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'm better off with Node.js as opposed to Go?</p></pre>MrCowPie: <pre><p>for small business websites as a freelancer, clients don't really care what you use as long as you get things done. Furthermore it's unlikely you'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'll be times when hosting is already picked out and paid for before you get to it. And most likely it's shared hosting like godaddy, in which case you'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'll come across it if you create websites for a living. </p>
<p>I'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'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't care what language you use to accomplish a task typically. I would recommend Go for the simple reason that it's a fantastic language and the places it excels best are possibly being easy to learn, being easy to understand others' 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't know that I'd be an expert if I only used it on hobbies.
As far as Node and PHP go, I would discourage them. You'll learn enough JavaScript and TypeScript over time (if you're doing web) that you'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'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'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'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't there that I can see. If you'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'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'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 "back-end" but it'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'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'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
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传