Live data from Hacker News

Why I’m Frustrated with Go

dev.to

61–70 of 233 posts

Re: Why I’m Frustrated with Go

#61
post #11

I did Go for years, but stopped doing any serious work in it about a year ago. In general, I found it a chore to maintain Go-based systems. There's a lot to like about Go. But it doesn't seem pragmatic for the types of applications I see people using it for. For example, the entire error thing is absurd. Anders Hejlsberg got this right many years ago: 9 out of 10 errors are "handled" by a central error handler (log +…

> This is especially true when your system is interacting with external data - like user input and a database. I did C# and Java for years. These interactions are, at best, painful with static languages. Why? I find when you're importing external data or user input, that's exactly where you want strong types as that's the most likely place unexpected values are going to be generated (e.g. unexpected null values, stri…

I don't disagree. It's just more tedious in static languages.

Let's say we're doing a user registration. In most dynamic languages the JSON body will get parsed into a map. Excuse the fat controller and pseudo-language, but it'll end up looking something like:

    func create(conn, params) do
      if not Validator.is_email?(params["email"]) do
        return error(conn, "email is not valid")
      end

      if not Validator.min_length?(params["password"], 10) do
        return error(conn, "password must be 10 or more characters")
      end
     
      create_user(params)
      true
    end
In Go, if you want this nice and typed, you'd add a RegistrationInput struct with the field mapping tags:

    type RegistrationInput struct {
       Email string `json:"email"`
       Password string `json:"password"`
    }
Map the user's input to the structure, handling the error:

    var input RegistrationInput
    if err := json.Unmarshal(req.body, &input); err != nil {
      ...
    }
And then write the exact same validation checks.

What safety does Go's version buy you?

Re: Why I’m Frustrated with Go

#62
post #33

Earlier quoted context omitted.

Another thing I can think of - Go's interface mechanism overhead is usually significant, and I've also found that the networking stack is slow compared to raw C. When I brought this up on the user group a few years ago I was told that this is a fair price to pay for Go's safety and concurrency abstractions. I pretty much agree actually. I won't be necessarily writing a database in Go, but for robust and fast applicat…

Re: databases in Go, I remember seeing a lot of these concerns a few years ago but it looks like many people found a way to make it work: https://github.com/avelino/awesome-go/blob/master/README.md#...

I actually experimented with a "database" of sorts, a redis compatible server with replication, persistence and an extendable API. It was okay as a toy project but never came close to redis performance, even when it only did ping/pong. Plus it had the issue of stop-the-world GC that was how Go worked back then. Not sure how well it would work today.

Re: Why I’m Frustrated with Go

#63

So, once upon a time I wanted to associate information with http connections (as I am accustomed to in every other language I've ever written) just to enable proper http keepalive and debugging through a proxy written in Go. Ended up with this. [0] Turns out the Go authors don't think you should do this so I had to majorly alter and recompile the stdlib. I still appreciate many go tools and the cross platform single…

That's more a criticism of the standard HTTP server, which is a bit of a black box, apparently intentionally. There's nothing wrong with writing your own server to make up for it's limitations.

Re: Why I’m Frustrated with Go

#64

> You know how much code I’d have to write if this were C++, C#, or Java? None. They all have reusable notions of an immutable, ordered map. Actually C++ doesn't have immutable data unless you count compile-time constants and literals. You can declare things 'const', but that only provides a read-only (1) view on mutable data. Also, to provide good 'const' support in containers, you usually have to provide extra read…

Let's take this const map:

  const std::map constMap = { {1,1}, {2,2 } };
Or take a const map copy-constructed from from a non-const map, if you wish.

How is this not immutable data, and "only provides a read-only view"?

It is linguistically guaranteed to be non-mutating - const-casts excepted of course.

All languages that are constructing const data types on the fly are putting them in a writeable pages in memory, after all.

Re: Why I’m Frustrated with Go

#65
post #39

The OP suggests "some form of codegen" as a way of getting around the Go dev team's, shall we say ... unusual hostility toward generics. But that way lies C++ templates, which were originally meant to be implemented as macro-generation -- and which lead to the messiness and complexity of C++ builds which were one of their major reasons for doing a new language in the first place.

Templates don't help C++ build times, but the root problem is that it uses the C model for compilation (several sequential passes).

D compiles faster than Go usually and with templated generics all over its std lib

Re: Why I’m Frustrated with Go

#66

Earlier quoted context omitted.

>I found it a chore to maintain Go-based systems My opinion is the opposite. Almost every go code base I've seen is extremely consistent compared to other languages. Going from one code base to another is almost always seamless because learning Go involves learning the Go tools which forces you to follow Go coding standards. I'd choose to work on a Go code base over Java or C++ any day of the week. I don't have much…

>> the entire error thing is absurd. Anders Hejlsberg got th is right many years ago: 9 out of 10 errors are "handled" by a central error handler > This is almost always unacceptable in production, especially when it comes to mission critical hard/software. You need to be able to handle errors in production that you may not even be able to catch in testing and that means you need to catch all the errors and think cri…

Exactly, once you wrap errors with their context, or just at the lowest level wrap it with a stack trace, they become much more useful.

Re: Why I’m Frustrated with Go

#67
post #38

OT: I recently learned that the newer ETH client Parity is written in Rust and much faster than the older Go-based Geth ETH client. Guess it is due to a different architecture and design which makes the client faster (e.g. chaindata is smaller) but does anyone know why they chose Rust instead of Go for the Parity client?

I would think having better safety guarantees is a big reason. Rustc can detect data races, which I'd say it's very useful with an Ethereum client.

Go can detect data races as well, not sure it's the reason. Probably performance.

Re: Why I’m Frustrated with Go

#68
post #33

Earlier quoted context omitted.

Rust bounds-checks indexes by default (there exist indexing methods which bypass that, they are unsafe).

Another thing I can think of - Go's interface mechanism overhead is usually significant, and I've also found that the networking stack is slow compared to raw C. When I brought this up on the user group a few years ago I was told that this is a fair price to pay for Go's safety and concurrency abstractions. I pretty much agree actually. I won't be necessarily writing a database in Go, but for robust and fast applicat…

> Another thing I can think of - Go's interface mechanism overhead is usually significant

Yes that's a more likely culprit, interfaces mean dynamic dispatch, outside of hand-rolled codegen I don't think Go can statically dispatch abstractions.

Re: Why I’m Frustrated with Go

#69
I think you have to work with the language you're in. I had similar frustrations when I first moved into doing some dev in Java and C# and it really bugged me that there was no compile-time guarantee that an Object reference passed as a method parameter would not be modified within that method (as I was so used to using const-refs with in C++)

In retrospect however, I was frustrated with these languages because I was wanting it to be something it wasn't. To my mind, the loss of that feature meant that programs were less expressive - particularly in large codebases - I had to read methods to work out if something was being modified or not.

To complain here about Go lacking immutability and constness features seems to be the same as complaining that it is missing in Python, Ruby or JavaScript. It's a fact that constness isn't a feature of these languages, if you want these features, use a different language.

Re: Why I’m Frustrated with Go

#70
post #11

I did Go for years, but stopped doing any serious work in it about a year ago. In general, I found it a chore to maintain Go-based systems. There's a lot to like about Go. But it doesn't seem pragmatic for the types of applications I see people using it for. For example, the entire error thing is absurd. Anders Hejlsberg got this right many years ago: 9 out of 10 errors are "handled" by a central error handler (log +…

> This is especially true when your system is interacting with external data - like user input and a database. I did C# and Java for years. These interactions are, at best, painful with static languages. Why? I find when you're importing external data or user input, that's exactly where you want strong types as that's the most likely place unexpected values are going to be generated (e.g. unexpected null values, stri…

No matter where the data comes from, there's so much more validation to be done that types can't handle. Why should validation concerns be split up?
Post reply on HN