342 points · by reillyse · 2y ago · 511 comments
Staying in that lane. In my part of the world Go is seeing adoption that no other “new” language has exactly because of its simplicity. It’s not the best language, but it’s often the best general purpose language because it has a lot of build in opinions which protect you from yourself.
No stacktraces and error wrapping forces you to not only invent unique error messages. You must also conceive a unique wrapping message at every call-site so that you can grep the error message and approximate a stacktrace.
The weird "return tuple" , which obviously just exists for errors because there is not a single other place where you can use tuples in the language, and the awkward variable initialization rules, make it so that you use the wrong `err` var at some point. E.g. if you want to reassign the result to an existing var, suddenly you have to declare `var err error`, and if `err` already exists then you have to reuse it.
There should be an enum type in go, or instead of the bizarre "return tuple" mechanics exclusive for errors, they should have added a better syntax sugar for errors like rust's `?` sugar. Instead we have something extremely tedious and quite error prone.
> it has a lot of build in opinions which protect you from yourself
It does have opinions, but too often they seem to be there to protect the language from being criticized. Sadly, this works, as marketing (lying) is an important factor towards making a PL popular in today's market.
MRV, go does not have tuples.
Go is not the only language with MRV (as a special case) and they’re not necessarily bad, iirc Common Lisp uses them as auxiliary data channels and has a whole host of functions to manipulate and refit them.
Go is singularly incompetent at MRVs though, in the sense that only syntax and builtin functions get access to variable arity (e.g. if you access a map entry you can either get one return which is a value, or two which are the value and whether the key is/was in the map). So MRVs mostly end up being worse tuples infecting everything (e.g. iterators needing Iter and Iter2 because you can’t just yield tuples to for loops).
> MRVs mostly end up being worse tuples
I think you noticed yourself that you’re getting too hung up on terminology. Multiple return values are a half-hearted, non-reified version of tuples.
Acronym for Multiple Return Values https://gobyexample.com/multiple-return-values
It's a plus versus minus type of situation, where both have their advantages and disadvantages, along with a number of workarounds and alternatives that can be used.
In many cases, people can return arrays, hash maps, or structs in place of tuples. That looks like the reasoning in Go, where if the person needs something beyond MRV, they can use the other options available. Go and various other languages, didn't need or didn't want to lean on tuples as much.
The tenet "accept interfaces, return structs" is violated all over by returning the `error` interface.
IMO it's okay to make behaviour-exceptions specifically for error handling. Rust for example doesn't really have builtin behaviour exceptions specifically for errors, they're generic to sumtypes and just happen to work well for errors. But then in practice you must resort to thiserror or anyhow helper crates to deal with errors in anything but tiny programs.
If you do make behaviour exceptions for error handling, be honest and upfront about it. Don't say "errors are just values so just use them like regular vars" in docs, if then there are several huge exceptions (tuple-returns and breaking a core tenet). If you make exceptions then you might as well do them right, instead of half-assing them. I believe zig does it right, but I haven't gotten around to try it.
To be fair, that expression came from a blogger who often wrote about Go. It is not a tenet held by the Go project. In fact, Rob Pike has made clear that he considers it to be misguided advice. It is only violated in the same way returning Result in Rust violates the assertion I made up for this comment: Do not return Result.
I agree that Go should really have an analogue to Rust's `?`, but you can't really do that in a sane way without sum types to represent your conditions. The very multiple-return style error propagation makes it impractical to do.
IMO Go should add really basic tagged unions and rework the stdlib to use them, but such a change would probably necessitate a v2.
There was a proposal for a `try`, which I still think should have been adopted.
Under that proposal, `someComplicatedExpression(try(functionReturningError()))` would be converted to `foo, err := functionReturningError(); if err != nil{return zeroValue, zeroValue, err}; someComplicatedExpression(foo)`
There is always the Odin style 'or_return' operator, which is defined for a similar situation.
It could be just some simple (hey, that's what go wants to be, right?) macro thing, that just does the everyday `if err!=nil{return ..., err}` for you without having to juggle (and think about) vars.
b := g(f()?)?
// var b B
// {
// var a A
// var err error
// a, err = f()
// if err != nil {
// return *new(A), *new(B), err
// }
// var b B
// b, err = g(a)
// if err != nil {
// return *new(A), *new(B), err
// }
// // no accidental reuse of err
// }
I mean look how much utterly useless noise this is, and count all the opportunities for mistakes that wouldn't get caught by the compiler.Looking at Alef, apart from using tuples to provide multiple return values in a C-like language, they don't seem to actually add much functionality over what Go has without them. One of the few extra things is the ability to pass a tuple over a channel, however passing a struct is more or less equivalent.
I've not looked in much detail at what Limbo could do with its tuples.
So maybe they don't really add that much, hence why they were not carried over when Go was created?
Alef had enums, Limbo has something like the Go constant scheme and iota. Limbo also had tagged unions / varient-records, in a sort of Pascal like fashion - the "pick adt".
Go functions also accept a tuple on input. While theoretically you could pass an error, or a pointer to an error for assignment, it is a stretch to claim it is for errors.
They are just horrific gotos that any library can invoke against your code. They are pretty much never, ever handled correctly. And nearly always, after an exception is “handled”, the application is actually in an unknown state and cannot be reasoned about.
Even junior engineers have a trivial time debugging most go errors, while even experienced principles struggle with figuring out the true cause of a Java exception.
https://blog.plan99.net/what-s-wrong-with-exceptions-nothing...
> Even junior engineers have a trivial time debugging most go errors
Not my experience at all. I had to do this once. An HTTP request to a production server was yielding a 400 Bad Request with no useful information for what was bad about it. No problem, I'll check the logs and look at the source code. Useless: the server was written in Go and the logs had no information about where the error was originating. It was just getting propagated up via return codes and not logged properly. It ended up being faster to blackbox reverse engineer the server. In a language with exceptions there'd have been a stack trace that pinpointed exactly where the error originated, the story of how it was handled, and the story of how the program got there.
Diagnosing errors given stack traces is very easy. I've regularly diagnosed subtle bugs given just logs+stack trace and nothing else. I've also had to do the same for platforms that only have error codes that aren't Go (like Windows). It's much, much harder.
This is the most important aspect of exceptions in my view.
The line that threw the exception isn't even the part of a stack trace that I find most interesting. The part that is most valuable to me when working on complex production systems are all of the call sites leading up to that point.
I remember in my junior years I wasn't a big fan of exceptions. A stack trace would make my eyes glaze over. I would try/catch at really deep levels of abstraction and try to suppress errors too early. It took me a solid ~5 years before I was like "yes, exceptions are good and here's why". I think a lot of this boils down to experience and suffering the consequences of bad design enough times.
Go has support for exceptions, not to mention providing runtime access to stack trace information in general. They are most definitely there if your application requirements necessitate, which it seems yours did. Unfortunately, language support only helps if your developers actually speak the language. Go in particular seems especially prone to attracting developers who are familiar with other languages, who insist on continuing to try to write code in those other languages without consideration for how this one might be different and then blame the technology when things don't work out...
In your map example, just add a scope guard that removes the just-added element using the returned iterator if the rest of the procedure doesn't succeed. It's no different in Java.
I’ve seen this argument, but if you look at real golang code and examples, it’s just a bunch of “if err <> nill” copy pasta on every line. It’s true that handling errors is painstaking, but nothing about golang makes that problem easier. It ends up being a manual, poor-man’s stack-trace with no real advantage over an automatically generated one like in Python.
How I hate it, that every second function call can break my program when it's clearly not a "halt the world, it's totally unrecoverable that the user sent us nonsense" type.
Return a Result and get on with your life!
Once every return is a Result, every call a ?, and every error a yeet, what's the difference between your program and one with exceptions except the Result program being syntactically noisy and full of footguns?
Better for a language to be exceptional from the start. Most code can fail, so fallibility should be the default. The proper response to failure is usually propagating it up the stack, so that should be the default too.
What do you get? Exceptions.
I shocked my Professor at university with that statement. After I started laughing, he asked me more questions... still went away with a straight A ;D
To me this proved that there's nothing inherently wrong about exceptions.
It's how you structure your code and the implied assumptions you share with your colleagues.
Some people are way too optimistic about their program will actually do.
Happy path programming.
Not true at all
* goto goes to a specific hard-coded address
* return looks up the previous address from the stack and goes there
* exceptions are a complex mess that require branching logic to determine where to resume execution
Also, exception systems usually come with built in stack trace support, "this error caused by this other error" support, debugger integration ("break the first time something goes wrong"), and tons of other useful features.
(Common Lisp conditions are even better, but you can't have everything.)
You can't just wave the word "goto" around as if it were self-evident that nonlocal flow control is bad. It isn't.
> And nearly always, after an exception is “handled”, the application is actually in an unknown state and cannot be reasoned about.
That's not been my experience at all. Writing exception safe code is a matter of using your language's TWR/disposable/RAII/etc. facility. A programmer who can't get this right is going to bungle explicit error handling too.
Oh, and sum types? Have you read any real world Rust code? Junior developers just add unwrap() until things compile. The result is not only syntactic clutter, but also a program that just panics, which is throwing an exception, the first time something goes wrong.
Many junior developers struggle with error handling in general. They'll ignore error codes. They'll unwrap sum types. They might... well, they'll propagate exceptions non-fat ally, because that's the syntactic default, and that's usually the right thing. We have to design languages with misuse in mind.
If you really don't like unwrap[1], you can enable a linter warning that will let you know about its uses to flag it during code review. You know exactly where they are and when they happen. Exceptions are hidden control flow, so you rely on documentation to know when a function throws.
> Writing exception safe code is a matter of using your language's TWR/disposable/RAII/etc. facility. A programmer who can't get this right is going to bungle explicit error handling too.
Rust has RAII, so you don't have to worry about clean-up when returning errors. This is a Go problem, not Rust.
At the same time Checked Exceptions were a nightmare as well, because suddenly they were part of the contract, even though maybe wrong later.
Junior developers will write suboptimal code in any language. So I'm not sure what your point is.
On the flip side I have yet to find a person who’s familiar with sum types (e.g., Maybe, Option, Result) that finds the golang approach even remotely acceptable.
I don't LIKE it, but it's acceptable.
I have been working with Rust since 2015 (albeit not professionally, but a lot of side projects) and love it.
But I also dabbled into go the last couple of months and while it has its warts, I see it as another tool in the tool-belt with different trade-offs.
Error handling is weird, but it's working, so shrug
As I pointed out I think Rust does it better with its types error handling. That isn’t too relevant for me though as Rust will probably never seem any form of adoption in my part of the world. I think Zig may have a better chance considering how interoperable it is with C, but around here the C++ folks are simply sticking with C++.
However, I do agree that it could be argued that Golang has become much more of a Java and C# alternative. Looks like Rust will be shoehorned into C++ and C spaces, but it remains to be seen how successful it will be as an C alternative. Seems like many fans of C are quite resistant or even outright dislike Rust.
I disagree. Typescript, C# and Java are terrible languages (as are Python/Ruby/etc. in other ways). Golang is bad by OP's standards but there's nothing wrong with it gaining ground on those languages.
Besides it's also easier to convert a codebase to Rust from Golang than Typescript or C#/Java.
It's a Google solution to Google scale problems, e.g. codebases with millions of lines of code worked on by thousands of developers. Problems that few people that have an Opinion on Go will ever encounter.
on this point go's error handling is a massive fail. Notice that I'm not saying explicit error handling is bad. I'm saying the insistence that error handling needs to be implemented inline interleaved with the happy path is the problem. You can have explicit error handling in dedicated error handling sections
maybe this has something to do with how bug-prone it usually is for a new hire to modify a codebase for the first time in most orgs
you could also just do things fail-fast style and panic everywhere if you REALLY wanted to stop inlining error conditions. or ignore error checks until some sort of guard layer that validates things.
IME you usually don't want to do either of those things, and the go approach at least encourages you to think about it closer to the site than checked exceptions (which you can more easily toss up and up and up and auto-add to signatures of callers). unchecked exceptions are arguably less-bad than "just ignore go return errors" - they'll get seen! - but terrible for a reliability/UX perspective.
optional-esque approaches are nice but just a different flavor of the same overhead IMO.
Some people didn't like the "try" keyword it reminded them too much of exceptions, some people didn't like that they couldnt see a return inline (which was the purpose of the proposal in the first place).
it's not that there are no solutions. the main problem is the go team's insistence to have "one true way" (tm) of doing something and unfortunately this gap between people who want to see every return inline and people who want to see the clean solution separate from the error handling is not something that can be bridged by technical means. the only solution is to implement both ways and lets see which one wins.
Where I agree: It forces you to think about all of the possibilities your code might generate. (This is more of a C question than it is with other languages)
However, when abstracting blocks of code away, you don't always need to handle the error immediently or you may want to handle it down the stack.
You're giving up a lot of readability in order for the language to be particular.
Except it doesn't actually. You can totally just ignore it and pretend errors don't exist. Lack of sum types/Result, and pointers as poor mans optional, really hinder's Go's error handling story.
The coding style encourages the behavior you're talking about. We're back in the C days where you have a result and an error. It's not a good pattern.
I’ve seen way too much Go code which never even tested the err value to believe that until something like errcheck is built in to the compiler.
I do agree that this is a plus for the explicit model but that’s been a better argument for Rust in my experience since there’s better culture and tooling around actually checking errors. I’m sure there are plenty of teams doing a good job here, but it always felt like the one lesson from C they didn’t learn well enough, probably because a language created by experts working at a place with a strong culture of review doesn’t really account for the other 99% of developers.
Error handling is still explicit, but it gives you the tools needed to make it less tedious.
Like as soon as I wanted to try and get sensible reporting in their, suddenly we were relieving libraries, adding shims and fighting mismatched types and every article was saying the same thing: haha yeah it's kind of a problem.
I'm very, very unsold on explicit error handling compared to exceptions for practical programming. The number of things which can error in a program is far larger then those that can't.
Even the simplest functions tend to have error states - i.e. floating point math can always wind up handing back NaN.
So where I end up is, the default assumption is every function is effectively of a type MightError(T)...so why even make us type this? Why not just assume it, assume the unwrap handling code, and so you basically wind up back at try-catch exception handling as a syntactic sugar for that whole system.
Positive example of good and appropriate usage here: https://github.com/coder/websocket/blob/master/internal/exam...
So... I'd say that this is a fumble in the design of Go.
Go, however, forces you to spread your error handling over a thousand little pieces with zero overview or control of what's happening.
Rust eventually realised this and introduced try! and ? to simplify this
A problem I often face in Go and TypeScript code is code that ignores errors, often unintentionally. For instance, many uses of JSON.parse in TypeScript do not check for the SyntaxError that may be thrown. In Go, it is common to see patterns like
_ := foo.Bar()
// assume Bar() returns error
This pattern exists to tell the reader "I don't care if this method returns an error". It allows one to avoid returning an error, but it also stops the caller from ever being handle to the error.Also, the position of the error matters. While the convention in the stdlib is to return errors as the final value, this isn't necessarily followed by third party code.
Similarly, errors are just an interface and there is no requirement to actually handle returned errors. Even if one wants to handle errors, it's quite awkward having to use errors.As or errors.Is to look into a (possibly wrapped) chain of errors.
The benefit of Rust's Result<T, E> is that
- position doesn't matter
- there is strong, static type checking
- the language provides operators like ? to effortlessly pass errors up the call stack, and
- the language provides pattern matching, so it's easy to exhaustively handle errors in a Result
The last two points are extremely important. It's what prevents boilerplate like
if err != nil {
return nil, err
}
and it's what allows one to write type-safe code rather than guess whether errors.As() or errors.Is() should be used to handle a returned error.It is unfortunate that many of Typescript developers still rely on throwing exceptions around (even in their own typescript code). Result types are totally doable in Typescript and you can always wrap native calls to return result types.
90% of the criticism of exceptions I see comes from the bizarre and mistaken idea that every call needs to be wrapped in a try block and every possible error mentioned.
That was prototyped around Rust 0.4, so I wouldn't say "eventually" :)
Is there in practice a significant difference between try/catch and Go's "if err" ? Both seem to achieve the same purpose, though try/catch can cover a whole bunch of logic rather than a single function. Is that the only difference ?
I think that's the biggest difference.
With Go you need to specifically check the errors and intentionally decide what to do, do you handle it right there or do you bubble it upwards. If you do, what kind of context would the caller want from this piece of code, you can add that too.
Honestly makes me wonder what I'm missing. Maybe it's because I don't deal with state much? Do the problems start to mount up when you get into writing transaction locks, rollbacks etc? But I don't see why you wouldn't have the same problems with Go's mechanism.
Hoping to gain enlightenment here.
[copied from a comment below]: They are just horrific gotos that any library can invoke against your code. They are pretty much never, ever handled correctly. And nearly always, after an exception is “handled”, the application is actually in an unknown state and cannot be reasoned about.
Maybe this is it? I prefer a "fail early and often" approach, and I tend to validate my data before I perform operations on it. I don't want to attempt recovery, I want to spew log messages and quit.
The big issue with exceptions in C#, Python and JS is that they're not included in function signatures, which means you have to look up the list of possible exceptions from documentation or source code. This could be amended with checked exceptions like Java, but it allegedly doesn't mesh well with the type system (I haven't personally written Java to confirm this). And then there's the C++ crowd that slaps noexcept on everything for possible performance gains.
Personally, I like the way Koka does exceptions with algebraic effects and type inference. It makes exceptions explicit in function signatures but I don't have to rewrite all the return types (like in Rust) because type inference takes care of all that. It also meshes beautifully with the type system, and the same effect system also generalizes to async, generators, forking and other stuff. Alas, Koka is but a research language, so I still write C# for a living.
I think that’s misdirected but illustrates the emotional reasons why people develop a negative impression of the concept. Usually it means someone had bad experiences with code written in a poor culture of error handling (e.g. certain Java frameworks) and generalized it to “exceptions are bad” rather than recognizing that error handling isn’t trivial and many programmers don’t take it seriously enough, regardless of the paradigm. As a simple example, C and PHP code have had many, many security and correctness issues caused by _not_ having errors interrupt program execution where the users would have been much better off had the program simply halted on the first unhandled error.
If you write complex programs with lots of mutable shared state, yes, it’s hard to reason about error recovery but that’s misattributing the problem to the mechanism which surfaced the error rather than the fact that their program’s architecture makes it hard to rollback or recover.
Yes - for me, the simplicity is essential. As a part-time programmer, I don't have months to spend learning C++ or Rust.
If my project needs to compile to small(-ish) standalone binaries for multiple platforms (ruling out Python, Ruby, Java, C#, etc) what simple alternative language is there? Plain C?
I kind of see your point. In this very moment, it doesn't matter whether I agree. What I don't understand, though, is why (typically) people who abhor exceptions are among the fiercest defenders of garbage collection, which does add a “magic” and uncontrollable layer to object destruction.
Personally, having learned to love RAII with C++, I was shocked to discover that other languages discarded it initially and had to add it in later when they realized that their target developers are not as dummy as those choosing Golang.
A garbage collected relatively simple language that compiles into a statically linked binary but has a type system similar to rust, rest types etc.
Syntactically, Gleam and Kotlin come somewhat close but not really. I like Rust but I do believe it is too complicated for many people who are capable of creating something but are not CS grads nor working as programmers. If you're only gonna use the language every once in a while you won't remember what a vtable is, how and when things are dropped etc. I understand that "the perfect language" doesn't exist but I think both Go and Rust brought amazing things to the table. I can only hope someone takes inspiration from both and creates a widely usable, simple programming language.
In practice, Kotlin is extremely complicated, and you end up spending time being clever. There are 1000 ways to do things. Operator overloading. Proxies. Properties. Companion objects. Exceptions AND result types...
The build system (assuming you use Gradle) is tantamount to torture for anyone used to "go build".
The coroutines APIs feel simultaneously more complicated and yet more restrictive than Goroutines. More structured but less flexible and more effort to use.
Access control feels awkward. There's no way to make a type package-private -- it's file-private or available to the whole module. This leads to either a larger API surface than desired, or the inability to break up complexity into multiple files.
Kotlin/Native and Kotlin/JVM really are two different beasts too.
Kotlin/JVM is mature, but then you are running on the JVM, so that cuts out a whole class of use cases you might bust out Rust for.
There is a very weak ecosystem for Kotlin/Native, and it's poorly documented. There are some scary bugs in the bug tracker.
You can't publish source-only libraries for Kotlin/Native either, so you need a complex CI setup to build binaries for every OS and arch under the sun. Or just don't publish libraries at all, which probably feeds in to the weak ecosystem...
Go has the one big advantage that is almost solely responsible for it's success: It was created and directly used by a giant company that could afford to create amazing tooling around it and develop great opensource libraries for it. Already being in use and having libraries feel like the biggest determinants of a languages success.
Start with JavaScript. The basic syntax is delightfully direct, it has massive adoption already, the ecosystem is large, the runtimes are getting better all the time, compilation is here with WASM,
Now remove the weird parts (e.g., too much flexibility to redefine things, too much use of the global scope, too much weirdness with numbers, etc.), and add:
- Types (including sum/product types, Result<T>, Maybe<T>, decimals, etc.)
- More functional features (everything-is-an-expression, pattern matching, currying, etc)
- A comprehensive standard library.
Already this starts to yield a language that has the best chance to be what a lot want.
The other major advance in developer tools that I'm wanting to see is revamping HTML to have proper sophisticated controls built-in, controls that can be easily styled with inline CSS. This will reduce the amount of JS needed on the client.
These two things will yield a massive advance in programming productivity, at least as far as web-related development is concerned, IMO
The one thing I would add: Provide a well-trodden path to easily drop down into Rust/C/C++ for performance critical functionality. I have found this to be a big point in Python's favor over Go; you can write things the slow way (ie. executing in the Python runtime), then profile and figure out where to push things down into an extension. Often you're doing something that already exists in a library like numpy or pandas or polars, but if needed, you can write your own extension.
Does WASM enable FFI on its own?
Also to be productive you have to utilize the rest of the erlang ecosystem, so at least some superficial knowledge in elixir & erlang is helpful for for some use-cases.
Syntactically I actually don't think it's that for off, but I dunno what GP was thinking, maybe that it leans more into functional patterns & sugar for those whereas rust/go can also be used in a procedural style. (Though at least personally I am using way more functional patterns in rust than I expected)
Out of everything mentioned, I think Gleam is the most likely to succeed and what I think I will invest in as well. But that's not just because of the language design but rather because of their approach to community and community building! It's a very very nice extra that the language/syntax also happen to be what I like and have described in my previous comment.
Compile to static native binary with 'dotnet publish -p:PublishAot=true' (or add this property to .csproj to not specify on each publish). In the case of F#, you will need to use Console.* methods over 'print*' because print has unbound reflection inside for structural output on "%A" format specifier (it will work most of the time but negatively impacts binary size and causes the compiler to complain).
I can especially recommend F# as "easier more business-focused Rust alternative" because it is expression-oriented, has discriminated unions, full HM type inference and gradual typing is a joy to work with. Data analysis and domain modeling are very pleasant to do in it too.
For systems programming C# is going to be the option to use - it will give you great concurrency primitives, fast (sometimes even zero-cost) native interop, smaller than Go native binaries and a lot of low-level APIs including portable SIMD. Go is often poorly suited for these tasks or can't do them at all (at least without workarounds). There are many new high-performance libraries focused on this domain as .NET gains popularity in non-gaming communities in this area. And of course you benefit from a huge existing ecosystem and won't have to do the all the heavy lifting by yourself unlike in niche languages suggested in sibling comments.
So OCaml then (ocamlopt to do native code compilation)
Swift.
But sadly it's not that easy to create a statically liked binary in swift. The last time i did it it also included the whole runtime, and the resulting "hello world" binary was 50mb large. Annoying at least.
For years I wished they got their stuff together, but at this point I'd be very suprised. They probably have too much technical dept already due to the support of XXX edge cases Apple need for iOS/MacOS development.
This is a thing that's having work done, but still too large depending:
https://www.swift.org/documentation/articles/static-linux-ge...
See here for sizes of various languages as of August 2024 when I'm commenting, but this is Swift 5.10 for Windows:
https://github.com/MichalStrehovsky/sizegame
Build actions here:
https://github.com/MichalStrehovsky/sizegame/blob/master/.gi...
What you want, instead, is Swift 6 for Linux, while e.g. Alpine, as of summer, still too large:
https://mko.re/blog/swift-alpine-packaging/#:~:text=Package%....
In this thread on Swift for AWS Lambda, a dev gets a Linux static build to 5.9 megabytes:
"Then, I stripped it and it's now 5.9Mb. That's an impressive 86% reduction. Given that musl libc.a is 2.4Mb and libc++.a is 10Mb, I find that 5.9Mb for an executable that contains both libc and the Swift runtime is not that bad :-)"
https://forums.swift.org/t/aws-lambda-functions-and-the-linu...
> They probably have too much technical dept already due to the support of XXX edge cases Apple need for iOS/MacOS development.
See also embedded Swift:
"Apple explains that Embedded Swift is a subset of the Swift programming language with a much smaller footprint (the binary can be around 10KB..."
https://www.cnx-software.com/2024/06/13/embedded-swift-esp32...
You just described Ocaml and ReasonML (which is Ocaml with Go-like syntax).
If you check the Wikipedia page for OCaml to find out where it gets used, you'll see why it's ocaML. That is, you'll notice that it's mostly a MetaLanguage, or a language for writing other languages. The same observation applies to other languages in the ML family.
Rust syntax, compiles to Go.
Yeah! Pattern matching too. What are currently available languages closest to this? AFAIK, Gleam relies on a virtual machine, but otherwise seems promising.
Go: "I'm a simple language!"
User uses Go for some time.
User: "I hate you, you're a simple language!"
Perhaps it's because I'm 50+, I love a simple language.I feel the "critique" is not very balanced, and I view judgements that are not balanced as weak, as everything in technology is about tradeoffs.
I of course come to a different conclusion: https://www.inkmi.com/blog/why-we-chose-go-over-rust-for-our...
There are many examples in the article that point out the annoying inconsistencies in the language, those are the opposite of simplicity.
I love Rob Pike's presentations on Go, some of them were eye-opening to me. However, I just wish that the Go I see in practice would be much closer to the Go language that Go-fans describe in abstract.
Despite its veneer, once you start writing Go it quickly becomes apparent that it isn't simple. Hidden complexity and footguns are abundant (e.g., https://archive.ph/WcyF4).
It's nevertheless a useful language, and I use it quite a bit, but it's not "simple".
Go is easy, but it is not simple. For example, solving the problem of generics in a generic way from the start so the same problem can be addressed in the same way everywhere, would be simple, but maybe not (as) easy. Contrast that to giving the runtime/standard library a special exception with maps and lists. That's easy, but not simple. People used to literally use code generators or weird UTF-8 characters to fake generics, that's not remotely simple.
And plenty of other examples that aren't in that article:
- You have a struct with an embedded interface. Does the outer struct satisfy the embedded interface? And can I type assert the outer struct into whatever embedded struct is fulfilling the inner interface?
- When should I pass by value and when should I pass by reference? Like I generally know when to choose which, but do I really know without performing a benchmark? And what about arrays? Should I store pointers in them? But it also seems that people just don't care and just randomly roll the dice on when to return a pointer or a value?
- Shorthand variable declaration. How does it work when you shorthand declare two variables but one of them already exists?
Don't both answering the questions, that's not the problem. The problem is that it's just not intuitive enough such that I'm confident I know the correct answer.
For example, passing by value/passing by reference is something covered immediately in the Go FAQ document once and for all. Everything is passed by value in Go, that is it. There should be no confusion at all. If you spend 15 minutes reading Russ Cox's post on the internals of the most common data types, you will also understand what data structures have implicit pointers under the hood.
The second isn't related to Go.
The third I can see as being a bit confusing, but isn't it something you try once and then remember forever?
Here's one: Creating a new variable via shorthand that shadows a variable in an outer scope - that can be confusing and an easy mistake to make.
But broadly, I would strongly advocate that it is simpler than most other languages, even if it has some quirks. In the same vein of "If I had more time, I'd write a shorter letter", sometimes it takes a bit of time to understand why something is simpler than the alternatives. No language has zero ramp-up. Go doesn't exist in a vacuum, you have to compare it's learning curve and complexity to other languages.
Same about benchmarking, if you want and need the fastest code, or the best memory management, use Rust.
If you need something faster than Python in general but not the fastest, use Go.
Not really. But that’s one of Rob Pikes rules [1], I think the intention is to write whatever is simplest and optimize later. The programmer doesn’t need to remember 100 rules about how memory is allocated in different situations.
There's more stuff to think about, because the language is doing less for you.
Everyone can read Go code and understand what happens. There are some minor difficulties like func (*A) vs func (A).,
In my opinion, a simple language should be highly consistent (have a few rules, but which are universal and consistent everywhere). Instead we have a language with weirdnesses, inconsistencies and workarounds all over the place.
A good example is type elision: it's available when declaring arrays, slices and maps, but not for structs. Allowing that would have several benefits in terms of readability, and also allow named parameters via anonymous struct arguments (which would greatly improve the design compared to the ugly workarounds that are currently used).
Use the tool that works for you.
(fixed the statement to focus on your value, not age per se)
I love language ergonomics above all. Python wins. But for runtime bang-for-the-buck, Go wins.
The difference, for example is: Go invents an abstraction just for one use case, and just for the standard library/runtime itself, instead of taking the time to create a universal version of that abstraction. Generics for maps and lists, and tuples for error handling.
Is the post written to make one feel better having a failed a project the language? (It's not me, it's the language) Or is it the failure to understand that not everyone thinks / works the same and what one finds unacceptably bothersome, others barely notice? Languages that do not cater for a real need would likely vanish on their own, they rarely need help.
As for Go, despite the differences compared to "more sophisticated" languages it works brilliantly for the projects I've encountered. I hope the author is not forced to work with Go though. For the rest of the community, we keep churning out services, giving our feedback to the Go team and seeing the slow evolution of the language without breaking our stuff in production.
"""
Inherent complexity does not go away if you close your eyes.
When you choose not to care about complexity, you're merely pushing it onto other developers in your org, ops people, your customers, someone. Now they have to work around your assumptions to make sure everything keeps running smoothly.
And nowadays, I'm often that someone, and I'm tired of it.
"""
> [Go] works brilliantly for the projects I've encountered.
Of course, C, C++, PHP and JavaScript works too! Of course many many many things "work" in our world. Of course just adding one more lane works too, of course police states work too!
Yet something else would work even more brilliantly?
The supporting argument in the text is that even simple things like downloading a file can get hairy very fast. Networks are complex, HTTP, IPv4/v6, DNS - it's always DNS! - filesystems, permissions, running out of space, computer runs out of battery, etc.
Probably a better argument would be to focus only on application logic (type system, error handling, syntactic-semantic ergonomics) and show that a complex piece of Go [like the k8s persistent volume controller] can be written in a nicer, more maintainable, safer way in Rust.
Of course not all Go code achieves Kubernetes-level complexity. And I think it makes sense to pick the right tool for the job, which is whatever the team/programmer is productive with. (And here productivity is measured based on how well the resulting code/software solves the business case. And basically if there's no need for Rust-level safety/quality/maintainability, or if there's an explicit need for Go-level cheaper hackability, then that's a great result business-wise.)
The important corollary of this is that business requirements tend to change, yet software has inertia and that's roughly how we ended up with insert famously bad software that got wildly popular unexpectedly (for example Windows, Macromedia/Adobe Flash and the infamous plugin, random low-level crap in appliances, and adjacent to that the Bluetooth stack that got rewritten in Rust for Android).
So - of course - for society it would be amazing if software would be better from the start. (Duh!)
Also, one more thing I think worth mentioning, is that the argument about the lack of information in code at callsites in Go (is something passed by reference or by value), how hard it is to keep boundaries (immutability) is basically an argument for making this complexity up-front and visible. Hence Rust looks complex. (And again, the argument is that it's there even if Go hides it.)
https://blog.rust-lang.org/2017/03/02/lang-ergonomics.html
https://github.com/kubernetes/kubernetes/blob/60c4c2b2521fb4...
I would guess the 'why' is because OP feels like they have an opinion that they don't feel is sufficiently represented 'out there'. Indeed, as a not-a-fan-of-go, in 2022 I was confused at go's popularity because it always felt to me to have some pretty glaring shortcomings that were seemingly ignored.
Note that people don't really write big blog posts about PHP being a bad language (anymore?) because that's been done to death.
Go is used in a lot of places for unglamorous things where the most important thing is explicitness, and where all these features that the PL nerds want, do nothing but make things more implicit.
It's not perfect, but it's a great language. People who like it, though, like me, are pragmatists. The shortcomings of the language that are apparent in complex code are strengths when writing the simple straightforward code that makes up most Go projects, because all of THAT becomes much simpler than it would be in a fancier language.
The reason I've never bothered to write a response to these kinds of screeds against Go is that usually I'm too busy getting shit done with it.
Just because this blog post isn't written in a way you like doesn't mean it doesn't have value to others.
Anything that Go did, no matter if it was the most basic implementation or if other languages already did it (better), was essential, the best and only way to solve that issue.
Anything Go did not do was superfluous and downright a conspiracy by Big Complexity to keep us unenlightened Non-Goers addicted to the Syntax Sugar: Things like sane null handling, sane error handling, less boilerplate, generics, or not creating special cases for everything (generics and tuples) instead of developing one cohesive solution.
Even now, in this thread, the strawmanning continues: Error handling is brought up, and instead of admitting the unmistakable truth that Gos error handling could be much better (s. Rust), people bring up things like JavaScript. As if anyone criticizing Go that JavaScript was the pinnacle of error handling.
“Go is designed as a systems programming language” has been retconned so that “systems” is redefined to mean programs talking over a network?
“Real programs won’t use repetitive error handling, but build on top of it.” I don’t think this one needs further explanation.
“Go doesn’t need xyz.” This is just the slow and painful process of the golang community realizing one at a time why other languages have the features they do.
“Explicit is good.” Explicit and verbose are not the same thing. You can have explicit and terse.
“Golang is simple.” Golang is primitive, not simple. There are tons of footguns and gotchas, not all of which are chronicled in the linked essay, which would have been so easy to avoid. And everyone just collectively internalizes these issues as if “just avoid writing those bugs” is a sane mindset any different than the languages that came before.
“Go doesn’t need a package managers.” Oops, it did. Now we’re like three attempts deep.
Over and over and over I feel like we’ve been gaslit and told we’re crazy, only to later on have the community act like (for example) golang always intended to add generics and of course they’re a good idea.
Stuff like "Go doesn't need dependency injection because it's simple". I heard that literally dozens of times. The opposite is true! It's an even bigger pain without DI because the language is so simple! DI everything or make your users suffer!
Or a personal favorite: "Go doesn't need a package manager". We see where that went, and how much insanely better it is now that we have it.
Or errors. Without wrapping. Oh boy we're gonna pay for that for decades.
There's stuff to like in the language, but the zealots (especially early ones) really did not know which parts they were.
I just love the fact that it literally just works. You install Go, you download code, and write code that's it.
No figuring out what version, runtimes, configurations, build tools, package managers to use. Just install and Go.
I think maybe Rust is the only other programming language that provides the same experience.
Maybe these are just lies I'm telling myself, but every time I use Python, Typescript, or Java I dread programming because I just want to write code and I'm often debugging things or figuring out related to configurations, package managers, build tools and versioning.
I guess I feel bad for people who are particularly sensitive to the areas that Go does not succeed in, because they are probably going to be complaining about it for the rest of their lives. The truth is though, I don't use a bunch of rationale about what is the best programming language to choose which one to work on for a project, I choose a language that I feel works well for me, that I feel I can consistently write good software in, that feels, well, nice to work in. Being a person that values correctness, I do sort of wish that language could be something more like Rust, but for now, it's just not, though it's not like I hate Rust, it's just not what I reach for in a pinch.
Enough has been written about how terrible Go is by this point. At least now I know what it's like to have been a fan of PHP a few years ago! (That's an exaggeration, but it's not that big of one in my opinion.)
Well, that’s a stellar endorsement of the article, because that’s literally the point they’re making.
You’ll use go.
…and then regret it.
…but by then it’ll be too late, and you’re stuck with it.
I think the author makes a compelling argument, which is very difficult to counter, that it is a bad choice and you will regret having it in production in many of the explicitly listed cases, and in many professional situations where companies that are not technically competent use unsuitable tech.
Companies should stick to boring tools.
…but, for personal projects? Sure, go for it.
Will you regret choosing Go? Maybe. Or, maybe not.
I'm not so sure. I know C programmers that swear by it, warts and all, with absolutely zero regrets for using it e.g. in the embedded space.
Then there's software I've been involved in where I believe Go was the wrong choice. And software not written in Go where I believe Go would have been the wrong choice.
My point is, Go is just another programming language, with a unique set of strengths and weaknesses, and there are plenty of cases which i have experienced myself where there are genuinely no regrets around picking Go. Not because there aren't shortcomings in Go, but because there are plenty of cases where those shortcomings don't matter.
In my professional life, I have seen significantly more regret associated with choosing JavaScript on the back-end than with choosing Go. But then again, there are services in production written in JavaScript where that just never has been an issue and there are no regrets.
As a result most things written in go are, in my own experience, of lower quality compared to things written in other languages.
So using things written in go is usually my last resort, because I expect they won't be high quality before even downloading them.
And I am a go developer that likes go and use it for 95% of my coding, including MMO servers. I love programming languages and have used and dabbled in many. I still go to go.
And many go tools I use tend to be pretty well written. But maybe this is just a sample size of 1 vs a sample size of 1 issue.
Where is the tradeoff analysis? Yeah, you might regret using Go when some zero value you forget to fill in somewhere pops up later and ruins your pipeline. But are you considering all the issues that didn't pop up because you chose Go?
Java's boilerplate code? Rust and C++'s lifetime analysis and memory management? C's lack of tooling? Python/Typescript's runtime errors? Functional languages' tiny employee pool? How much did trouble did you save by avoiding these?
Also it doesn't have packed structs so it's completely incapable of doing low level networking or to handle binary files (you can of course do all the bitwise operations yourself… but is it sensible to use a language that is more error prone than C in 2024?).
Also due to its lack of A LOT of system calls, you will need to use modules written by someone on github, which will happily segfault if you look at them funny.
So now you have hidden memory management! Fun!
Of course if all you do with go is a glorified jq script… sure then it's kinda fine.
Then again, I sort of like Java and Python too, two languages I am proficient enough at. All of those are good tools for what they intend to be.
I don't understand why people get so passionate about programming languages. They are tools. You may like soke more than others, but that doesn't invalidate the ones you don't like.
Because when you're a professional programmer, tools are a huge part of what you do and how you do it, same like a race driver would need to be passionate about cars.
It's just that for an e.g. carpenter, tools are more or less standadized and simple enough to evaluate.
If saws and hammers and routers had as much variety as programming language tooling, and were as multi-faceted to evalute, carpenters would be absolutely obsessed with using the good ones - even more so than they already are.
I am a professional programmer. Have been one for more than two decades. And perhaps for professionalism, I think there is no space for passion when it comes to choosing the tools of the trade. Passion would make me pick unsuitable tools because well, I would be passionate. Passionate people don't tend to make rational decisions.
I would expect a professional carpenter to be the same. They may have preferences due to familiarity, positive experiences, etc and so forth. But passion?
I certainly wouldn't give up my electronic hardware repair tools without a struggle, it took me years to find ones that I like!
Which is the wisest choice for everyone. Golang is only a problem when a manager imposes it on you.
Every Go developer survey has results where the community overwhelmingly votes to improve error handling, but a few extremists have derailed all progress.
A lot of people really don't like Go because they have experienced other language features. Go has taken an arrogant stance at trying to make the decision about what features you might need and has given you a very small amount of things to work with.
One frequent praise one hears of Go is that a developer can open any codebase and immediately understand what's happening. Go is readable and stable, which are critical for code for the long term.
I think you're overlooking the context of the language. It was a language that introduced a lot of new concepts to most programmers out there on top of that it was flexible to accomidate existing Java developers (for better or for worse). It evolved and grew quite a bit.
The fact that you could develop different styles made the language a lot more useful.
I'm not sure what you mean by transferable skills.. but that sounds like code for overly excessive coding preferences by hiring groups. If you're working with Play you'll be able to learn Finagale, or go to Http4s.
When you attack a codebase, you can't consume it and understand the full context easily, the range of operations that a code base is expected to do is far too vast for that. Even with Go, you can't just pickup and go that quickly. It may (if you're that experienced) become easier to understand. But with a large codebase, it's going to make it much harder as that it encourages large drawn out functions and verbose handling of errors. Also, Go's testing preferences tend to make it harder to write good and effective tests.
It didn't get 67 new features that start shooting deprecation warnings on old functions in the meantime. I don't have to learn new paradigms or switch integral parts of my code to something new.
Generics has been in Go for dunno how long, haven't used it once. Didn't need to.
(With exception to some java9 and minor deprications).
However, wait long enough that will come to Go, or it'll become less useful.
I will keep very fast compilation times and decade long backward compatibility over a lot of your features. Because those are features too.
Then you're doing yourself a disfavor by using Go. In other languages it would be even more explicit, mandatory, and automatically checked whether it's handled!
I have no need to worry about a 24 byte overhead for a slice allocation, if I did have to worry about that, I'd probably use C or Rust.
But that's a point made in the article, that Go is also good for prototyping. But there's a few languages good for that, e.g. Ruby which powered a lot of the HN startups in their early days until parts needed to be rewritten for performance / scalability.
But writing a new, unproven product in a high performance, high difficulty language from the get-go is cargo cult; you hope you will need the performance and correctness offered by the language. Meanwhile, halfbaked hack jobs like Facebook and Twitter exploded in popularity and revenue, and while their performance issues gave their developers headaches, at least they knew what problems they had and had to solve instead of guessing and hoping.
You'll have to rewrite your whole program (or at least factor out the "core" part you care about into a separate binary and talk to it via IPC or network) because Golang has terrible FFI as pointed out by OP.
(130 points, 148 comments) https://news.ycombinator.com/item?id=34188528
(748 points, 544 comments) https://news.ycombinator.com/item?id=31205072
Well the post rambles a fair bit, IMHO. The whole bit about Go being “accidental” is BS given that Rust is just as much “accidental” in its origin and design.
One thing stuck out to me is that Nim certainly isn’t a “better C”. It has a GC or you can use reference counting. You can use it as a better C if you really want.
Nim’s type system avoids many of the problems that Go has, though it’s not nearly as pedantic as Rust.
At the end of the day lots of software has been written and shipped in Go which runs fast, has minimal downtime, generally seems effective, and has minimal security issues. I’d argue (much) fewer software projects have been shipped in Rust. Firefox is still 95%+ C++.
It's funny but this comment reminded me of this tweet[0] from 2022 (!). I don't have a horse in this race as I am happily using Python and C++ at $DAYJOB. I'd argue that even if much less software has been written in Rust (source?), it still qualifies as "lots of software has been written and shipped" with it. Not to mention all the investments by $BIGCORPS in the language.
I think maybe the more common, but less helpful comparison of go vs rust comes from the fact that they are both part of a new wave of languages and that they both default to producing staticly linked binaries.
There are many stylecheck tools that should be apart of a good stack. Accepting the creator's style is putting a lot of weight on their opinion. Most organizations have their own preferences for good reason.
> short ramp up for junior engineers
Junior engineers aren't a place you're concerned on being productive. Most of the time at that stage in someone's career they should be learning more, getting up to speed with professional practices, tools, and trying to learn code bases+patterns. Ramp up time for a language is a very minor consideration.
Both of those things have very little to do with server environments.
Bigger corporations struggle with Go's module system and forced reliance on seperate repos for separate modules. (Can you bundle multiple modules in the same repo.. yes but you're going to have a bad time)
My experience of bigcorp is that they need lots of servers (http is the modern bailer twine) and want developers to act as far as possible as indistinguishable resource. They will have rotating, high churn, globally distributed teams of vendors, contractors, consultants, internal staff and the teams will encompass a vast range of skill levels and abilities.
Some languages amplify skill level disparity, some attenuate it.
It's a really bad choice for situations where Java is a good choice as not only is the language limited, the ecosystem around it is also very limited when compared to say Java.
I'm maintaining Go, C# and TypeScript as my main languages as that gives me excellent coverage. I'll add Rust to the mix when I have 6 months where I can accept the productivity drop or have a project where the quality requirements are lower (it only takes a week or two to pick up a language, it's learning how to engineer within the ecosystem which takes the time).
Someone please explain to me what's C-like about Go other than vaguely the syntax and that it compiles to machine code.
> You can't use Go to write a kernel ...
Not a production kernel, but MIT did use Go to "study the performance trade-offs of using a high-level language with garbage collection to implement a kernel" [1]
There is also gVisor [2] which implements, as best as I can describe, a kernel in user space. It's intent is to intercept syscalls made in containers and to redirect its execution in a sandbox.
> ... program a microcontroller ...
I'm not sure if one would classify this as a microcontroller, but USB Armory did write a, iirc, Go compliant runtime for bare metal ARM and RISC-V [3].
There is also TinyGo [4] with the following listed microcontroller support [5]
[1] https://github.com/mit-pdos/biscuit
The fact that it can't fill many of the usecases that C can and yet has ergonomics as bad as C makes it even worse.
With influences from other languages along the way.
Are Rust and Go sufficiently different that they should each be chosen in different cases? Sure! But that’s literally why someone would consider both and pick one.
People have an irrational hate for it based on the enterprise cruft and horrible third party frameworks you can just completely ignore if you build a new thing
It's not good for commandline stuff but for a long running small service it is pretty great
It is much more practical to choose a language that does not have a terrible history of poor API design to begin with.
..and I'm generally a Java-hater as the language itself is objectively inferior to my beloved C#.. but even then there are situations where Java is a better choice.
Except they are not unlikely to consider Java.
It's a language with a very robust ecosystem, it is relatively easy to hire Java developers, and a decent job for large, complex projects.
Go should have been the obvious choice but for a reason I don't understand I dislike its syntax. For Rust I understand: it uses a lot of special characters that aren't easy to remember and to type with a non qwerty keyboards (plus other unrelated pain points). For the different lisp, it was the parenthesis and the reverse polish notation. But for Go, I'm unable to rationalize why I don't like it.
For the anecdote, I settled on compiling my python code with nuitka. No speed gain that I'm aware of but I can now provides a binary. I'm also looking more and more at C# because of its progressing AOT compilation and although I dislike the verbosity of its base mode and the fact it's so tied to windows.
I liked a lot nim and crystal but the small community was a barrier, although I'm really impressed by what nim is managing to do with such a small community and it may me think it's an excellent language
(I will try to motivate myself to pick up one of the language I mentionned above also)
Dotnet Core is not tied to windows except for certain frameworks like wpf (and there are alternatives for it that work everywhere), credential store.
And it's actually really good to use these days.
Our team uses C#. We dev on Apple silicon Macs. Some use Rider, others just use VS Code. We build on Linux via GitHub Actions. Ship to prod running AWS t4g Arm64 instances.
C# to me is like TypeScript++. The language, syntax, and core constructs are close enough that anyone with a good handle on JS and TS can pick it up easily and be productive.
There are other approaches which give up on C-API and build a bridge to languages such as Go and Rust.
I've spent a few years working on py2many. Would appreciate feedback on the approach.
If I can't get at least ADTs and parametric typing, give me gradual like CL.
I am not a stranger to the programming world. I am fluent in Python, Java, Scala, Erlang. I can write acceptable Haskell and C++ and Common Lisp. I am well versed in functional programming (though I don’t hate OOP — it is still a good thing when done correctly, and I am a big fan of Smalltalk).
However, for some reason, I am completely unproductive in Rust. It always fights me. There’s always something I want to do (graph structures? spliced lists?), and it’s always “you don’t need that” and “it’s not the Rust way”. There’s always explicit lifetimes and you miss something and you need to rewrite huge swaths of your code. And nothing is refactorable. It’s not even a good functional language, there are no persistent data structures, and it’s a pain to make them, and no ways to express yourself functionally like I used to do with Scala.
But apparently, everyone and their dog like Rust and are insanely productive in it. What am I missing?
In other words: Don't think of it as rivalling the entry cost of Python or Java, or the expressiveness of Haskell or Scala. Try to think of it as a replacement for C++, with memory safety and piles of quality of life improvements. And then with a sprinkle of the other things on top.
Interestingly, I have the same feeling when trying to write something with Vulkan — the amount of ceremony and boilerplate before you even get to the first triangle is a huge barrier for my productivity. I want something more immediate.
Out of all the bugs which Go permits I have yet to see one which could survive in production for some time without being discovered. Almost all of them would cause a failure the first time a segment of code is run.
This post is always a scary read:
This excerpt should be enough for you to know if you will find the article insightful or useless.
Too often I see code like "xyz := pkg1.SomeFunc(a, b, c)" that makes xyz's type non-evident, especially when interfaces are involved.
Please write Go code like
var xyz pkg2.SomeType
xyz = pkg1.SomeFunc(a, b, c)
My 0.02€, YMMV.Since this article was written Go introduced generics which does solve some of the complaints. The rest I mostly solve with linters, libraries, and conventions.
Go has a syntax that is well designed (arguably one of the best) if you’re aiming for familiarity with C style syntax in an imperative language. Other than that it’s a poorly designed language with by far the best engineering work having gone into things that aren’t actually the language per say (cross compilation, asynchronous runtime, GC, module system, super fast builds, etc). They wrote an ACM Queue article essentially stating that: https://cacm.acm.org/research/the-go-programming-language-an...
>The success of Rust is due in large part to it being easy to adopt piecemeal and playing nice with others.
And as if Rust itself didn't suffer from the same kind of imperfections one can find in Golang. So much for that "nothing new under the sun" back in 2012! But then it starts talking about the "rust shills" boogeyman, and one has to wonder if it's not trying to justify one's choices. (which is fine, anyway) And I agree wholeheartedly to each and every single one of the "lies" listed in the article, that you could very easily rewrite half of which to fit Rust, and the other half requires no changes to apply.
Which imperfections are these?
It's "we learned about green threads and didn't bother to learn anything else" approach (also prevalent in many other languages)
The argument about FFI and CGO was the most unappealing to me. If you really need to do that, it feels that at some point some decisions were made that weren't the right fit for the project.
Also, I feel that many arguments in the article are potential pitfalls for unintended side effects I've experimented in other languages, like Ruby itself. Keyword arguments are nice, but I know that they've bitten me several times.
Go forces the developer to be explicit about their intentions, that's why I also don't find something bad that your struct functions need to have the pointer receiver. It can be annoying when you forget, but that's what linters are for.
A strange take. Zig, Nim and Odin are about fixing semantics not to bring syntax sugar.
- No sum types
- Default zero values
- "Go is an island": Fully integrated toolstack makes it easy to use the same tool top-to-bottom, but makes it difficult to use with any other project
None of those are lies; apart from the first, they all have advantages and disadvantages. Sure, there's an advantage to forcing you to specify every value, but there are disadvantages too. And sure, there are disadvantages from Go being an "island", but he lists some of the advantages right there in his post.
If those are deal-breakers for him, then sure, go use something else. But lots of us like the advantages more than we dislike the disadvantages.
It's a bit too low level for many use cases in my opinion, and that does get in the way somewhat. It also works against the "easy to learn" part unless you start with developers familiar with low level programming.
I also found some types of library code surprisingly difficult to read, especially when empty interfaces where used.
The standard library was great though, it covered stuff that others don't and it just worked out of the box.
On one hand, say, I love operator overloading, I love how Python does it (once you satisfy an interface, its operators Just Work).
On the other hand, I can appreciate the choice not to do it at all because half of the ecosystem will do it, and another half won’t. Also, it would require implementing function overloading, and it is a can of worms.
Or generics and rich type systems, which all come with their own tradeoffs. I hear that Rust cajoles you into tinkering with the type system, and wach tweak requires refactoring of more codebase than anyone would like (don’t take my word for it, it’s just what I heard from a few different sources). I know that Nim is so expressive that it can be annoyingly trivial to be too clever and run into a valid edge case that will make the compiler barf and die. Go sidesteps the issue by not wading into that territory, and that may be perfectly okay, albeit verbose.
It’s always picking your poison, so I guess check your tolerances and allergies so it doesn’t kill you before you get the job done…
Is this different from other styles of operator overloading? Why does it matter whether, when I want to overload the + sign, I need to define a function called `__add__` or `operator+`?
Well maybe not.
If I’m an expert in only Java 6, I might not be aware of all sorts of useful features that other languages have, such as sum types, traits, type inference… I only know one side of the trade off.
I might be vaguely aware of those ideas and dismiss them because I can’t imagine how they would fit in my Java 6 workflow.
And yet when some of them arrive in later Javas, I begrudgingly use them. Years later I can’t imagine how I ever lived without them!
We’ve seen this play out so many times.
Remember when lambdas were just for weird functional languages?
Truth be told I quite like Go. It’s small and simple. It does the job. You can onboard people on it quickly and in practice with the toolchain you don’t run into the issue mentioned.
Would I rather use Ocaml most of time? Of course but it doesn’t have the same ecosystem. Would I rather use Rust? Heck no, I’m not going to deal with the borrow checker and life cycles if a GC is fine.
I think a large part of this is due to error handling in Rust and the sugary `?` syntax which is so incredibly useful.. I can't count how many times I have done the following in go
x, err := Foo()
if err != nil { return nil, err } // or something like this
I'm pretty sure a large chunk of the LOC reduction was in that alone. Though, a large chunk is also some crates that make a lot of boilerplate go away (serde, serde_json, etc).
It works perfectly well with stdin/stdout as well, as seen in many LSPs
As a new joiner, some things have a "religious" feeling, like: the go gods have given us THE language and we must use it their way, without questioning too much.
I have the feeling other languages are less opinionated and this allows for more ergonomics and comfort when developing.
It's a language built to make it hard for new joiners to mindlessly add complexity, as the language itself will fight you. It makes it hard to add dependencies that aren't very visible and vendored in, it makes it hard to change how the language behaves with overloading, preprocessor magic or macros, and so on.
It's built to fit Google specifically, with their army of new grads, and deep investment into reinventing all the dependencies themselves, and having a huge monorepo.
If you're not google, you're gonna have a bad time, which is also good for google.
When engineers focus on language features they focus on the wrong things. Yes, languages like Java and Rust are fantastic for large codebases because generics and strong encapsulation become especially important as the number of engineers working on a project scales. Contrarily, Go would probably be a million times better for a small project of one to three staff that primarily revolves around a few well-designed data structures and basic array manipulation. In this context, the more sophisticated features of a Rust or Java are actually hindrances and end up making things more elaborate than needed.
Languages are a resource and a tool, not an identity marker. Use the language that makes sense for your constraints. Programming is all about modeling problems. No language will do this for you and each one has features that help or hinder and some are better or worse form problems of different shapes. Learn about how computers and compilers actually work so that you are empowered to use a wealth of languages and can choose the best one for your project on rational grounds.
Or, you can embrace Haskell and use the only perfect programming language to have been thus far invented :)
Is the author implying that Go was created by accident?
1) Sum types (E.G. C/C++ union types) - Yeah, something similar to that should exist... it's syntax sugar over #2
2) 'casting' / reshaping perspective on data ; as long as something has the same struct size a programmer should be able to tell the compiler 'but this is actually that'. Which also implies a way of fixing the layout of a given data structure. I figure that's why Golang doesn't allow this already.
Yeah, 24 bytes (len, cap, pointer) per slice (dynamic array) has a cost, but if that really gets your goat use a fixed size array, or pointer/reference to such [n]thing.
3) Seriously, for a slice, make it like a map, a pointer/reference to a len,cap,blob - so that when I pass a slice by value I pass the WHOLE slice, not a COPY of len and cap and a reference to the slab. Current golang has the worst of all worlds with passing slices around, in that changes mutate, UNTIL it's resized or manually copied. The current design has the behavior it does to support slices of slices, which requires the pointer to the blob. A more complex scheme of a container behind the slice, and references to that could also work, but would be an entirely different datatype.
I can't put my finger on why it was so off-putting, but it just left a bad taste.
Maps 'work' because as a programmer you're aware of how expensive it is to copy a whole hash table, and it makes sense that a pointer to the thing is the whole thing. So it's an exception, but one _clean_ exception that just behaves consistently.
Slices are horrid in that they SOMETIMES work the way someone who passes by value expects, and that's the same for both NOT updating AND Updating. This is because the management stage is passed by copy, not reference, but the backing data IS a reference, which initially is copied. That leads to in-place overwrites when no change in size has happened. It leads to appends that do get written but not reflected in other copies of the slice, and then if there's a need to re-allocate it leads to even the updates not updating the other copies of the slice.
Slices are the most beginner un-friendly part of Golang.
At this point, I prefer strict Typescript with very restrictive ESLint rules than Go. I don't understand how this language was pushed for web servers, it lacks common constructions to represent very frequent data types in API design.
Also, the whole go func(){} and channels is nice if you are coming from a language with worse ergonomics (C?), but when doing multiple web requests to other places and wanting them to happen in parallel, it gets messy fast. It lacks a pretty abstraction -- I very much miss an await-like construction which uses wait groups under the hood.
So, I very much agree with the post. I like errors as values, though.
Go's channels are probably awesome, if you need parallel computing.
If you want to build in k8s land, you can't avoid Go.
But besides that?
Maybe, use Gleam or Elixir.
NO. Not necessarily. Use a handsaw to fell a forest if you like, or a hoe to till 1,000 acres. But I will not. Tool simplicity will come back to bite you if the task you're trying to accomplish is complex or high-scale. And simplicity of design in no way correlates to simplicity of outcome, or of your workflow using the tool.
Golang has, to be fair, more going for it than just its relative simplicity. But in many ways the OG criticism rings solidly true. The "we'll do just enough language features and tooling" becomes an abdication and an excuse in a complex world.
Explicit error handling means that I actually think about and handle errors. No surprises in production. No random exceptions throwing deep inside some dependency. I've been running some Go services for years with no crashes.
The brain-dead simplicity means I am not tempted to waste time being clever.
The tooling means my code is trivial to build, even years later on a new machine.
For my personal background, i started with golang about 6 years ago and im using it mainly for private and open source projects.
Yes golang for sure isn't perfect, but what language is tho? I think the major point is - the language you use should match your use case. If it doesn't it will always feel "bad" or you will more likely tend to find points why the language isn't perfect (for your needs).
Sure you could write a website builder in ASM or you can write an Operation System in Javascript - but why should you?
Just look at your use case - check your needs and decide what language fits the best.
If its golang? Fine use it. If its not golang, than don't. But don't take a language and try to match it on "everything" and than complain that it doesn't do the job - because no language will.
Thats my 5 cent's on this topic....
I want to orchestrate asynchronous, highly fallible tasks. I could use Rust but I feel I would drown in correctness of handling various edge cases over which I’d rather panic and wind down everything I can.
Elixir/Erlang would also be an option, but getting it installed in specific version isn’t simple (and ASDF was guilty for long time of installing Elixir built on different OTP than defined one) and also problem lies in interacting with IOs, which also bring consequences.
And so, yeah, Go is simple enough so that I feel confident that if aj get hit by a bus there won’t be enough magic so that it won’t be picked up by someone and it… works.
After being in pull rope competitions with bash, sh, Perl and Python I have fun working with it.
Really? Are you not using gopls? It absolutely will warn you about this. And the mutex case. And a lot of the other similar criticisms.
> Go not letting you do operator overloading, harkening back to the Java days where a == b isn't the same as a.equals(b)
In languages that have it I've never used operator overloading to produce anything good or that was obviously better than just using methods.
> The Go toolchain does not use the assembly language everyone else knows about.
Honestly I've never noticed or had to care. And you can build plenty of things that don't require CGO.
The whole "gnostic" tone in language articles on HN is becoming overbearing. There are parts of the language to criticize but couching it in this "lies _we_ tell ourselves" and somewhat kitchy writing that presents minor matters of taste as fully existential issues makes this an unsatisfying read.
I used a Scala library for S3 once that overloaded + to mean upload.
var bucket; var file;
bucket + file;
Which is obviously bad and unnecessary.It's really a feature that should be used very rarely by those who make basic libraries, but there it can make a lot of sense - data structures, numeric types, etc.
There are much better examples of the operator overloading for example cons:
item :: item2
Later you can break that down in pattern matching.
There is a huge difference between no value and default value. I had plenty cases where I needed to distinguish them because absent value is a violation of a contract. Defaults are not a solution.
And more. Defaults bring their own problem. Chosen values are neutral only for some operations. The most simplest case - int default value is 0, but it kinda "works" only for sums. With nulls you'll get an error in production. With defaults discovery of the error is postponed even more. It's literally the same as making up values ignoring clients will (and this decision even not ours but designers of the lang).
Defaults are implicit. It's simplifies mistakes due to human factor.
I've developed in all kinds of languages in the past: Pearl, Java, C++, REALBasic, PowerMOPS (a Forth derivate in the 90s), Ada, Rust, Python, Java, Racket and various scheme dialects, CommonLisp, ObjectPascal/Lazarus, just to name a few. Out of these, REALBasic was by far the one in which I was most productive. Alas, it became unaffordable and the vendor lock-in really burned me. No more commercial languages or IDEs it is for me.
If Ada had a garbage collector, I would probably use it even though the development time is a bit longer. Likewise, I'd love to use CommonLisp and think it's the best dynamic language. But it simply doesn't have enough 3rd-party support, and I'd also be wary about how it runs on mobile platforms.
I've got to say I'm pretty happy with Go so far. Is it the ideal language for me? No, because full OOP with multiple inheritance would make my life much easier. But it works, is easy and fast to develop in, and the results speak for themselves. I have no problems with bugs. The explicit error handling may be a bit cumbersome but it forces you to think about and deal with every error, unlike people in languages with exception system who often ignore errors until so far up the call chain that they don't even know what actually happened any longer. I don't see the point of that. If you have an illegal state of an object it doesn't matter if you call the object nil or DefunctInstanceOfBla, you're going to have to deal explicitly with the illegal state.
Notably, C# was also in my final selection of languages. For my principal use case - distributed client/server applications with GUI - Go's GUI options were not so stellar and I was thinking about using C# instead. AFAIK, C# is very suitable and a great language, too. I decided against it because of the C#'s bizarrely complex runtime library situation and naming schemes (WTF?) and simply because I would have had to learn it first and already knew Go fairly well.
Beware the language aficionados and purists. I used to be one of them, too, advocating Scheme & CL. However, in the end purely practical considerations are always more important. Programming languages are tools for getting things done.
Please note, no offense intended, I just like this quote to describe Go success.
I've written code that runs in production for 20 years now and every language I ever shipped software with, from ASP, PHP, and C# to Swift, TypeScript and Rust, one thing is always true: there's a pretty good reason the language was picked, and yet a long list of grievances. The reason a language is picked is most often productivity, some belief that software will ship more safely and often if we pick this language. Of course that belief can be uninformed and proven wrong later. But it's really hard to say, for any language, that "you will regret picking this language".
Sure maybe you shouldn't pick PHP for your new startup backend because you'll have a harder time finding developers. Maybe you shouldn't pick Python because despite asyncio there's still that one call you accidentally did that will lock up your highly concurrent service. Maybe you shouldn't pick Java because it's got verbose factories and something about billion dollar mistakes. Possibly picking Rust is a mistake because your developer team will spend 80% of their time fighting the borrow checker. Picking Swift to do your backend seems rather odd, and C++ is too risky with all its undefined behaviors and segmentation faults. Beware of Node.js unless you're ready to dedicate beefy RAM instances to it.
That is of course all hyperbole, I've seen productive code in all of the above languages. And I should add that many of them were not designed any more than Go was, to address one of the author's concerns. I've picked Go many times since it hit 1.0 and I don't regret it, even with production code that is over 10 years old. Go does concurrent processes and I/O really well. The GC works very well for long-running programs with lots and lots of individual goroutines. I also saw developers that had never touched Go enter the code base and make productive edits, which I consider a benefit of Go's simple design (or non-design, as per the author). I've also done similar systems in other languages, especially Node.js, Python, and Rust, but they haven't been as productive in my experience for this use case.
Ironically code written in Rust did wake me up in the middle of the night more than Go did, possibly because it was harder to express the mental model the way originally intended, and instead the code was written to satisfy the computer's memory model. I would still use Rust every day for things where that matters more, but the author seemed to imply somehow avoiding Go avoids unexpected errors, but they happen in every language.
TLDR: Programming languages live on because they make people feel productive. Maybe this feeling is aligned with the business needs, maybe not. But don't go saying that everyone should avoid a language entirely because of your personal experiences.
Since these blog posts were written, Go has made official the interning approach that the netaddr.IP type depended on, now without the horrible pointer hacks, and the IP type itself has been migrated into an official package with even more improvements, now benefitting everyone. The iOS network extension memory problem was a very nice deep dive into what happens behind the scenes (something that is assuredly not perfect in any language) and resulted in a better Go experience for everyone using the language.
So a team pushed the limits of a language and made the language better for everyone out of the box. This happens in most languages, but rarely do you see such approachable blog posts about it, where the solutions are readable in the language itself, and with enough commentary even understandable.
I recommend reading these articles as examples of good language evolution, not as examples of a broken language.
First off, let's appreciate the fact the author has managed to write this humongous article in a day. That's some writing skill.
And indeed, leveraging writing skills to unleash a flood of words in order to overwhelm anyone trying to respond is just the first tactic of many used by the author to sound more convincing, which is going to be the point of my post. I'm going to analyze each rhetorical device, fallacy, and bias present in the article.
> The author is a platypus
The point of this paragraph is not to present any arguments, it is devoid of them, but to elicit sympathy from the reader for the poor author who is clearly getting ganged up upon. Comments in the referenced HN thread did not in fact attack the credentials of the author in any way. See Appeal to pity [3].
> Mom smokes, so it's probably okay
Lots of words here, but the gist of it is:
> Or you can be horrified, as you realize that those complex problems only exist because Go is being used. Those complex problems would not exist in other languages, not even in C, which I can definitely not be accused of shilling for (and would not recommend as a Go replacement).
Setting aside the validity of the technical arguments, the tactic used here is to imply that since certain other languages don't have the specific mentioned problems, they are strictly superior. In reality, had another language been used, the Tailscale team would simply be dealing with different problems. To riff off the C example, if Tailscale used C, they'd be dealing with memory safety issues instead.
> The good parts
A clever attempt at a lie of omission. First we list a tiny subset of the pros of Go, then we claim that this tiny subset is not enough to make up for the numerous cons. See Cherry picking [4] and Straw man [5].
> And since, just like C and Java, you do not get to decide what is mutable and what is immutable (the const keyword in C is essentially advisory, kinda), passing a reference to something (to avoid a costly copy, for example) is fraught with risk, like it getting mutated from under you, or it being held somewhere forever, preventing it from being freed (a lesser, but very real, problem).
Here we see a thinly veiled reference to the main bias behind the article. Can you guess what language the author is implicitly talking about here?
> Go is an island
Nothing really interesting here, but it's worth noting that, just like the majority of arguments presented so far, this largely applies to most languages out there (but of course not to the language we're really talking about here).
> All or nothing (so let's do nothing)
The thrust is another strawman, quite simply nobody argues this: "It's not like you can prevent all problems anyway.".
This section is only a lead-up to the next one anyway...
> "Rust is perfect and you're all idiots"
Huh, why do we suddenly have a tirade about Rust in what's supposedly an article on Go? If you correctly guessed earlier that this entire article is actually about Rust, congratulations.
> Folks who develop an allergic reaction to "big balls of mutable state without sum types" tend to gravitate towards languages that gives them control over mutability, lifetimes, and lets them build abstractions. That those languages happen to often be Go and Rust is immaterial.
Wait a second, language*s* with sum types, control over mutability, and lifetimes? So, Rust, Rust, and Rust?
> Because function signatures don't tell you much of anything (does this mutate data? does it hold onto it? [...]
Only Rust is good enough, we get it already.
---
Overall, we have quite a few strong technical points here that could have made for a compelling article, but they're marred by copious use of fallacious arguments and blind fanboyism for a certain language.
---
[1]: https://news.ycombinator.com/item?id=31191700
[2]: https://news.ycombinator.com/item?id=31205072
[3]: https://en.wikipedia.org/wiki/Appeal_to_pity
Not everyone cares about correctness at scale! Python for example is a perfectly fine language to use when getting something out is more important than being correct at scale. A lot of game dev can also live without full correctness because things like player positions can just be fixed up afterwards if there's a bug. But if correctness at scale is a priority, Rust is the only serious imperative option.
> As it happens, I am not a junior developer, far from it. Some way or another, over the past 12 years,
I'd say that's isn't too far from it to be fair.
Or maybe the links are left to the default for the browser to decide.
Either way I would prefer an easier to read color.
The majority of code we write runs on servers, even if its ultimately in service of a mobile/web client. Even if mobiles didn't support them, that doesn't mean these languages will die. The servers still have to run.
Creating the tools to run them on mobile is a solvable problem. Rust is already supported in the Android platform [1]. It takes more work to write an application in a non-standard language but its doable. Just saying don't worry about every other language dying out because of mobile, that won't happen :P
[1] https://source.android.com/docs/setup/build/rust/building-ru...
So, adding an extra struct field results in the base value, and by design this should be used as a base default. The go proverb make base values useful goes hand in hand.
Obviously functions are not the same. And calling function with the wrong args is a compile time error. There is also CI check that check for this use case.
Overall this seems like a comparison to Rust, and its obvious they are not same same. Apples to Oranges.
Of course they are not same; that's why we want to compare them in the first place: were they the same, there'd be no need to compare them at all. Since, you know, they would be same and have no differences.
I mean, come on, coming to Go and of all things complaining about brace style? Coming to Python and of all things complain about syntactically significant whitespace? Coming to Lisp and complaining about parentheses? This is so old.