8 ms·
Well, it's good to have a hard-compiled language that's (almost) memory safe. Three problems with Go: - The Go mantra is "share by communicating, not by sharin
by Animats 12y ago
Well, it's good to have a hard-compiled language that's (almost) memory safe. Three problems with Go:
- The Go mantra is "share by communicating, not by sharing". Then look at all the thread examples in "Effective Go". They all share memory, while trying to construct locks using message passing. Multi-threaded Go programs are not memory-safe. That's why Google won't let you use them on their AppEngine. Compare Erlang, which takes message passing seriously.
- The lack of exceptions is resulting in hacks using the "panic" mechanism to create an exception mechanism. This is where we were with "longjmp" in C. I know someone at Google who has constructed a language on top of Go mostly to deal with exceptions.
- The lack of generics is resulting in hacks using the reflection mechanism to create generics. This is painful and slow. Go has generics for built-in objects; channels and maps are parameterized types, so there's already syntax for instantiating a parameterized type. Extending that to user-defined types would not be too bad. Fear of the C++ template mess seems to have been the problem.
- kyllo 12y agoRust addresses all of these problems. It's memory safe through compile-time reference counting and borrow checking (not garbage collected), and it has exceptions and generics. It also has a more powerful type system with type inference. Having tried out both Go and Rust I don't see any reason to prefer Go, at least once Rust has a 1.0 release, which is supposed to happen the next 2-3 months. Both languages were designed to replace C++, but only Rust has the features to actually succeed at that, IMHO.
- higherpurpose 12y agoI think at this point Go is more of a replacement for Java than C++.
- kyllo 12y agoPerhaps, but the problem is, with no generics or exceptions, it might just be too low-level and not expressive enough to really be a suitable Java replacement.
- agmcleod 12y agoYeah i just see Go as an alternative for web technologies, where Rust is much more system level focused. I could be wrong, but that seems to be the direction I see with Rust.
- naasking 12y ago> Yeah i just see Go as an alternative for web technologies I don't see any web technology Go could replace. Not even dynamically typed langauges.
- vec 12y agoI'm starting to use Go as an arguably better Node. Very fast, easy (pseudo)concurrency, relatively nice HTTP capabilities in the stdlib. It wouldn't be my first choice for building a full library, but it works well as an internal component in a service oriented architecture or a background worker for a queuing system.
- sagichmal 12y agoGo is very uncontroversially a better Node. It also predates Node.
- spion 12y agoDepends on what you mean by "better". Better language? Not really, if you want types TypeScript is a much better option. With node+typescript+react you can get end-to-end typechecked code with no FFI involved - thats really, really cool. Better concurrency? Oh yeah, definitely. Better core libraries? Yes, by far. Better package ecosystem and management? Definitely not.
- sagichmal 12y ago> Better language? Not really, There is no conceivable universe in which the expression "JavaScript is a better language than Go" evaluates to true.
- pjmlp 12y agoGiven how the JVM ecosystem looks like and what is planned for Java 9+ in terms of mechanical sympathy, I have my doubts.
- tptacek 12y agoPeople love to say this, but the observation falls apart quickly under scrutiny. People working in Java are doing so to retain access to the JVM and to the zillion libraries built on it. The JVM with its ecosystem is a colossal asset for Java; one of the greatest in all of commercial software development. (I say this as someone who does not enjoy Java). Meanwhile: Golang neatly fills in a sweet spot just "below" Python and Ruby, where finer-grained control of memory and more predictable performance characteristics are required, but bare-metal performance isn't. That sweet spot actually describes a huge fraction of all the use cases for C/C++ in Internet software. So this is a meme I'd like to see die. It somehow manages to simultaneously get Golang, Java, and C++ wrong all at the same time. The only way to make it worse would be to work in some kind of Lisp comparison, based on Golang's parsimony with parenthesis.
- threeseed 12y agoCouldn't agree more. Anyone who thinks Go will ever be a replacement for Java is frankly clueless about enterprise software development. Go has almost non-existant integration with enterprise systems e.g. SAP, Hadoop. It lacks operational management capabilities e.g. JMX. And seriously the range of libraries on the JVM covers pretty much everything e.g. banking/finance use cases. And concerningly there is not a single reasonably sized Go project to get an understanding of how it works with 20, 50, 100 or 500+ developers working on the same codebase.
- kasey_junk 12y agoI think when people claim that Go is a replacement for Java, what they really mean is "Go has similar performance characteristics as the JVM and also doesn't require manual memory management". Anyone who has ever worked in enterprise software can tell you, Go is (currently) exceptionally poorly suited for that style of development. I don't think that is an accident though. I think there is at least the implication that enterprise software development models and architectures are flawed at the core. Go seems to be designed from the start to prevent you from developing that way. I may be reading more into the Go culture than I should, and I certainly don't think that there is proof that enterprise software can't be successful, but Go clearly steers you into building small, self contained servers that do one thing well and can go without change for a long time.
- rakoo 12y ago> Both languages were designed to replace C++ AFAIU Go was designed to replace C++/Java/Python as _the_ language to use at Google, not as languages themselves. Which is why there is so much focus on simplicity, tooling, productivity (like compile speed and easy deployment). Criticizing Go for not having enough features is missing the whole point: Go was created in part because C++ has too many features. To my understanding, it was built for systems creators, not for programmers; it was built as a goto language who have to write program that is both efficient and simple to write and maintain. OTOH, I do see Rust as a C++ replacement, which makes it complementary to Go's focus (sadly it seems that D is lost in the middle, though...)
- doorhammer 12y agoThis is the feeling I get. I don't write much Go (I'm just now getting into it) but all of the major features I hear about seem to be directed at creating code and projects that are tractable at "Google Scale". Everything has been designed for massive teams, from fast compile times, or having a standard formatting scheme, to choosing syntactically insignificant whitespace (specifically the podcast mentioned finding instances where python snippets were embedded in another language somewhere which would shoot the whitespace to crap). The language being dead simple also seems to be to that end, with things like removing ternary operators or not having the pre-increment being smaller sacrifices, and no generics being a larger one. All in all it seems like the underlying philosophy of Go is focused on Google specific context and engineering goals, and it's a happy accident when they work out well for programmers in the general case, whereas something like C++ or Rust isn't catering to those specific parameters (though they're obviously capable of working in that role, perhaps just not in the "ideal" way that the Go language maintainers would prefer).
- threeseed 12y ago> Everything has been designed for massive teams Weird. Because I see the opposite. Go would be fantastic for microservices or targeted applications. But features like exceptions are critical when you have 100+ developers spread across the world working on the one codebase and you want to ensure consistent error handling behaviour across the application.
- steveklabnik 12y agoWhy do you say Rust has exceptions? We have fail!(), which does roughly the same thing as Go's panic(). So much so that we decided to rename it to panic!().
- kyllo 12y agoYou're right. I must have misunderstood something I read.
- steveklabnik 12y agoCool :)
- kyllo 12y agoAhh, I remember what it was. I saw a code snippet like this: let input = reader.read_line().ok().expect("Failed to read line"); And I thought "Cool, Rust has exceptions!" I'm probably too used to thinking in Python. Or maybe I'm just dyslexic and I read "expect()" as "except()". Either way, your comment prompted me to dig into it further and find out how Rust actually handles errors. So, thanks!
- steveklabnik 12y agoThanks for elaborating! I wrote that line in the docs, actually. I wonder if I should add an explicit note about exceptions not being a thing.
- gabriel-aszalos 12y agoWhat are generics?
- commentzorro 12y agoThey're a repressed memory from a less austere time.
- charlieflowers 12y agoThe ability to use type parameterization to create a type with one or more "holes" in it that is filled in at declaration time. For example, a type that is a List of ints would often have almost exactly the same code as a type that is a List of strings. But without generics, you have to write it twice (or copy/paste, use code generation, etc.) With generics, you say "List<T>", and the compiler makes it work for both List<int> and List<string> (and pretty much any other type you substitute for T). (There are various ways of making it work under the compiler can use under the hood).
- pjmlp 12y agoWell, at least it can replace 90% of the use cases one would use C for. I am leaving those 10% for kernel code and portable macro assembler tricks. Even with my position regarding generics in Go, I have to agree interface {} is way better than void* or macro tricks. EDIT: Should mention that those 10% also include embedded deployments where ANSI C barely fits.
- 23david 12y agoFrom what I've seen lately, Golang programs take up too much disk space to replace small C utilities that are used in lightweight or resource-constrained environments. Memory usage also tends to be much higher, but that may be less of an issue since it can be optimized through careful profiling. I haven't seen any way to really optimize disk usage yet... I hope I'm wrong though. It'd be exciting to see Golang equivalents of optimized C utilities that come close to using the same disk and memory. Or maybe there's an embedded golang compiler in development that does a good job of optimizing for these use cases...?
- Blackthorn 12y agoI don't see how that's all surprising. I'd be surprised if a Go program without the explicit goal of being tiny managed to compete on disk size and similar metrics with something like Busybox, which has the explicit goal of being tiny.
- deleted 12y ago[deleted]
- kyrra 12y agoSingle-threaded Go programs also run faster for some (many?) cases. The runtime is able to bypass a number of locks when running in a single-threaded mode. And depending on the profile of your code, turning on multiple threads for a Go program can slow it down even if you use channels (as moving data from one CPU core to another can be much slower than just doing a context switch in a single core).
- sagichmal 12y ago> The Go mantra is "share by communicating, not by > sharing". Then look at all the thread examples in > "Effective Go". They all share memory, That mantra is spoken in the context of concurrent code, not as a general axiom of the language. And I think it's remarkably well sustained in all of the concurrency examples I've seen so far. Can you be a bit more specific? > The lack of exceptions is resulting in hacks using the > "panic" mechanism to create an exception > The lack of generics is resulting in hacks using the > reflection mechanism to create generics. At the risk of making a No True Scotsman fallacy, idiomatic Go code does neither of these things.
- Animats 12y agoSigh. First example of channels in "Effective Go" shares the list to be sorted between two goroutines. https://golang.org/doc/effective_go.html#sharing https://golang.org/doc/effective_go.html#sharing All that's sent over the channels is a flag message to start the process and report completion. Yes, there's the fanboy answer that they're not "really sharing" because both threads don't access the list at the same time. I've heard that excuse. The threads are sharing data. Deal with it. Locking is (hopefully) provided by abusing the channel mechanism to simulate a semaphore. The channel mechanism isn't doing anything here that a semaphore couldn't do better.
- xkarga00 12y agoActually the Effective Go page needs to get updated. They also comment next to c <- 1 that value does not matter where the use of a struct{} channel would be more idiomatic. But still the Go mantra is valid, the means (channels) provided by the language allow for sharing by communicating and IT IS actually considered idiomatic where appropriate. Also your points about exceptions and generics are non-valid or at least very specific cases. I am working on backend stuff (mostly command-line tools) and i never felt any "lack" of them.
- skybrian 12y agoIt's rather unfair to complain that they're simulating a semaphore when they explicitly said that this is what they're doing.
- lazyjones 12y agoPeople always forget that sane language choice isn't ticking checkboxes on lists of features. If you actually program in said languages, you'll learn to appreciate maintainability, the time it takes you to get something right and the general pleasantness doing so, which is where Go shines (but you'll have to actually use it to see that). Perhaps you'll be one of the 5% users who will actually miss generics or cannot work without exceptions (even though Go's error handling makes perfect sense without them, it's just a different approach), but it's not very likely.
- threeseed 12y agoAnd you seem to forget that exceptions, generics etc all affect maintainability, time to get something right and general pleasantness. Those "list of features" are pretty important for many people. Go is basically Java 1.0 + Quasar. At some point Go will "grow up" and start adding these features and people like you will fall by the wayside.
- _ak 12y agoEven if Go added exceptions or generics, people would still complain because something would be different from how they expected generics or exceptions to be. If you want a specific language, then just use that one, but don't try to impose your expectations on other languages.
- eloff 12y agoThankfully the go language designers were more focused on practicality than purity. Shared nothing concurrency is nice in theory, but it is so slow by comparison to just sharing memory between threads. But then I write high performance servers and concurrent data structures using lock free algorithms (including in go), where even a mutex is a luxury, so maybe the problems you work on are very different to what I work on. But I'm very happy go can accommodate the evil things I do in the name of performance.
- Animats 12y agoFear of copying overhead can introduce more performance problems than copying overhead. Modern CPUs are really good at copying, which, after all, is completely parallelizeable. If you just created some data, and then pass it to something else by copying it, and it's immediately used there, it will probably still be in the fastest level of cache. At least if the message passing and CPU dispatching are properly connected. QNX gets this. Almost nobody else does. The reason for having subroutine-like IPC, rather than "send on channel A, then wait on channel B for reply", is that the scheduler can immediately transfer control from sender to receiver. If two unidirectional channels are used, you have the sender and receiver threads both in ready-to-run state, which means a pass through the scheduler for somebody, and possibly a handoff to another CPU, with all the attendant cache misses. A good test of an IPC system is to have one thread calling another as a service, with control going back and forth rapidly, while other threads are compute-bound. If the presence of compute-bound threads kills IPC performance, it was done wrong.
- andrewmwatson 12y agoThey most certainly do let you run Go on AppEngine!
- cmelbye 12y agoHe didn't say Go. He said multi-threaded Go. GOMAXPROCS=1 on App Engine.
- deleted 12y ago[deleted]
- cmelbye 12y agoCan you expand on why App Engine doesn't allow multithreaded Go programs? I never quite understood what they were trying to prevent you from doing.
- Animats 12y agoHere's a description of the race condition exploit: http://research.swtch.com/gorace http://research.swtch.com/gorace