News for hackers. Stuff that matters.
Re:Why I’m Frustrated with Go by latch on Sunday July 23, 2017 @08:00AM (#14831855)
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 + "sorry, try again"). You can do this with error values, but at best it's verbose. Maybe error values makes sense for system programming, I could certainly believe it makes more sense.

But, really, the main problem is the type system. I'm a huge fan of dynamic languages. I think they're so much more productive. 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. But they're downright infuriating in Go (poor reflection, no generics). I wrote a somewhat popular library to help deal with map[string]interface{} nonsense (2), but it's not enough.

When it comes to web/tcp stuff, I think OpenResty for any middleware-ish system and Elixir for everything else are far more productive and enjoyable ecosystems. We've been doing Elixir for about a year now, and I've never seen such a consensus on productivity and quality (everything else always had some issue: Ruby is slow, Node is single threaded, Java is verbose).

There's certainly more space than just that. Go might still be a good choice for CLI tools, and both OpenResty and Elixir have a distinct memory/threading model that precludes some use cases - but those are in the minority.

(1) - Nothing against Erlang model, but I do think it's more restrictive.

(2) - https://github.com/karlseguin/typed

Re:Why I’m Frustrated with Go by seanwilson on Sunday July 23, 2017 @08:22AM (#14831931)
> 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, string instead of an array).

Re:Why I’m Frustrated with Go by sametmax on Sunday July 23, 2017 @09:18AM (#14832128)
Most modern dynamic languages have strong types. In Python you will get a TypeError if you try to add a string and an int or use > on a tuple and a dict.

As for data validation, the hard part of it is not checking type but that the value is safe and coherent. And dynamic languages excel at that because they make complex declarative schema descriptions easy while powerful.

See marshmallow for Python: https://marshmallow.readthedocs.io/en/latest/

It will validate everything, including nested recursive data with cross references in fields and a need for sanitation and casting. But you don't need a lot of code to do so.

Static languages are good to enforce safe practices at scale . That's why they are popular in big IT structures. Dynamic languages are fantastic when you have a lot of external data manipulations. Hence their popularity for the Web, banking, biology, geography, etc.

Re:Why I’m Frustrated with Go by seanwilson on Sunday July 23, 2017 @08:48PM (#14835213)
> Most modern dynamic languages have strong types. In Python you will get a TypeError if you try to add a string and an int or use > on a tuple and a dict.

You mean a dynamic check? It's better than nothing but I don't exactly want my e.g. scheduled data import process crashing because it was sent some bad data. I'd much rather have static checking and have all the possibilities accounted for before the code runs.

> As for data validation, the hard part of it is not checking type but that the value is safe and coherent. And dynamic languages excel at that because they make complex declarative schema descriptions easy while powerful.

Why couldn't you write this with static checks? Statically checked functional languages for example are great for writing compilers.

Re:Why I’m Frustrated with Go by sametmax on Monday July 24, 2017 @04:56AM (#14836865)
keyword being "easy"
Re:Why I’m Frustrated with Go by seanwilson on Monday July 24, 2017 @05:24AM (#14836986)
I just don't find that personally. Having to run the code over and over again to manually check for errors or having to write unit tests to gain confidence it's working is more difficult to me than getting help from static type checking. I mean why do you think it's always going to be more difficult with static types? Because you have to write type annotations?
Re:Why I’m Frustrated with Go by sametmax on Monday July 24, 2017 @11:29AM (#14839250)
External data are never perfectly documented or known. You usually have huge and painful experimentation phase with parsing it. Experimenting is way easier with dynamic languages. You type less. Changing your mind has a lower cost. You don't need to think about doing the right things as much.
Re:Why I’m Frustrated with Go by seanwilson on Monday July 24, 2017 @12:39PM (#14839949)
So in a statically typed language, if all I know is that I'm getting a string as input, it'll force me to deal with all the possibilities. Is it a number in the form of a string? A null value? A string that isn't a number? The type system will guide me through handling all the possibilities and enforce that I handle all of them. With dynamic typing, there's always a chance you've missed a case and next time the data comes in it'll trigger an exception.

If you have decent type inference there isn't extra typing and any time you think you're saving with dynamic languages gets eaten up having to manually fix things when errors happen at runtime. I'd much rather spend time fixing predictable compile time errors than unpredictable runtime errors.

Re:Why I’m Frustrated with Go by fnord123 on Sunday July 23, 2017 @02:49PM (#14833751)
> Most modern dynamic languages have strong types. In Python you will get a TypeError if you try to add a string and an int or use > on a tuple and a dict.

>>> (1,2) > {1: 2} True

>And dynamic languages excel at that because they make complex declarative schema descriptions easy while powerful.

Marshmallow looks like it works the same way as existing systems in statically types languages. e.g. Serde in Rust:

https://serde.rs/

This validates at compile time.

Re:Why I’m Frustrated with Go by nooorofe on Sunday July 23, 2017 @03:03PM (#14833831)

  In [60]: (1,2) > {1: 2}
  ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  <ipython-input-60-f9d83a4c8f73> in <module>()
  ----> 1 (1,2) > {1: 2}

  TypeError: '>' not supported between instances of 'tuple' and 'dict'
Re:Why I’m Frustrated with Go by sametmax on Monday July 24, 2017 @04:59AM (#14836872)
I said "modern". Python 2 is not modern. Python 3 is.

And the keyword in my schema validation sentence is "easy".

I love rust, but a low level language cannot be compared in productivity to a high level language for this stuff. They are much, much easier. That's the whole purpose. You trade easiness for rigor.

Re:Why I’m Frustrated with Go by nicwolff on Sunday July 23, 2017 @03:22PM (#14833911)
He means Python 3.
Re:Why I’m Frustrated with Go by latch on Sunday July 23, 2017 @08:58AM (#14832058)
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 by mercurial on Sunday July 23, 2017 @09:49AM (#14832239)
Well, the dynamic version won't complain until runtime the day you mix up the order of your parameters and invoke "create(params, conn)", for instance. Besides, you can make it statically impossible to generate an invalid user object with a static language. In a dynamic language, an invalid user object is just an assignation away.

Now, if we are talking about error handling, the way it is done in Go is not particularly representative. Most static languages would go with exceptions (or maybe checked exceptions in Java). Haskell/Rust/Scala would probably go with a Result type, and then it's more a question of the language giving you the tools to propagate the errors and wrap them (Rust with error-chain is excellent at this kind of thing).

Re:Why I’m Frustrated with Go by hota_mazi on Sunday July 23, 2017 @10:55AM (#14832522)
Your example actually illustrates why dynamically typed languages should be avoided in general, especially when manipulating data coming from outside.

Your code starts by making a few checks on the shape of the data you're receiving and failing earlier if some conditions are not met. Great.

Once these checks are cleared, you now know that you can materialize an object with valid values in it, something the rest of your business code will be able to manipulate. So you instantiate that new object, return it and... all the knowledge about the shape of that data is lost.

The only thing your callers will see is an Object and zero information about what operations or fields are available on this object. They'll have to guess.

With a statically typed language, you don't have such a problem. You have asserted all these properties about the data that came in, you know exactly the class of the object you are creating, why forget all this precious information that will keep your code robust?

In my experience, dynamically typed languages are at an evolutionary dead end and offer close to zero advantages over modern statically typed languages (e.g. Kotlin, Swift).

Re:Why I’m Frustrated with Go by harpiaharpyja on Sunday July 23, 2017 @12:06PM (#14832908)
> Once these checks are cleared, you now know that you can materialize an object with valid values in it, something the rest of your business code will be able to manipulate. So you instantiate that new object, return it and... all the knowledge about the shape of that data is lost.

I'm not really seeing how that necessarily falls out of the example given by GP. Could you go into that in more detail?

Is there something preventing create_user(params) from emitting an object with a well defined interface?

Re:Why I’m Frustrated with Go by hota_mazi on Sunday July 23, 2017 @12:33PM (#14833060)
That function does create an object with a well defined interface, but because you are using a dynamically typed language, that object has the type "Object" (or Any, or whatever the mono type of that language is).

If you call that function, you have no idea what the type of that object is. Only the function knows it and that information is lost as soon as the function returns.

Re:Why I’m Frustrated with Go by harpiaharpyja on Sunday July 23, 2017 @06:27PM (#14834746)
I think I will have to disagree with that. The type of object is not enforced by the compiler, but that's a long way off from "you have no idea what the type of that object is."
Re:Why I’m Frustrated with Go by hota_mazi on Sunday July 23, 2017 @07:50PM (#14834989)
The fact that the compiler cannot enforce it is a big deal since it prevents automatic refactorings, often impairs performance and overall, hinders readability.

And yes, you really have no idea what the type of that object is unless you look at the source of the function. Which is obviously suboptimal, especially if you don't have access to that source.

Re:Why I’m Frustrated with Go by Pxtl on Sunday July 23, 2017 @09:44AM (#14832221)
In C# MVC, the JSON gets deserializrd into a tree of statically-typed objects you declared beforehand. Any malformations of the JSON are an error.
Re:Why I’m Frustrated with Go by seanwilson on Sunday July 23, 2017 @08:56PM (#14835232)
> What safety does Go's version buy you?

A statically typed version guarantees you haven't made some fundamental mistakes and enables automatic refactoring.

Say we wanted to change an ID field from being a string to an int later in development for example. You've now got to hunt around all your files making sure the right type is being used. It feels incredibly primitive when you need to do this manually or have to rely on an exhaustive and annoying to maintain test suite for this.

Re:Why I’m Frustrated with Go by jasonkostempski on Sunday July 23, 2017 @09:09AM (#14832102)
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?
Re:Why I’m Frustrated with Go by Ar-Curunir on Sunday July 23, 2017 @10:25AM (#14832389)
It's one less thing to worry about, and cut out some tedious overhead for the developer?
Re:Why I’m Frustrated with Go by jasonkostempski on Wednesday July 26, 2017 @08:55AM (#14855760)
But the way it's done in static languages​, it's one more thing you have to worry about constantly, even when it's not a real concern. And when you need to parse external data, all you get for free is ugly exceptions that you have to decipher to construct a user readable error.
Re:Why I’m Frustrated with Go by dbattaglia on Sunday July 23, 2017 @09:54AM (#14832262)
Couldn't agree more. In my current life as a Ruby dev I've found the dry-struct (http://dry-rb.org/gems/dry-struct/) library a huge help in getting some level of sanity when dealing with converting inputs to data types. It also helps being able to reason about the inputs structure outside of just looking at some hash field indexing at time of use.
Re:Why I’m Frustrated with Go by junke on Sunday July 23, 2017 @08:56AM (#14832049)
Strong types, not necessarily static ones.
Re:Why I’m Frustrated with Go by atombender on Sunday July 23, 2017 @08:52AM (#14832027)
I don't like the "central exception handler" idea -- it is invariably too far away from the error site to do anything intelligent.

I do like Erlang's approach with hierarchical error domains ("processes" and "supervisor trees"), and I honestly think Go made a mistake here: The semi-recent introduction of Context acknowledges that a control hierarchy is present and an important part of a concurrent, distributed application and that there are aspects of this that need to flow through everything. The Context exists to permit a caller to call functions and launch goroutines that inherit deadlines, the ability to cancel their work, and so on. But this is a rather blunt and intrusive tool that could have been better solved by baking termination into the goroutine scheduling runtime. Of course, one reason goroutines cannot be forcibly terminated is because everything is mutable all over the place, but you could still have termination induce system-level errors that the goroutine would be forced to handle (or maybe you could safely induce a panic)... but that ship seems to have sailed a long time ago.

And yet a hierarchical approach similar to supervisor trees would have been awesome to have in Go. Managing hordes of complex, "crash only" goroutines in Go gets gnarly fast, and you tend to end up with your own ad-hoc type of supervisor trees that uses waitgroups and maps and what not to corral trees of composed workers to ensure they are all able to cancel, retry + back off, and time out appropriately. Even something like retry with backoff isn't part of the standard library, even though it's extremely core to distributed, concurrent programming.

I think I agree with Go's authors that exceptions are bad, but exceptions in an explicitly hierarchical, supervisor-type process model, where processes are "crash only", actually make sense. It means you tend to design your system into discrete parts consisting of dumb workers (that give up and crash on the smallest error) and slightly less dumb supervisors (that react to said crashes). It's not a panacea, but it's better than the loose, somewhat impoverished set of tools that Go gives you.

Re:Why I’m Frustrated with Go by KallDrexx on Sunday July 23, 2017 @11:12AM (#14832595)
I don't think a central exception handler means ONLY handle exception in one very specific point. It means that if you can handle an error handle it, otherwise let the central exception handler handle it.

I really like Elixir and the Erlang VM but supervisor trees are not a perfect solution either. For all the talk about how in Erlang you just let things fail and don't have to do defensive coding, any non-trivial application requires a lot of very thorough design on how to handle error scenarios and keep your application consistent.

If a process fails too many times too often (say your web service it's trying to ping is inaccessible) it can take out your whole supervisor. If that supervisor is holding an ETS table that holds important coordination data (but not data that requires persistence) that ETS table (and all it's data) is now completely gone, and unless that case has been handled you have a lot of processes running but not doing what they should be doing, and your application is inconsistent until you completely shut it down and restart it.

And if you don't plan for a lot of these scenarios then you will be caught completely surprised when it happens in production.

Re:Why I’m Frustrated with Go by regulation_d on Sunday July 23, 2017 @04:40PM (#14834257)
If you need an ETS table to have greater resiliency move it up higher in the supervision tree. Nothing prevents you from starting it at the application level.

Also you have a lot of control of your supervision tree. You can specify the quantity and frequency of failures that would cause a supervisor to fail. For some use cases, 3 failures in 5 seconds might be reason enough to restart that supervisor. For other use cases, a much higher failure rate might be justified.

Re:Why I’m Frustrated with Go by KallDrexx on Sunday July 23, 2017 @10:42PM (#14835546)
Right, so you have to make a lot of decisions on what things can fail, how often they should be allowed to fail, what side effects can be tolerated with a major failure, what happens if a bad process fails when it comes back up (thus risking causing the supervisor itself to cascade restart itself), etc...

These decisions are not trivial and are exacerbated because of the Actor style of flow due to the independent pieces.

So from my experience you have non-BEAM languages where a single error can take down your whole application if you don't plan your failure scenarios properly, where as in BEAM languages if you don't plan your failure scenarios properly you are more likely to end up with an inconsistent system. The former isn't that bad in a lot of circumstances as you should have an external application monitoring and restarting a critical server that's no longer running (even for BEAM systems) but the latter can be very bad because it can be a silent issue.

I have systems working at my job written in .net that have been running for over 6 months without a restart, even when Azure had failures and it could not talk to its command and control server for an hour and kept running perfectly fine with using a well thought out architecture and a well placed central error handler for generic errors without things cascading throughout the whole system.

So resiliency has less to do with language or supervisor trees and more to do with making every step has failure scenarios thought about and planned for.

Re:Why I’m Frustrated with Go by candiodari on Friday July 28, 2017 @04:51PM (#14877489)
last I heard the idea of "tombstoning" (guaranteed cancellation) in Go was impossible and given up on.
Re:Why I’m Frustrated with Go by fnord123 on Sunday July 23, 2017 @09:12AM (#14832111)
>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 + "sorry, try again").

You are correct that this is how it's often done - 9 out of 10 errors probably ARE "handled" by a central error handler. But this is an incorrect approach if the goal is a reduction of catastrophic errors.

In the following paper, "Simple Testing Can Prevent Most Critical Failures" (OSDI '14). the authors discuss how some catastrophic errors occur in distributed systems that they test (Cassandra, HBase, Redis, HDFS, MapReduce).

http://www.eecg.toronto.edu/~yuan/papers/failure_analysis_os...

Notably section 4.1: Trivial Mistakes in Error Handlers:

"""

Figure 5 further breaks down the mistakes into three categories: (i) the error handler ignores explicit errors; (ii) the error handler over-catches an exception and aborts the system; and (iii) the error handler contains “TODO” or “FIXME” in the comment.

25% of the catastrophic failures were caused by ignoring explicit errors (an error handler that only logs the error is also considered as ignoring the error). For systems written in Java, the exceptions were all explicitly thrown, whereas in Redis they were system call error returns.

"""

I haven't used Go much but I personally much prefer Rust's error handling which appears to be largely similar.

Re:Why I’m Frustrated with Go by rumcajz on Sunday July 23, 2017 @09:21AM (#14832137)
Depends on the app. In GUI, yes, why not, display an error message and you are done. In infrastructure software, OTOH, you want to handle errors in thoughtful manner. If you can't it's often better to crash the application than to continue with broken state.
Re:Why I’m Frustrated with Go by fiddlerwoaroof on Sunday July 23, 2017 @11:05AM (#14832566)
I think the distinction between errors (bugs) and exceptional situations made here[1] is important: if you have a problem because of some transient condition (an exceptional situation like a network outage or a full filesystem) then it makes sense to try to recover somehow. If you hit an error (i.e. A programming error or a bug) all you can do is abort, since you can no longer trust that the program will do the right thing.

[1]: http://joeduffyblog.com/2016/02/07/the-error-model/

Re:Why I’m Frustrated with Go by masklinn on Sunday July 23, 2017 @09:36AM (#14832196)
Erlang/Elixir is pretty interesting there in that it will "crash the application" but said application's scope is a single process (unless others are linked to it, which lets you build supervision tree and take down and restart the entire tree when one of the processes crashes).
Re:Why I’m Frustrated with Go by fnord123 on Sunday July 23, 2017 @10:01AM (#14832287)
Sure, if you're in a GUI then you report to the user that an operation failed and it's up to them to figure out what they can do about it.

As for infrastructural software, yes you want to handle errors in a more thoughtful manner. If you can't and the process has corrupted it's own stack or heap (in the case of C or C++) then sure, abort. But I'm saying this line is often chucked over to "log the exception and do nothing" too quickly because it's often the easier thing to do. 25% of catastrophic failures in this one study appear to occur because of this.

tl;dr: The devil is in the "If you can't".

Re:Why I’m Frustrated with Go by rumcajz on Monday July 24, 2017 @12:58AM (#14835986)
Yep. And lack of exceptions in languages like C or Go makes it harder to pretend you have done the right thing, if you in fact did not, given that it forces you handle every single error condition explicitly.
Re:Why I’m Frustrated with Go by fnord123 on Monday July 24, 2017 @03:13AM (#14836455)
Yes, exactly.
Re:Why I’m Frustrated with Go by brango on Sunday July 23, 2017 @03:47PM (#14834019)
I've done my first project with go. Goroutines are undoubtedly cool and I like the strong typing.

* Unfortunately error handling sucks (no stacktrace by default? Let's go back to the days of peppering print statements around just for fun).

* DB support is terrible (I've spent hours doing what I could have done in half an hour with python).

* It's so verbose, even simple things like mapping over an array to create another array requires a for-loop dance. Same for just checking if a value is in an array. Same, obviously for no exceptions which you either love or hate. I hate.

I can't see myself doing any other projects with it.

Re:Why I’m Frustrated with Go by zimpenfish on Tuesday July 25, 2017 @08:11AM (#14847093)
I get stacktraces from `panic()` - is this not what you're after?

    goroutine 1 [running]:
    main.b()
        /home/rjp/git/godiggy/test.go:8 +0x64
    main.a()
        /home/rjp/git/godiggy/test.go:13 +0x9b
    main.main()
        /home/rjp/git/godiggy/test.go:18 +0x9b
    exit status 2
Re:Why I’m Frustrated with Go by brango on Friday July 28, 2017 @08:23AM (#14873689)
I want to be able to handle errors, pass them up a few functions then log a stacktrace. I don't want to panic everywhere since robustness is important.
Re:Why I’m Frustrated with Go by ejcx on Sunday July 23, 2017 @10:37AM (#14832430)
Wat. OpenResty as an alternative to go? Wat?

Please, nobody write full fledged WebApps or all of your middleware in lua. Trust me that's a horrible idea. I have seen about everything you can do in lua/nginx and it does not turn out pretty.

Re:Why I’m Frustrated with Go by oceanghost on Sunday July 23, 2017 @11:38AM (#14832731)
I honestly thought the OP's post was a troll. Lua is for masochists.
Re:Why I’m Frustrated with Go by coldtea on Sunday July 23, 2017 @12:58PM (#14833188)
>Lua is for masochists

Is this a happy-hour for Reddit users on HN?

Re:Why I’m Frustrated with Go by weberc2 on Saturday July 29, 2017 @10:01AM (#14881252)
> I'm a huge fan of dynamic languages. I think they're so much more productive.

This hasn't been my experience. I work in Python (and JS) by day, and I can't wait until we upgrade to 3.6 so I can reasonably employ type annotations. Without them, people tend to write hacky code, such as functions which do completely different things based on the data type passed in (rather than fixing the abstraction) or build up huge, nested data structures with no formal definition (various parts of the code base just tack on whatever they like, and the documentation inevitably falls out of date). Even my prototyping is in Go, because I would rather have a compiler catch my errors than to spend tenfold the time trying to debug. Also, when I'm working in Python, I sorely miss the tooling that I have in Go and other static languages.

I don't think Go is the end-all-be-all of programming languages, but I think any dynamic language would be more productive if it was at least optionally typed.

Re:Why I’m Frustrated with Go by jorgec on Sunday July 23, 2017 @09:42AM (#14832213)
"I'm a huge fan of dynamic languages. I think they're so much more productive. This is especially true when your system is interacting with external data - like user input and a database." Im not so sure about it. Database is not dynamic and user input should be controlled, or number, or date, or text, for example an user could enters the price of a product a text.
Re:Why I’m Frustrated with Go by vince14 on Sunday July 23, 2017 @09:58AM (#14832279)
>Node is single threaded

You can still utilize all of your cores in Nodejs. So which problem are you encountering?

Re:Why I’m Frustrated with Go by coldtea on Sunday July 23, 2017 @12:59PM (#14833193)
That the utilitization of the cores is sub-par, and at a crude coarse level (node process).
Re:Why I’m Frustrated with Go by brightball on Sunday July 23, 2017 @09:22AM (#14832144)
I always wonder if the Go error issues could be handled more cleanly by using the suture library. I haven't seen widespread use but it's supposed to give a supervisor pattern to Go.
Re:Why I’m Frustrated with Go by jorangreef on Sunday July 23, 2017 @08:47AM (#14832006)
The Node event loop (the control plane) is single threaded, but the data plane is multi-threaded, you can easily write C++ bindings to run in the thread pool to handle CPU intensive work.
Re:Why I’m Frustrated with Go by tannhaeuser on Sunday July 23, 2017 @09:54AM (#14832260)
Speaking of Node in the context of error handling, what are current best practices in Node (other than running node-forever respawning)? Up to v0.12, Node used to have heuristic cleanup code for file handles and other resources on exception domain error handler execution, but the domain API has been deprecated for some time now ([1], [2]).

[1]: <https://nodejs.org/api/domain.html>

[2]: <https://github.com/nodejs/node/issues/66>

Re:Why I’m Frustrated with Go by ludwigvan on Sunday July 23, 2017 @11:04AM (#14832559)
This is pretty informative on handling errors in node: https://www.joyent.com/node-js/production/design/errors
Re:Why I’m Frustrated with Go by 43224gg252 on Sunday July 23, 2017 @08:12AM (#14831903)
>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 experience with elixir, but that's because I like to stay employed.

>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

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 critically about what should be done when that error is encountered. "Central error checkers" are almost never robust enough for mission critical systems.

Go basically forces people to write high-quality, resilient code bases, and I like it for that.

Re:Why I’m Frustrated with Go by barrkel on Sunday July 23, 2017 @08:52AM (#14832029)
> This is almost always unacceptable in production,

This is not true for almost all software outside of embedded domains. In fact responding to an error near where the error occurred is almost always a mistake. The rare exceptions to this are when "error" is unavoidable due to concurrency (e.g. I/O), and even then many errors shouldn't be handled (misconfiguration, incomplete system initialization, etc.) or should be wrapped and transformed for human consumption (e.g. user tried to access a resource that couldn't be found - we still bubble up).

> you need to catch all the errors and think critically about what should be done when that error is encountered.

If you support this position, you'd support checked exceptions like Java - something that's widely considered a mistake.

There's lots of reasons why it's a mistake. A more important reason has to do with dynamic construction of control flow. If you use any monad design patterns in the construction of your application (easy to do because the monad design pattern is so powerful), you quickly create boundaries that errors need to cross unmolested because they're generic and cannot possibly encode policy. The same criticisms follow through into dependency injection and other forms of modular decomposition that use dynamic recomposition. Java style has you doing utterly pointless things, like wrapping all the implementation errors in a generic module-level error - obscuring the very thing that might theoretically let user code react to the error state!

More philosophically, abstractions fail in implementation-dependent ways. When you encode policy about failure outside the abstraction boundary, you're encoding implementation-dependent behaviour; but you can't put the policy inside the abstraction boundary either, because then the abstraction isn't reusable - different applications have different policies. Error handling is inherently opposed to abstraction. That's why microscopic error-handling close to the cause of the error only flies in small closed systems, like kernels, databases, embedded.

Re:Why I’m Frustrated with Go by masklinn on Sunday July 23, 2017 @09:34AM (#14832188)
> If you support this position, you'd support checked exceptions like Java - something that's widely considered a mistake.

The primary problem of checked exceptions in java is not that they exist, it's that they are very badly integrated with the rest of the language e.g. it's impossible to be generic or transparent over checked exceptions, their hierarchy is messy and it's often unclear why specific exceptions are checked and others unchecked. Haskell's error handling (reified through Either error values) has similar effective semantics but nowhere near the dislike because it's well integrated in the language and you can be generic over the error, the value, and the result itself.

Re:Why I’m Frustrated with Go by barrkel on Sunday July 23, 2017 @10:59AM (#14832540)
Haskell doesn't encourage runtime polymorphic module boundaries. That's the key difference with Java, not hierarchies. Abstractions invoked through runtime polymorphic interfaces compose poorly with statically typed exception specifications.

Generic composition that lets error types flow through abstractions also lets implementation details flow through, so it is an architectural choice, make no mistake. You don't dodge the tradeoff between abstraction and error handling.

Re:Why I’m Frustrated with Go by latch on Sunday July 23, 2017 @08:42AM (#14831990)
I definitely agree with you that Go codebases has a high level of consistency. It's certainly one of the many good things Go offers and something I hope other languages look at to see if they can replicate.

But, that doesn't really have anything to do with it being a chore. We can just agree to disagree on that.

However, I think you misunderstood my point about errors (or maybe you're just working with very different types of systems). Empirically, looking at Java codebases, the C# team found that most errors weren't "handled" beyond an outer exception handler. Anecdotally, this has been my experience as well. I admit that this is a very 'web' point of view, where requests are isolated and most exceptional situations are best handled with logging + showing the user a friendly error message.

At this point, they should adopt the Elixir approach and consistently provide a ! alternative across the stdlib (Must* is inconsistently available and verbose). They thought Go would be used by C++ programmers, instead it's being used by Ruby programmers (1). The language paradigm doesn't fit how people are using it as well as it could.

I'm not sure what other languages you've been exposed to, but your last line is hard for me to believe. If you look at other languages, you'll find a lot of techniques aimed at quality and resilience that are nowhere in Go. Again, that doesn't make Go bad, but "resilient" ? Go has mutable, shared memory, nils, no thread isolation, no generics (so runtime casting), no pattern matching and so on. Even the error system which you like is reckless (??) compared to what you'll find in languages like Rust and Haskell (Result and Maybe).

(1) https://commandcenter.blogspot.com/2012/06/less-is-exponenti...

Re:Why I’m Frustrated with Go by thinbeige on Sunday July 23, 2017 @08:29AM (#14831951)
> I don't have much experience with elixir, but that's because I like to stay employed.

While the previous commenter gave an objective and rational overview why he think Go gives him a hard time you can't resist to get polemic.

Re:Why I’m Frustrated with Go by 43224gg252 on Sunday July 23, 2017 @08:33AM (#14831971)
I gave rational counter arguments and employment is pretty important too imo. It seems a lot of the anti-Go people tend to favor languages that no one gets paid to use.
Re:Why I’m Frustrated with Go by nine_k on Sunday July 23, 2017 @10:18AM (#14832351)
You should stick with Cobol. It paid the developers for 60 years, and has a very fair chance to continue commanding reasonably good salaries for another 20 or 30.

Maintaining Cobol code is a chore, though, partly for the same reasons as Go code.

Re:Why I’m Frustrated with Go by thinbeige on Sunday July 23, 2017 @08:50AM (#14832014)
Yes, but the discussion wasn't about the employment situation and if--your tone was slightly inappropriate. You could have also written: "I've no experience with Elixir but your words catch my interest. The inferior Elixir enployment situation (compared to Go) held me back from Elixir. But I should give it a try."

Same message and nobody loses his face.

Re:Why I’m Frustrated with Go by actsasbuffoon on Sunday July 23, 2017 @08:53AM (#14832035)
I'm getting paid to write Elixir right now.
Re:Why I’m Frustrated with Go by di4na on Sunday July 23, 2017 @11:00AM (#14832545)
Paid for Elixir full time, and there is definitely a market :)
Re:Why I’m Frustrated with Go by freeone3000 on Sunday July 23, 2017 @09:41AM (#14832210)
You have the ability to choose Go - you could as easily have chosen Elixir.
Re:Why I’m Frustrated with Go by jorgec on Sunday July 23, 2017 @09:32AM (#14832182)
In reality, Go is a language that practically no one gets paid to use. Go is niche and the few projects around here are short term.
Re:Why I’m Frustrated with Go by zimpenfish on Tuesday July 25, 2017 @08:13AM (#14847111)
I interviewed for two Go jobs in London last month that were specifically building up Go teams for long term projects. It's definitely getting less niche by the month.
Re:Why I’m Frustrated with Go by coldtea on Sunday July 23, 2017 @12:44PM (#14833118)
>I don't have much experience with elixir, but that's because I like to stay employed.

Yeah, because Go is the epitome of employability...

>"Central error checkers" are almost never robust enough for mission critical systems.

Go is not used in mission critical (embedded, medical, aviation, communications, etc) systems anyway.

Besides the notion is wrong: mission critical systems DO centralize error checking. The code local to the error wouldn't have enough context (and shouldn't have the reach) to call the right procedures for cleaning up and moving on.

Re:Why I’m Frustrated with Go by vbezhenar on Sunday July 23, 2017 @10:55AM (#14832521)
I tried Go and so far I'm feeling that Go forces me to abandon error checking and even if error is catched, I have no idea where this error comes from, because there's no stacktrace or anything like that. Best thing I've come to is using strings as errors (completely throwing out any error hierarchy) and returning new error string for every call with call information (doing poor job which Java would do for me automatically).
Re:Why I’m Frustrated with Go by Thetawaves on Sunday July 23, 2017 @03:42PM (#14833998)
This is not the right way to do things.
Re:Why I’m Frustrated with Go by dullgiulio on Sunday July 23, 2017 @08:46AM (#14831999)
>> 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 critically about what should be done when that error is encountered.

Absolutely. My approach is usually that errors are always wrapped not just returned. The wrapping itself ends up looking almost like code documentation: "could not do X: <previous error>", "error while doing X: <previous error>". Every error string is then unique in the program, easy to grep.

"Could not perform the operation", maybe together with a 500 lines stacktrace in your logs (which are maybe line-by-line bacause that's the default)... you are up to a nice middle of the night debugging session :)

Re:Why I’m Frustrated with Go by rufugee on Sunday July 23, 2017 @11:12AM (#14832594)
The problem I've found it that you might wrap errors this way, but the libraries you use don't, or approach it differently. So you're either chasing down strings that may or may not be grep'able or you're fighting with delve to track down what's happening. The whole error situation with Go is one of the main drawbacks of the language imho.
Re:Why I’m Frustrated with Go by jorgec on Sunday July 23, 2017 @09:35AM (#14832190)
When you wrap the error then you are kicking it out. Sooner or later you must catch the error. So, in most case, its just delaying the inevitable.
Re:Why I’m Frustrated with Go by dvirsky on Sunday July 23, 2017 @09:06AM (#14832090)
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.