9 ms·
Can someone explain? I'm a big fan of C and python and I've never used Go. My initial impressions from readings were that Go is a better C. But then I came acr
by fizixer 12y ago
Can someone explain?
I'm a big fan of C and python and I've never used Go. My initial impressions from readings were that Go is a better C. But then I came across a Go person who was lamenting that misunderstanding and that Go is python but with better performance. What's it all about?
Also even if we compare it to C I don't like the garbage-collection thing at system level. Also what does Go let you do in terms of garbage collection that cannot be done with a C gc library (which anyone can use if they want but then also have the choice to do raw/manual memory management if they want too).
- schmichael 12y agoThe comparison to C has always struck me as strange. It has curly braces and pointers, but few semicolons, no pointer arithmetic, garbage collection, and tons of high level language primitives (maps, slices, channels, select, goroutines, a userland scheduler). Many people, myself included, find it a wonderful language suitable for all sorts of service development whether it's data processing systems or web APIs.
- bkeroack 12y agoI love Go and I consider it to be the spiritual successor to C, in a way (sort of an anti-C++, which the creators have said they used as an explicit example of what not to do). Given that it was co-created by Ken Thompson (of Unix/C/Plan9 fame), I think the comparison is justified.
- jimmysawczuk 12y agoAnother similarity is that both Go and C compile to dependency-free and portable binaries with no VM needed to run them. In my mind, that's the biggest similarity. And regarding semicolons: you don't use them as much while coding, but the lexer puts them in for you, so they're there on some level.
- nkozyra 12y agoI think the general idea is C++ (not C) in the style of Python. You still have access to memory/pointers/unsafe, it shares a C-style syntax (go ahead, put in the semicolons if you want!), is compiled but offers the gentle, elegant watchfulness of a Python-like scripting language. In most cases it can be a relatively drop-in replacement for C++ or Python as a binary. It will never be like C in that there's a lot of overhead and lack of memory control for embedded systems, so you probably can't treat it as a C competitor in any way.
- mseepgood 12y agoI would say it shares some design philosophy with C: simple, "New Jersey style", imperative, pragmatic, non-generic, explicit control flow.
- cosn 12y agoLike any other language, there're some pros and cons with Go. For example, C gives you complete control at a very low level, but can make higher-order operations more complex. On the opposite end of the spectrum, Python removes a lot of that friction at the cost of doing more things behind the scene, which obviously affects performance. I regard Go as somewhat in-between -- it provides you with some of the lower level constructs (like pointers) but also reduces complexity (by giving you goroutines, for example). Specifically about garbage collection, I'd recommend taking a look at what's coming up in 1.4: https://docs.google.com/a/stripe.com/document/d/16Y4IsnNRCN43Mx0NZc5YXZLovrHvvLhK_h0KN8woTO4 https://docs.google.com/a/stripe.com/document/d/16Y4IsnNRCN4...
- loudmax 12y agoGo was originally pitched as a better C, but it seems to be finding a niche as a better Python or possibly a better Java. Go binaries have built-in GC, and Go will probably never reach C levels of performance. There is a lot to like about Go and it is working out very well for a lot of people, but it isn't appropriate for every situation. If you want a better C, better to look into Rust: http://www.rust-lang.org/ http://www.rust-lang.org/
- jff 12y agoRust looks a lot more like a slightly more sane C++, given the proliferation of Someclass::Somethingelse
- pcwalton 12y agoRust doesn't have classes.
- deleted 12y ago[deleted]
- deleted 12y ago[deleted]
- higherpurpose 12y agoWhen Google will completely deprecate Java for Go on Android (could be a number of years, if ever), then Java should imminently become irrelevant (over a number of years, maybe a decade, or maybe it will never disappear completely, but the point is it will rapidly decline with new and existing developers).
- pjmlp 12y agoGiven Android's core team statements at Google IO 2014 about Java being the only official language, with no plans to improve the NDK beyond the existing support, I find it very hard to ever happen. Unless Management forces the team to change their mind, that is.
- NateDad 12y agoGo is a very pleasant language to develop software products in. Unlike the dynamically typed languages, it doesn't trade speed for beauty of syntax. This means that sometimes syntax can be a little non-uniform, but there's always a reason. Unlike C and C++, it doesn't trade safety for speed of execution. There are no buffer overflow vulnerabilities in Go applications. It treads a fine line of where to let the language do the lifting and where to make you do it. In general, it does a really good job of finding the pragmatic side of the line to sit on in any particular situation. I don't know of any widely used C garbage collection libraries. The benefit of it being a language-level is that everyone uses it, which means your code works the same as everyone else's, so you can easily just reuse other people's code, without having to restrict your search to some small subset of repos that use your particular GC Library. Also, in Go, unlike most other garbage-collected languages, there is a stack, and you can pretty easily write code that only uses memory from the stack, and never needs to run GC. Finally, Go's tooling is really phenomenal. Testing, doc generation, performance reporting, code coverage, linting, package distribution, code formatting, refactoring, cross-platform compiling, and soon, pre-processing, are all built-in and really well done.
- kyrra 12y agoThe toolchain part of Go is very interesting (I only know the basics). Go doesn't use GCC, LLVM or other existing compilers. Go's compiler/linker originated from the Plan9 C compiler (that Rob and Ken worked on)[0]. Because of this, it allows you to create binaries for any target platform from any platform you have the Go toolchain on. So from my OSX macbook, I can compile Windows and Linux executables. When you start diving into it a a bit more, you'll see that Go has it's own ASM language[1] that your code is first compiled into (which then can be translated into specific os/platform asm). This has it's own ups and downs. Debuggers don't work all that well on Go generated executables (gdb is the closest, even that one isn't all that great). You also don't have the years of optimizations that GCC and LLVM bring to the table. But the Go team has tight control of the tools, which allow for quick compilation and allow them to pick their own direction. [0] https://golang.org/cmd/gc/ https://golang.org/cmd/gc/ [1] https://golang.org/doc/asm https://golang.org/doc/asm
- 12y ago
- chc 12y agoA C garbage collection library generally has to be very conservative because most C code is written with the assumption of not being garbage-collected. Having GC built in allows you to do more aggressive collection without worrying about breaking code that assumes it has precise control over memory. There's a reason why even people who like garbage collection don't tend to use garbage collection when they write C.
- kyrra 12y agoThe Golang FAQ will help answer your questions about some of their design principles[0]. Rob Pike also has some interesting views on why Go seems to attract Python and Ruby devs rather than C and C++ devs[1]. [0] https://golang.org/doc/faq#What_is_the_purpose_of_the_project https://golang.org/doc/faq#What_is_the_purpose_of_the_projec... [1] http://commandcenter.blogspot.com/2012/06/less-is-exponentially-more.html http://commandcenter.blogspot.com/2012/06/less-is-exponentia...
- methodology 12y agoGo's syntax and semantics seem ad-hoc, hard to remember, and inconsistent, but that's because Go was designed from uses cases and experience by prominent thought leaders such as Rob Pike and Ken Thompson, and Google. For example, sometimes you'll get Unicode code points, but sometimes you'll get bytes of UTF-8. The language was designed to give you the right one in the right case. UTF-8 is coupled with the language because it's the most useful choice. Another example is that pointers are automatically dereferenced, but not when you have pointers to pointers, because that's less useful. If any thread runs in an infinite loop that doesn't call built in functions, the entire runtime will freeze. But this is by design. You're meant to do actual useful stuff in your loop such as calling IO functions (which will yield to the scheduler) or calling GOSCHED. It was designed to compile fast, and compiles faster than most languages and still has near C-speed. It doesn't have a GIL so it has better concurrency (Java style memory model). It has no complicated features like generics, instead you just use type assertions when you need. It also has impeccable tooling.
- enneff 12y ago> If any thread runs in an infinite loop that doesn't call built in functions, the entire runtime will freeze. That's not entirely true. Go 1.3 introduced pre-emptive scheduling, so now only the most trivial (useless) of infinite loops will hog the scheduler. But if you're doing real CPU-bound work you won't block other goroutines from executing.
- methodology 12y agoCorrect, pointless programs like this freeze but that's by design since they're pointless: package main import "fmt" func main() { go func() { for ;; {} }() for ;; { fmt.Println("still here") } } Even bigger pointless programs also freeze: package main import "fmt" func f(v int) int { return v+1 } func g(x int) int { if (x > 100) { return 1 } return 0 } func main() { go func() { for ;; { if g(f(111)) == 0 { break } } }() for ;; { fmt.Println("still here") } } This is of course by design, because Go was designed only to support useful programs. The programmer trying to figure out how the concurrency model works may whine that it's inconsistent and he can't figure it out, but that's only granted because threading is hard. Go makes it easier by only supporting useful cases.
- bad_user 12y agoFor me, touting a language as being "Python, but with X" is a big turnoff. I worked for about 2 years in Python and hated most things about it - from the whitespace sensitive indentation that led people to write really long lines and the limited expressive capabilities forcing people to do meta voodoo in their libraries leading to incomprehensible DSLs, to the legacy that sticks like "old-style vs new-style classes", to the performance problems and the sad state of libraries in the ecosystem, let alone the complete cluster-fuck that is dependency and deployment management on top of Python. So you know, I want to hear about languages that are not like Python.
- NateDad 12y agoOh, then you'll love Go. It's nothing like python. At least, not like the python you've described above. Go is actually quite different from python in a lot of ways. Most of the stuff you hate about python does not apply to Go in any way. You can't really make a DSL in Go - there's no operator overloading, no meta classes... no classes at all. The performance of Go is an order of magnitude faster than python and only a few times slower than C. Dependency management and deployment are trivial - Go compiles to a standalone binary with no dependencies (except sometimes libc depending on what you're using). So... Go is nothing like Python. When people say it is, what they mean is, Go tries to make its syntax really obvious, and make life pleasant for experienced developers writing software in the language.
- p0nce 12y agoGo is a slower C[1] with worse syntax and oversold ideas. Stockholm syndrom is a builtin feature that comes with it and not much else. It doesn't provide basic stuff like generics, warnings, or exceptions because the authors want to make a bold statement about how they are in the Right and their potential users are wrong. Meanwhile system software will continues to be built in C and C++ since Go addressed some real problems with system programming but created new ones. Go was explicitely created for the average programmer like is said in videos talks. It is a dumbed down language to address the maintenance problem through tools instead of through better craftmanship. Go isn't very successful at Google but in startups who could do technically anything and still have the same outcome. As always with the HN hype: Do. Not. Listen. [1]: http://benchmarksgame.alioth.debian.org/u64q/go.php http://benchmarksgame.alioth.debian.org/u64q/go.php
- abritishguy 12y agoyour entire comment is crap but the following bit definitely is: >Go isn't very successful at Google Go is used heavily for networking and server stuff at Google. The entirety of dl.google.com runs on go (ported from C).
- pjmlp 12y agoThere are currently three public projects. - dl.google.com - vitess - Google App Engine, that used to be maintained by someone on the Go team not the Google App Engine team, if the Google IO information is still valid. Chrome is focusing on Dart support and Android team was very explicit at Google IO about Java being what really matters. So any other very successful Go projects at Google that can be shared? EDIT: For those that bothered to provide answers. Thanks.
- abritishguy 12y agoyoutube.com Most of the places it is used are not public facing stuff they are low level network systems which is what it was designed to be good at.
- laumars 12y agoIf I had to summarise Go; I'd say it does most things better than most languages but doesn't do anything significantly better than specific languages. Which isn't very exciting but it is generally what people want. Something that's a good enough multi-purpose language to cover normal use cases. And in the rare examples they need something more niche, then there's other languages that will serve those functions better.