Top
Best
New

Posted by xngbuilds 1 day ago

Just Use Go(blainsmith.com)
214 points | 201 comments
dualvariable 1 day ago|
> if err != nil is the feature, not the bug. It forces you to look at every place something can go wrong and decide what to do about it.

No it really doesn't. It litters your code with if statements that are all just about the same, except that one that needs to be different, and you go blind looking at them all and can't spot the difference. And these days people probably just type "tab" and their LLM assistant fills out the entire block incorrectly in one keypress copying the pattern from everything else.

But LLMs didn't create that problem. Having to type something never meant you had to think about it, or thousands of "sudo shutdown -r now" commands would never have been run on production databases, because typing "sudo" would have magically made someone think about it, rather than just being keyboard memory.

And the problem of reviewing the code and spotting the one error handling block that should be different from all the others is always going to be there for human reviewers.

Rust converts the common case boilerplate down into one character: ? which lets you focus on any exceptional error handling rather than a wall of if statements that almost all look alike. And the compiler can see that you're ignoring a Result from a function call and force you to explicitly do something about. Plus you can then use a monad without knowing a single thing about monoids, endofuctors or category theory, and impress your friends.

potato-peeler 1 day ago||
> No it really doesn't. It litters your code with if statements that are all just about the same

Wrong thing to be bothered with. This allows static analysis of every possible path the code can take. Try to do that with throw/catch. There is a reason many industry guidelines like misra, jsf, etc just outright ban hidden paths. They have been literally catastrophic. There is a reason why many modern languages like go, rust, etc, want errors to be explicitly handled.

Go documentation specifically reasons why they treat errors-as-values and why is it like that - https://go.dev/doc/faq#exceptions

> Rust converts the common case boilerplate down into one character: ? which lets you focus on any exceptional error handling rather than a wall of if statements that almost all look alike

Again, wrong way to look at errors. Errors are not a problem for a compiler to resolve. Errors are part of your business logic. They need to be explicit and handled. The syntax of one language vs another is not the point of error handling. Errors are not a distraction. It is your job to review each path the code can take.

Code may be written once, but code is always reviewed or audited or referenced more than once. No one is impressed if you write some meta magic one-liner. I would rather be more impressed if I can read your code and form a mental image on how many paths your code takes to achieve an outcome in a single sitting, instead of pinging you for a quick call to explain yourself.

> you go blind looking at them all and can't spot the difference

> And these days people probably just type "tab" and their LLM assistant fills out the entire block incorrectly in one keypress copying the pattern from everything else

Now, if someone is 'going blind' looking at error checks, its because their function is doing too much and has too many failure points. Perhaps one may need to focus on honing their software engineering skills on how to structure their code, instead of hitting that 'tab' more so often.

jesseschalken 1 day ago|||
Go has plenty of hidden code paths in defer, panic and recover. You can minimise the use of those things, just like in other languages you can minimise use of try-catch in favour of a Result sum type, which is already better than Go's "multiple return that you have to pretend is a sum".
potato-peeler 1 day ago||
Which is what should be discussed about go, rather than if-err clauses. That is hardly an issue in go. But Go has these little quirks which, if not careful, can become a problem. But instead most go critiques discuss only the error handling syntax. Look at the other comments.

The article is on point on the strengths of go, and in many cases, those other languages you say, you will find it really hard to do the same thing with the ease with which you can do in go.

What the article glosses over, is the footguns with working with the language. No compile time nil checks, implicit interfaces, lack of sum types, like you said, which more so often leads to bloated structs, member visibility which is just private and public. You can find more.

But these problems were not the main focus of go. Go was build because google devs wanted a simpler way to manage and deploy their software across thousands of services, not having to wait forever for their code to compile, not worrying about writing cpp code in the BEST possible industry standard, ability to do parallel processing of hundreds or thousands of workloads without choking your cpu, managing dependency hell. These were actual roadblocks. And google was not the only one facing these problems. Go solved all of it. Which language was solving this before go?

pjmlp 1 day ago||
Go was developed because two UNIX guys, and one Oberon guy, that didn't like C++ decided to create their own thing, and their manager decided to support them as their 20% project.

Nothing else.

The narrative of Google wanting Go never happened, it gets sold as such by many Googlers.

Even Kubernetes was originally written in Java, before some Go folks joined in and drove the rewrite into Go, which besides the Android build system are the only two key projects using Go.

potato-peeler 1 day ago||
https://go.dev/doc/faq#creating_a_new_language
pjmlp 1 day ago||
Yes, and?

Most of that was written by the Go team, not Google management, and even has the famous Rob Pike take on it.

The You Tube download rewrite from Python to Go, wasn't a management decision, rather yet another case of Go team taking language marketing into their own hands.

You will find posts from me on golang-nuts pre-1.0 days, as I was hopeful it would turn out differently back then, so I don't need education on how Go came to be.

potato-peeler 1 day ago||
> Most of that was written by the Go team, not Google management, and even has the famous Rob Pike take on it.

I am unable to understand your point or you seem to be making arguments that have nothing to do with the article nor with my earlier replies. I wonder why. Are you expecting sundar pichai to announce golang to his shareholders in his quarterly call? Which language does that?

This article and my replies are technical in nature. You need to have a technical response to a technical problem. You cant get emotional everytime. Which language allows me fast builds, lightweight and high performance concurrency, strong stdlib and tooling, easy cross compilation with static binaries, simple syntax, decent performance and by that i mean not worrying too much on memory management, easy onboarding and large scale maintainability? I am willing to try that tool.

pjmlp 1 day ago||
Because your narrative is wrong, it wasn't a Google project, it was a group of Google employees that rebeled and were lucky to have their line manager support, given being UNIX idols.

Google upper management was, and is, perfectly fine with Java, Kotlin, C++ and Rust, for the most purposes.

I won't suggest any "technical" answer, because clearly you only want Go.

potato-peeler 20 hours ago||
> I won't suggest any "technical" answer, because clearly you only want Go

You can’t provide me any technical answer.

amomchilov 1 day ago||||
I agree with all the motives you describe, yet come to the exact opposite conclusion.

The overwhelmingly common case is for an error in a nested call to be bubbled up to be handled by a parent call. If you make this common case look similar to the distinct case of actually handling an error, you just obscure where the real error handling happens.

Writing good error handling is Go is really hindered by two other issues mixing together: 1. There’s no Result type, so while it tries to treat errors as values, it’s missing out on a lot of the benefit of that idea. 2. Multiple function return values are implemented as a special case, and aren’t themselves a value

Most languages that support multiple return values, do it via some notion of tuples: returning a single aggregate value that you can pass around as a whole, but that also have some nice syntax for destructuring them into local variables. Go implements as a syntactic special case.

You can’t assign the multiple return values of a function call into a single variable. You’re forced to take all the parts, and pack them into a struct yourself. This means that you can’t factor your result-handling logic into testable functions, without needing to do this dance at every call site.

nurettin 1 day ago|||
> No one is impressed if you write some meta magic one-liner.

I am very impressed if they can express the entire algorithm succinctly with a one liner. That's the kind of abstraction every piece of code should strive for and be shamed to the ground if they haven't.

> I would rather be more impressed if I can read your code and form a mental image on how many paths your code takes to achieve an outcome in a single sitting, instead of pinging you for a quick call to explain yourself.

Does this mean you're impressed by the ability to read go's if spaghetti?

potato-peeler 1 day ago||
> if they can express the entire algorithm succinctly with a one liner > That's the kind of abstraction every piece of code should strive for and be shamed to the ground if they haven

This obsession with one liners is inversely proportional to professional experience.

nurettin 22 hours ago||
> This obsession with one liners is inversely proportional to professional experience.

Yes, I see this sentiment on every billboard. It is a sign of mediocrity.

clausecker 3 hours ago||
> No it really doesn't. It litters your code with if statements that are all just about the same, except that one that needs to be different, and you go blind looking at them all and can't spot the difference.

If most of your error handling is just bubbling the error up, you are doing something wrong.

  if err != nil { return err; }
is an antipattern. Not because it's verbose, but because you are supposed to handle the error, not pass it right through, in most cases.
treis 1 day ago||
There's a lot of merit in this. I call Go the Honda Odyssey Minivan of the programming world. It doesn't do anything exceptionally well but it does lots really well and in a way that's simple and reliable. Especially for the backend serving react front end niche.

But it's also a pig to write and comes with a lot of foot guns. Especially the Null handling. Somehow they made it worse than every other language.

lanstin 1 day ago||
Nilaway linter FTW here.
a012 1 day ago||
Why the Null handling and in Go is worse than others?
kevinmgranger 1 day ago|||
Another reason why it's worse is how it breaks logical laws thanks to the nil interface bug: https://go.dev/doc/faq#nil_error

Well, they'll call it a design decision, not a bug. I guess I'm being charitable.

oconnor663 1 day ago||||
Some weird nils don't compare equal to other nils. It's surprisingly easy to construct the weird kind by accident, because the conversion is automatic and invisible.
treis 1 day ago||||
It sets primitives to 0, "", false etc. Which is almost always but not always fine. And if they're complex objects you still get NPEs

To get true nullable fields you need to use pointers. That's a whole topic in itself but they're awkward.

It's much worse than true nullable objects that your compiler can check for NPEs. It throws fewer NPEs but at the expense of data integrity where you don't know if your 0 is actually a 0 from the user or a null.

Lvl999Noob 1 day ago||
What if Go went all the way? Referencing a zero pointer (nil) gives you the zero value of the pointed to type. If you try to access a zero map, it tries to deference the zero pointer to the underlying buffer. The zero pointer gives you the zero slice with zero length. The presence check fails without crashing and you get some pretension of reasonable behaviour.
clausecker 3 hours ago|||
Really bad idea.

Silently returning some (the wrong) value is always worse than catching the error right then and their and panicking. A panic is a noticeable symptom of something just having go wrong that is easy to chase after and debug. A silently returned wrong value just causes data corruption down the line, at great pain. It is very annoying to debug, in particular if people start to some times rely on this behaviour as an intentional part of their data flow.

ptman 1 day ago|||
So what happens when you write through the nil pointer?
Lvl999Noob 1 day ago|||
Well, what happens when you write through an invalid pointer? The runtime can swallow the write or crash the program or allocate new storage and replace the pointer. Depends on the wanted semantics.
chuckadams 1 day ago|||
Nil of course (nothing happens). Not saying it’s a good idea, it would just be consistent.
MintPaw 1 day ago|||
I think there's a large subset of programmers now who consider null checking (or even the existence of null) to be bad, and prefer something else like exceptions or option types. I don't get it personally.
chuckadams 1 day ago||
The existence of null is not the problem, it’s when null populates every single non-primitive type, making every access into a logic bomb unless explicitly checked. When null is a distinct type, there’s no problem at all.
thomascgalvin 1 day ago||
I like go, but a lot of little things stop me from loving it.

Like, enums. I get a lot out of the box when I use an enum in Java or Kotlin. Converting to/from a String is trivial. Type safety ... exists.

I can do that in Go, but I have to hack it in, for every single enum type I want to represent. Enums are not a thing in the language, which means its easier to keep the language in your brain all at once, but at the expense of making it harder to keep the software I'm writing in my head. Is this "enum" the same as that "enum"? I have to go read the code to figure it out.

But Go is excellent at a lot of things. Compile times, static binaries, resources compiled right into that binary, execution speed ... there is a lot to love.

nick_ 1 day ago||
The convention of explicit error handling after every method call is absolutely bonkers to me. I would never use it for anything serious.
therealdrag0 1 day ago||
I recently vibe coded a large app in Go, it’s so mind-numbing to read. Like half the code base is error handling.
nick_ 1 day ago||
The anti-exception mind virus of the 2010s did a lot of damage. Go designers finally caved and added panic & recover, but jeez, the damage was done. The whole ecosystem has exception derangement syndrome.
clausecker 3 hours ago||
Go had panic/recover right from the get go. Nobody “caved.” And indeed, you are free to use panic/recover for error handling in your code. That was always allowed.

That said, the key insight of the exception craze is that error returns are a normal part of a functions behaviour and as such should not use extraordinary control flow to take place.

Exceptions (panics) are used for things that should never happen or are indicative of a programmer error, like nil dereferences or out-of-bounds array accesses. That is, things where the programmer is not expected to provide reasonable behaviour on the API level if it happens (but perhaps there is a whole-program fault handler to shut down cleanly).

Opening a file that does not exist? Database record not found? Invalid credentials? These should be anticipated by the programmer and can occur at any time. Not exceptions, normal return values. Go requests that you think about these possibilities instead of pretending they can be ignored.

ntrianta90 1 day ago||
I really wish they had added Enums instead of the stupid generics.
pjmlp 1 day ago||
I would already be happy with enumerations Pascal style from 1976, without the const/iota dance.
0xbadcafebee 1 day ago||
Since AI coding, I've switched 90% of my code to Go. It's really great for most things. Lacks a development community large enough to have a really solid UI framework, but the existing frameworks are "good enough". I used AI to make an AI agent that works on Windows, Linux, Mac, iOS, and Android, with CLI, GUI, and web serving. LOC: 5575. Binary size: 35MB.

Also: why can't we vouch for flagged stories now? This post is actually good, and funny, and the conversations are worth having.

codegeek 1 day ago||
I love Go. But I prefer .NET for web development that also compiles to a binary and has a great ecosystem of libraries and packages. Go is great if standard library works (and it can for many cases) but when you need to start looking into non standard libraries, Go can hit limitations.

For example, to build a full production web application with database in Go, there is no great out of the box migration tool. There are some good 3rd party libraries of course but compared to something like EFCore in .NET, they don't come as close.

For me, it is now .NET and then Go. Of course, I use Go when just doing a lot of non web stuff as well.

bronlund 1 day ago||
Comparing Go and .NET is like comparing a Honda with an aircraft carrier with wheels.
MarkSweep 1 day ago||
Eh, at least for people consuming .NET apps compiled with NativeAOT, the experience is similar. Applications can be compiled as a single file with no dependancies. A hello world in .NET is half the size of one in Go:

https://github.com/MichalStrehovsky/sizegame

cloudfudge 1 day ago||
> that also compiles to a binary

"compiles to a binary" is not a useful criterion. The criterion Go is winning on is "compiles to a single, completely self-contained binary," meaning it does not depend on libc or any external runtime. You can't say that about .NET. You can't say that about damn near any other programming language. It's extremely rare. The fact that .NET uses a binary packaging format is, like... well ok, so what?

kevinmgranger 1 day ago||
.Net can compile to a self-contained binary: https://learn.microsoft.com/en-us/dotnet/core/deploying/nati...
cloudfudge 1 day ago|||
That isn't truly self-contained. It still relies on libc.
jaen 1 day ago|||
Nah. Go also relies on libc if you do anything non-trivial, like look up a the IP address of localhost.

    $ go build -o hello main.go
    $ file hello && ldd hello
    hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, Go
        linux-vdso.so.1 (0x00007f9c7b404000)
        libc.so.6 => /usr/lib/x86_64-linux-gnu/libc.so.6 (0x00007f9c7b1ce000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f9c7b406000)
ameliaquining 1 day ago|||
You can make it statically linked using musl. (This is underdocumented because Microsoft thinks it's usually a bad idea: https://github.com/dotnet/sdk/issues/37643#issuecomment-1873...)
potato-peeler 1 day ago|||
I suppose you are missing the point. Go had support for self contained binaries since its introduction in ~2009. This was not the case with dotnet, if i am not wrong.

But nevertheless , if any language provides something like that, win-win for entire ecosystem.

xnorswap 1 day ago||
I can't see any reason this list why I should use Go over C# / .NET.

.NET has almost all these upsides, but with a concurrency model (async/await) that is (now) more transferable to other languages.

shantnutiwari 1 day ago||
Agreed-- c# has a lot of these advantages and is a lot easier to write (yes, I know this will depend). Plus it has a much larger ecosystem

The only thing I can think of: I dont think c# can compile as easy to a single executable binary, like Go (or even rust)?

xnorswap 1 day ago|||
It's had support for single exe compilation for a while now, although the file sizes can get large without being more careful about dependencies.
stackskipton 1 day ago|||
.Net SRE here, you can do self contained executable but there is some foot guns there and if you are doing containers already, I'd just skip it.
pjmlp 1 day ago|||
I only have one reason, devops ecosystem where Go is expected nowadays, like plugins for something.

Otherwise Java, .NET, Typescript (with possible C++ addons).

2ndorderthought 1 day ago||
I can see reasons why people don't want to use .NET if Go is available. .NET has its merits but it's bloated, compilation is slow, and I find it's tooling to be really annoying.

For me go is just above c# and both of those are not super high on my list.

xnorswap 1 day ago||
I've never understood what is meant by "bloated", would you mind explaining, so perhaps I could better understand?

If it's "Large standard library", I think that's a selling point. Having anything you need available ( although these days, via optional microsoft.* packages ) helps keep projects consistent between different places.

If it means "Different ways to do the same thing", I can understand that criticism better, and some of that comes with 20+ years of legacy, where the wrong thing was done, and now there's a better way, but a ruthless adherence to backward compatibility means that the old way isn't dropped.

2ndorderthought 1 day ago||
The .net sdk is like 1gb, go is like 60mb or something. It's annoying when that matters.

More so, nothing happens quickly with it's tooling, and the tooling isn't friendly. All of a sudden I can't build my project in vsstudio(also bloated but admittedly optional but may be required depending on where you work). Clean build also fails. So I have to go to the command line and type in dotnet restore, dotnet build, magic it works now. ???

Okay time to install a package because msft has its own packages for things like aspnet but now I want to serialize json. Cool newton soft sounds good. Ah now I need a package manager, I'll install nuget. Oops I need to tweak this weird xml file with lots of options.

I press compile I wait 3 minutes to realize there is an error. Okay it builds and looks good in debug mide now I want to send my application to a friend who doesn't have .net runtime...

With go it's more like. Okay I automatically have web access from the std lib. I want a framework oh I already have a package manager. Edit my toml. One command done. Time to compile, poof done in 2 seconds. I send the binary to my friend and they run it.

I understand some of these are 1 time cost things, but I am requesting you to read between the lines as these aren't examples I am trying to quibble over. The point is the friction that go has focused on removing by being quick and small. It has less legacy cruft but I tried to ignore as much of that as I could.

Also keep in mind j am not a big go fan. It's not my favorite language but it is way easier to deal with on a regular basis for me

xnorswap 1 day ago||
That's quite a rant, but it seems like it's from experience with the old times. For the last decade or so it's been a completely different story.

System.Text.Json is part of the core standard library, the only reason to use Newtonsoft is developing on legacy applications.

Visual Studio isn't necessary or even much recommended any more. VSCode or any LSP editor works fine.

You don't need to install nuget, any more than you need to install cargo in rust, it's part of the SDK. You can also just edit the csproj in the same way you could edit your TOML file. It's XML, and you just add <PackageReference="" />.

You can compile --self-contained to be able to run it somewhere without the runtime installed.

.NET has a long history, but almost none of these are actual points of friction in the current year.

2ndorderthought 2 hours ago||
I disagree as someone who was using dotnet within the last 2 years.

Also we are comparing go to .net not to rust. Go is much easier and faster tooling wise. It doesn't require an IL and doesn't have 2 decades of enterprise cruft with vendor lock in strategies baked into it.

I asked to read between the lines.

The experience behind each of these things really stinks compared to go. If you haven't tried it, I recommend it just to feel the ergonomics. I don't care for go as a language. The funny thing is, I find the tooling so much easier, better, faster than .net that even though I like c# more than go as a language, I would prefer to start a new project in go instead of say c# instead. It's that annoying for me. I've met several other people who are language ambivalent who feel the same way.

I could write a huge blog post about it with facts. I'd rather not though. People do what they like and I am not here to change what someone likes.

bloody-crow 1 day ago||
Every time I see those kind of posts, it seems reasonable on the surface. But then you remember than a typical web app might want to do something beyond just serving an HTML template.

Like, what if you want some styling or javascript along with your HTML? Either write everything by hand like it's 2003 again, or start inventing a complex pipeline from scratch in Go. Countless of people have spent thousands of man-hours on solving this problem, but you use Go, so now you do this yourself from scratch.

Or maybe your app needs some relatively complex database access? Writing SQL-spaghetti only gets you so far until you need to do conditional joins and unions and parameterized subqueries etc. God forbid you want migrations too. Go has no answer for this and you either have to hand roll all those things as well, or spend tons of time comparing countless libraries that do some of things you want, but not quite everything, or don't fit into your pipeline for whatever reason.

I'd take an opinionated framework with fat dependency stack that has way more features than I'd ever need over trying to reinvent migrations or CSS preprocessing from scratch in Go, thank you very much.

2ndorderthought 1 day ago||
Go is fine for simple applications especially backend ones that connect to the internet. I do prefer it to node/js/ts/etc.

I do think a lot of projects would be better served having been written in go instead of java, or whatever else.

I don't think it's a panacea for anything. It's pretty easy to shoot yourself in the foot with. The easy stuff is easy the hard stuff is really hard.

I like rust a little more, and I don't rewrite things with it. I choose it first. That's my preference but go ahead and gopher on.

pjmlp 1 day ago||
Yeah, it breaks when the author decides to move from Github into Gitlab to protest against Microsoft.

Time to update all code references to Gitlab across the globe, in every single Go project.

Or spend the time configuring redirects between URL mappings, across everything that depends on it.

Not to mention that except for lacking garbage collection, even Turbo Pascal 7 for MS-DOS was more modern in language features, with faster compile times, on a 20 MHz powered computer.

0xjnml 23 hours ago|
> Yeah, it breaks when the author decides to move from Github into Gitlab to protest against Microsoft.

The import path is disconnected from where the build system looks for the files. Of course, the default is to use the import path as an URL, right, but nothing forces you to do that. And if you do, *you* lock yourself to the hosting you use. But that can be hardly blamed on Go.

Documentation here: https://pkg.go.dev/cmd/go#hdr-Remote_import_paths

Full example: https://github.com/rsc/swtch/blob/master/app/rsc-io/main.go

tl;dr: Serve this at your domain, update the repo-root when changing host platform for your code: <meta name="go-import" content="import-prefix vcs repo-root">. No one else has to do anything.

pjmlp 23 hours ago||
I am well aware, as you might find out in my comment history all the way back to Go pre 1.0.

Additional work that is superfluous in other mature programming ecosystems, that don't have the dumb idea to use SCM urls as import paths.

worldsayshi 1 day ago|
I often think of go as a "better" python. As in, easy to learn and easy to use. But also performant and the module system and package manager seem to be a little neater. (sorry for flamebait)

But I wonder how well it can cover similar use cases? Go is great for devops and web backends. But what about AI and data science?

jochem9 1 day ago||
I used to do lots of data engineering in Python, then started doing all kinds of engineering in primarily Go.

The Go ecosystem for data is very limited. There are no widely supported dataframe libraries (like the og pandas and the newer polars written in rust and also available as a crate). Very few data science libs, a few decent gen AI libraries, but not as popular as their Python cousins.

Most of the work I do now is streaming data and very small batches. For that Go is amazing. I don't need dataframes to transform a json, combine it with a bunch of other data and write to a database. I just need to write that logic and make it go fast. Very easy in Go.

chubot 1 day ago||
If Go interfaced with C as well as Python, I’d use it a lot more.

But I’m using the slower language because it still integrates with more things

For example, one reason AI is all in Python is because CUDA is basically part of the C ecosystem (ie build system)

impulser_ 1 day ago|||
Have you tried purego?

You can just embed the C library into the binary of the Go app call it directly in Go. Most of the time I have found calling C from Go faster or on par with calling C from Python.

https://github.com/ebitengine/purego

tardedmeme 1 day ago|||
Go interfaces with C better than Python does...
More comments...