13 ms·
I'm so conflicted by Go. If I want to write a website quickly, I'd use Python. If I were concerned about performance, I have Java. I write my systems stuff in C
by echelon 11y ago
I'm so conflicted by Go. If I want to write a website quickly, I'd use Python. If I were concerned about performance, I have Java. I write my systems stuff in C++ (Rust now). Is there a compelling reason for me to even learn Go? Is it better than Java in some measurable way? Should I take the time to learn it? Honestly curious.
- nkozyra 11y agoAt least for the Web, Go will match the conciseness of Python with the performance (almost) of Java. It takes a lot of cajoling to make Python a great backend for the Web. Since confounding downvotes, a tldr: closer to Python than Java.
- TheSwordsman 11y agoI'm not sure I fully agree it'll match the conciseness of Python. Go will be more verbose, for sure. If you start having to Marshal/Unmarshal JSON, it'll get pretty annoying pretty quick depending on the JSON format.
- nkozyra 11y agoGo's JSON marshaling can be heavy if you tie it to a strict struct versus, say, an interface. You can make it light, but yes, sometimes some reflection is necessary to utilize that data. For most web applications, JSON in or out is of a known schema, so this generally impacts other servers moreso than web applications.
- TheSwordsman 11y agoOh absolutely. I guess I was trying to call out that, depending on the API you are supporting, it can get hairy. If you are designing it from scratch, when starting the Go project, you can structure your JSON in a way that's easy to work with. If you're coming in to something that was easy to use in a language like Python, it may not be that easy in Go.
- nkozyra 11y agoI guess my point is it will be more concise than Java, certainly closer to Python.
- stephenboyd 11y agoAnd if you have to marshal/unmarshal XML, it gets worse. Go's XML library is buggy and its documentation recommends using JSON instead.
- millstone 11y agoGo is not concise, it is more verbose even than C++. Compare Python's list comprehensions to Go's for loops, or Python's sort() vs implementing Go's Sort interface, or Python's ternary operator vs Go's five-line if-else statement, or `if err != nil...`
- TheSwordsman 11y agoI wouldn't personally compare it to Java, having written it for some time. I too am not too fond of writing web apps in Go. It's doable, and you can do things to make it easier, but it can be painful. It took me some time to get in to the groove. I see it being used for system tools, to some degree, because it requires no runtime at all (static binary). It also seems to be pretty popular for different newer data stores. Again, if it's pure Go it'll run anywhere... so it makes development (and portability) much easier. I like its concurrency model, to a point. That said, I hope they really improve some things about in Go 2 (like working with channels and goroutines). I'm not sure when that will be. I use Go for a lot of things, most of which are command line applications. Whether it be interfacing with some sort of REST API, taking actions on the local system, or some sort of network client for devices on my LAN. It works well for quite a few cases. It seems to fit well with my mental model quite often, so I use it. And it's a simple language, so it was easy to get started with it. At the end of the day, it's a tool like many others. I think it's up to the creator to choose the tool that feels best to them.
- e12e 11y ago> I see it being used for system tools, to some degree, because it requires no runtime at all (static binary). This is something I haven't seen discussed much recently. Do people generally think static linking is a good idea for things other than self-contained system-level daemons? (Where that daemon and supporting libraries might be the only thing you deploy to a server/vm/container)? As I recently read in a (rather poor microbenchmark article) [1]: "The C assembly code I got with the following command is just 40 lines long. (...) The Go assembly code is 161.021 lines long which must be due to the static linking of Go.". As everyone (should) know(s) any kind of language that lets you write a useful program in a page or two of code, will include a runtime of some sort (or be depressingly machine- and kernel-specific assembly code, and probably slower than anything a modern half-decent compiler produce). But I don't see a lot of discussion on how you make sure all your go daemons get updated with a new TLS/SSL/GZIP/PNG/XML-library when there's new serious bug found. [1] Just included for reference, I don't really mean to pick on the author, but it's rather standard fare in the "quickly do a microbenchark; prove only that I'm wrong"-vein: http://karlheinzniebuhr.github.io/en/2015/09/28/C-vs-Go-vs-pypy-vs-Python/ http://karlheinzniebuhr.github.io/en/2015/09/28/C-vs-Go-vs-p...
- brightball 11y agoIt's a language that when compared to other languages it's the 2nd best at so many features that it gets the title of the most well balanced language. For the most part, it seems to have gained traction in the Ruby/Python/PHP world as a backend optimization language. IMHO that's where it currently fits best for most people.
- stephenboyd 11y agoIt's good for when you want to write something quickly and you're also concerned about performance. It's a deliberately simple language, it's designed so the most naive simple choice is often the best choice, and you can learn enough in one day to start developing productively. I've never tried to make a whole web app with it, but it's great for making microservices.
- viach 11y agoGo is less verbose than Java and more statically typed than Python, here you go.
- ihsw 11y agoSome people think Java is icky and other people think the JVM brings too much baggage for their comfort. Warranted or not, it usually fills the space where fast microservices are necessary. Personally I think Go's closest competitor is Scala. Coming from Python, Ruby, and TypeScript -- Go is a fair bit more verbose, and Java takes that a step further. So Go is a nice go-between from scripted environments to compiled.
- jpliska 11y agoHave you seen kotlin? Its a cross between java, python and scala for the JVM (and JS - with wrinkles)
- xaduha 11y agoEveryone should seriously consider using Kotlin, it's here to stay.
- minionslave 11y agoThe only thing I hate it the extra symbols. How to they justify using : val companyName: String = "JetBrains". Instead of string companyName = "Jetbrains" ?
- latch 11y agoI wrote The Little Go book [free], my first Go blog post was in 2011, and a few of my Go libraries are used by people other than just me. But Go's not my goto language. I'm a staunch believer in the productivity of dynamic languages. In my opinion, Go's less than stellar type system and weak reflection capabilities exasperate this gap, even moreso for most websites / apis (which deal with impedance mismatch at two boundaries). But, to answer your question. Consider first that Go's very simple to pick up. So the investment is small. Second, where I differ from you is on your second point: Java. I dislike it. It's complicated and verbose and gets in my way. Rust and Go are both proof that we know how to build better languages now. So, when I need to share memory across multiple cores and performance is a concern, I switch to Go because it's fast and simple.
- bogomipz 11y agoHi, could you elaborate on you comment about Go's "less than stellar type system"?
- latch 11y agoLack of generics (stick, meet dead horse) is at the forefront. Lack of very basic functions (map, filter, reduce) against slices. map[string]interface{} is pain to work with (one of the moderately popular libraries I mentioned helps: https://github.com/karlseguin/typed https://github.com/karlseguin/typed) Lack of immutability. I don't want to get into errors vs exceptions, but I've never heard a pro-errors argument that wasn't hand waving. I think the decision makes sense given Go's genesis (system programming), but given how Go's actually being used, it's a step backwards.
- bogomipz 11y agoThanks. Right, generics is a big one. But isn't Go actually being used for system programming? At least that what I think of when I think of Golang. Maybe the scales have tipped and writing api/microservices is the larger use case now?
- 11y ago
- deleted 11y ago[deleted]
- biomcgary 11y agoShould you take the time to learn it? Yes. It is a very small language, so learning will not take long. Go is a nice tradeoff in development time and performance that is only slightly slower to write than Python (for web servers) but comes with good performance out of the box.
- dominotw 11y ago> Is there a compelling reason for me to even learn Go? Yea if you are doing any devops and want to contribute to or use consul/docker/swarm/kubernetes/terraform.... curious if rust has a hit project like one of those above.
- tomphoolery 11y agoServo? :-) https://github.com/servo/servo https://github.com/servo/servo I mean, eventually...hopefully...
- coalescence 11y agoThat's the browser engine, for webapps, look here - http://arewewebyet.com/ http://arewewebyet.com/
- steveklabnik 11y agoPlease use http://www.arewewebyet.org/ http://www.arewewebyet.org/ , the .com has been abandoned.
- tomphoolery 11y agoIt's not better than any of the languages you described, but it's certainly different. Go was created in order to build large-scale distributed systems (like the largest search engine in the world), and the problems that Go makes easier to solve may not be the ones that you have. Unlike Rust, Go wasn't created to replace an existing language...it was created to replace an existing way of going about doing things. Unlike Python, Go wasn't created to make code easier to read in general, it was created to make incredibly complex code less ugly. So no, you shouldn't learn Go unless Go solves the problems that you need to solve. That said, as others have mentioned it's a pretty simple language and I found it quite easy to pick up and start writing programs in.
- iamgopal 11y agoMy strategy is to write very modular web app in python and when performance needed replace a module with go. Not only at that time specifications are mostly final, but most bugs are also covered. That way I get speed up the development of dynamic language and when needs a raise, use running speed of go language.
- dcu 11y agoI'd say go is just slightly harder to write than python and as fast as (or faster?) than Java. It takes a lot of less memory than Java and Python for sure. Easier to read than both. here's an interesting article: http://www.whitesmith.co/blog/why-i-started-to-use-golang-more-than-python-or-ruby/ http://www.whitesmith.co/blog/why-i-started-to-use-golang-mo...
- andersen1488 11y agoGo compiles to native binaries, and requires no overhead like the JVM.
- echlebek 11y agoLike the JVM, Go programs have a runtime that has overhead.
- jonathanoliver 11y agoSure it compiles to native binaries which doesn't require a separate VM install, but that doesn't mean it doesn't have overhead.
- NateDad 11y agoGo uses a lot less memory than Java, according to most comparisons. There's a lot of work going on in the cloud space with Go applications (docker, kubernetes, etc), so there's a lot of new libraries for networked webservers getting written. But mostly, you may find you just enjoy writing Go more than Java. It writes a lot like python... I switched from mainly writing C# to almost exclusively writing Go, and whoo boy, I'm not going back. No more huge class hierarchies, no more "everything has to be in a class"... no more "anything I call may throw and jump me out of my function in the middle and I have no idea if it will or not". There's just a lot of niceties of writing Go that don't exist in Java. Sure, there's a ton you can do in Java that you can't do in Go, but once you stop focusing on what Go can't do, you realize, it still can do pretty much whatever you want.
- vvanders 11y agoJava memory usage is not really that high if a bar to beat. Dropbox just rewrote parts of their Go infra into Rust explicitly because of the memory savings they needed.
- NateDad 11y agoWell.. yes, exactly. The question was "why should I learn Go if I know Java?" That's a pretty good reason.
- ngrilly 11y agoYes, but the rewrite would have happened ever sooner if the original code had been written in Java instead of Go. The Dropbox case is really very specific and very low-level.
- golergka 11y agoAnything you call in go can panic, what's the difference?
- danieldk 11y agoAnd nearly anything you can call in any language could theoretically exit(3). The difference is that exceptions are a normal control structure in C#, Java, or even C++, while the use of panic should be exceptional. It's not considered the regular way to report an error. Of course, if you have checked exceptions (which are for some unfathomable reason considered bad nowadays), nothing just throws an exception. Moreover, you don't know for sure whether a Go library correctly handles errors, because it's so easy to ignore them.
- echlebek 11y agoGo has concurrency features that the other languages you mentioned don't have. The select construct is a very nice language feature and allows a surprising amount of power. Go's compiler is very fast, which saves a lot of time in aggregate. Go exhibits good design in many areas, including the core language, the compiler toolchain, and the standard library. You can write a complete server-side web application using only the standard library, and it won't be terrible. Go is generally easier to learn than C++ or Java, and requires fewer concepts and fewer steps to produce a working program. A person who has written programs in Java or C can probably learn Go in about a day. Go's spec can be read in one or two sittings. The way to write "good" code in Go is usually obvious. I've spoken to some detractors of Go and can understand where they're coming from. Erlang and Elixir users tend to not find Go's concurrency features compelling. Functional programmers will not find that Go provides much in the way of expressive power. Java programmers have expressed concerns about the Go garbage collector, although I think a lot of those concerns are now at rest. For those that enjoy the set of tradeoffs that Go makes, it's a nice way to engineer software. edit: typo
- pjmlp 11y agoJava programmers also know a thing or two about java.util.concurrent, parallel streams, futures and Quasar. The only thing Go concurrency has over them is that it is easier to start with, but it isn't easier to use any other pattern, because Go doesn't allow library code to be first class in the type system.
- brightball 11y agoGo also has much lower RAM overhead with that concurrency.
- pjmlp 11y agoAssuming a JIT/AOT compiler that doesn't do escape analysis, which varies across JVM vendors. Also Go's advantage in using value types will vanish when Java finally gets to have them, although we still need to wait for Java 10 for them, while Go is available now. So Go does have a few more years to gain developer mindshare. Still Java isn't the only game in town, and there are other alternatives with GC, value types, more expressive type systems and battle tested concurrency frameworks.
- dgacmu 11y agoThere is - Go is a terribly fun language in the domains that it's good at. Like some other fun languages, if you take the time to get into 'the go way' of doing things, you'll get a new perspective on some kinds of programming that'll help you in general. Go is drastically less bloated than Java. Stupidly fast compilation and running lets you use it almost (but not quite) like you might Python for some things. A recent example for me: Writing a quick & dirty server that talked to a device that was spouting a stupid binary serial-over-TCP protocol. Goroutines made handling the bidirectional communication trivial, and go being a bit on the low-level side makes it easy to cope with binary protocols without worrying that your chars and bytes and unicode characters are getting all mixed up. You can do all this in Java - but it's so clean in Go. My current playbook looks something like: Network servers: Go. Go go go and more go. Things that talk to lots of other things and involve interesting communication are a natural match. I rewrote my pi searcher in Go a year or so ago, for example - http://da-data.blogspot.com/2013/05/improving-pi-searchers-speed-by-moving.html http://da-data.blogspot.com/2013/05/improving-pi-searchers-s... - and this year was able to run the thing through Pi day on only a single (larger) AWS instance. Woot. We use it for research, such as writing Paxos derivates. Great stuff. Go's also pretty amazing for little utilities if you want them to be faster than Python -- particularly if you want the launch time to be faster than Python. Which can be great for utilities you build to use in loops in shell scripts, etc. The fact that they're purely statically linked makes a lot of otherwise hairy cross-platform nastiness just go away. The fact that it's statically typed and includes great, easy-to-use parsing support for itself also makes it much better for refactoring than Python is. The tools aren't as mature as those for Java, but the language is well-designed to support it (think "go fix" -- which can automatically port forward much old code to newer versions of the language). The tooling for this kind of thing is great for Java, good for C and Go, and absolutely horrible for Python. As a consequence, Go can more roubustly handle being worked on in very large codebases and teams. What would be a slightly scary regexp replace in Python can be a much more syntactically and semantically safe change in Go (at the cost of a little more writing of the replacement code). Tensorflow (and most things numeric): Python. Because it was pre-decided. :) But, more seriously, Go's lack of generics hurt it here (you can't express matrix/tensor manipulation natively, and saying A * x is about as right as it gets when you're talking math). The ML community has adopted Python to a pretty strong degree, particularly because of NumPy, and so it fits in really well there. I still get grumpy about it -- I've lost count of the number of times I've messed things up that static checking could have caught, requiring quite a long time for tests/running it to finally do so. But I do like Python, to the point of: Beginners: Python. I pushed hard to switch CMU's intro course for non-majors to it, and succeeded with a lot of help from others. It's awesome seeing what a bunch of motivated, smart first-years can accomplish in Python in one semester. Damn. And they can 'take it with them' -- scientists/engineers and numpy are a pretty good match, for example. Fast as hell: C++, light on the ++, heavy on the C. A lot of our research code is very low-level. I'm still finding Rust incredibly annoying, but I may just be a slow learner, and it's on my list to take a really serious look at it after I'm back from Google. (You'll note that nothing that I do involves a UI. I'm a unix & systems person through and through, which helps explain the utter lack of Java, C#, Swift, etc. in my life.)
- beefsack 11y agoI actually find web applications a fairly weak use case for Go, it's never incredibly pleasant to do. Network services in general are very compelling, mainly because of the strong standard library.
- out_of_protocol 11y agoI'm totally ok with building services and cli tools using Go but it's not gonna work for web apps - situation is dire and that's ideological position - i.e. don't expect changes there :/ Basically DIY everything outside standard library ( e.g. section 9.1 building CSRF) Personally switched to http://www.phoenixframework.org/ http://www.phoenixframework.org/ for json apis/web apps
- buro9 11y agoI write in Go, and for me it is the sweet spot between all that you've said and only required a single language and a single tool chain. There is little more to it than that.
- wfsfw4w44 11y agoSince go is a compiled language, you get the benefit on zero startup cost, which you pay when using JVM or NET, or even Python.
- pjmlp 11y ago> which you pay when using JVM or NET Except Java and NET developers worth their salt are aware of ways to AOT compile their code to native, thus enjoying the same startup time as Go.
- jjnoakes 11y agoIs there a non commercial cross-platfornlm way to aot compile Java?
- pjmlp 11y agoThere used to exist GCJ, but its development died when the main developers joined OpenJDK development or moved elsewhere, back in 2009. There is still the RoboVM version before it got acquired by Xamarin. There are also Avian and JikesRVM, but it depends a bit what features you are using. The problem with Java non-comercial AOT compilers is that the majority of the Java shops that really care about AOT compilation don't mind to pay for it, so there isn't a real effort to invest on a free AOT compiler. The lack of community support for RoboVM was a good example of it. Even the upcoming AOT compiler in the official JDK will be a commercial feature, at least it was announced as such.
- jjnoakes 11y agoIs there a non commercial cross-platfornlm way to aot compile Java?
- twic 11y agoIf you (and your team, if applicable) already know that set of languages, then there's no reason for you to learn Go. Indeed, if you already know Java, the only reason to learn Go would be if you had a burning need to produce self-contained statically linked binaries. For example, at my company, we have a habit of producing command-line clients for our services, and Go is a good choice for that. Go has been most useful for people who know a dynamic language like Ruby or Python, but who are encountering problems where they need more performance, better concurrency, or stronger static guarantees. Go improves over dynamic languages in those respects, and it's pretty easy to learn, so it's a great addition to their toolbox.
- ngrilly 11y ago> If you (and your team, if applicable) already know that set of languages, then there's no reason for you to learn Go. Google is the perfect counter-example to your argument. C++, Java and Python were the 3 main programming languages in use at Google, and despite that, they designed Go and started using it instead of C++/Java/Python in some projects. Go can be used instead of C++ when you need and can tolerate a garbage collector, and you don't need things like a custom memory allocator. Go can be used instead of Java when you need a native executable, statically linked (like you wrote), when you need a better control over memory layout (especially to reduce pressure on the garbage collector), and when you need async IO without callbacks/promises/futures.
- FordPrefectAO 11y agoWell one reason [1] Google made go was because of how many junior engineers they had who couldn't be trusted with java/python/etc. Instead of letting them struggle, they created go as a more simple and easy to use language. [1]http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2014/From-Parallel-to-Concurrent http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2014/Fro...
- freyr 11y ago> Is there a compelling reason for me to even learn Go? ... Should I take the time to learn it? One thing to consider is that the language is purposefully small, and you can learn the basics very quickly. Spend a day with it, and you'll get a feel for the language syntax and maybe some exposure to the standard library. You'll have a sense then whether you want to pursue it further. So if you're curious, the compelling reason is that you can satisfy your curiosity without much effort, and that will ultimately be more satisfying than asking strangers to convince you one way or the other.