6 ms·
Very little people who have tried errors by value or Either monads (they are basically the same concept in some sense) think that exceptions are better. Excepti
by cube2222 10y ago
Very little people who have tried errors by value or Either monads (they are basically the same concept in some sense) think that exceptions are better. Exceptions cause your code to be non-linear. Also, it makes them seem like something exceptional (pun intended), whereas you should really carefully handle each error and decide what it implies.
Also, just something I noticed after almost two years of Go. Thanks to library quality I usually end up writing much less Go than Java/Scala for similar applications.
- kuschku 10y agoGo does not have Either monads, or real errors by value. It has a multi-assignment syntax similar to tuple return, but nothing else. For Java, with a tiny library, you can have real Either monads: https://github.com/spencerwi/Either.java https://github.com/spencerwi/Either.java I use them in lots of code. For Go, you end up with an assignment syntax where you have to manually check, and get no compiler safety. At all.
- cube2222 10y agoYou do have errors by value. You return for example two values, the response and error. What do you mean with no compiler safety exactly?
- kuschku 10y agoI mean that the compiler does not check if I’m handling the error. I can easily just ignore the error and work with the value, and therefore have code that breaks if the value might not be there. Any code that compiles should not be able to ever segfault or have NullPointerExceptions or similar.
- cube2222 10y agoWell, I never had segfaults. Anyways, it's true, I miss pattern matching on errors. However, in practice, you just get used to it. I haven't had a situation in the past half year where I'd forget to handle the error / check it.
- kuschku 10y ago> However, in practice, you just get used to it. I haven't had a situation in the past half year where I'd forget to handle the error / check it. But with the same argument, you could as well use PHP7. And this still doesn’t allow you to replace all stdlib datatypes with your own implementations without using custom precompilers.
- cube2222 10y agoExcuse me, what do you mean by 'replace all stdlib datatypes with your own implementations'. Why would I do that?
- kuschku 10y agoTo interface via an FFI with a game engine, which uses a custom allocator, and you need to pass datatypes between it and your own code? (As I’ve done in Java!) To replace existing implementations with your own, because you want a LinkedArrayList (a linked list of blocks)? Or because you want a TreeMap instead of a HashMap, or a Set with different implementation? Because you want to implement your own Either type to better handle return values (see https://github.com/spencerwi/Either.java https://github.com/spencerwi/Either.java )?
- cube2222 10y agoThis is an interesting point actually. Because it gets raised every time and I actually thought the same before starting with Go. Thing is, in practice you usually don't need special generic containers. And when I actually need it, I'll just code up a non-generic implementation. When I need a complex type system I'll use Scala.
- kuschku 10y agoWell, I use them a lot – I’ve written lots and lots of generic code in my projects, and reuse it across many dozens of projects. This allows me to have fully reactive collections in Java, lazy reactive collections, and more. I can just connect to a socket transmitting updates with netty, write a transformer, apply those to a lazy reactive collection, and have the changes directly appear in the list in the UI, fully threadsafe. Writing those things again, and again, every time, would be far more work, and increase the time I need to write code massively. I’ve actually used go a bit, and tried reimplementing several of my projects in go, but either it wasn’t easily possible, or I had to translate dozens of generic classes into hundreds of non-generic versions, with lots of duplicated code. And then I had found a bug, fixed it at one point, and had to copy it to hundreds of files.
- bborud 10y agoI think Go has made a lot of people re-think their assumptions about what makes a language a good language. I have yet to figure out precisely what it is that makes me more productive in Go (which I have relatively little experience with) than Java (which I've programmed since the first beta).
- cube2222 10y agoMake sure to write some blog post about it when you do! I'd be very curious to hear what it is.
- bborud 10y agoAt least one thing I can say right away is that they have taken care of a lot of small hygiene factors. Things like the rapid compiler, the "go" command that has a lot of nice things built in, the way they did away with formatting discussions (although I can't articulate how it differs from other languages that try to do the same....probably the tooling). The Go community also prefers libraries over frameworks. Coming from Java, and its humongous, cancerous framworks, that's a BIG selling point. I notice that when someone posts a link to a "Go framework" I get slightly ticked off and I feel resistance even before I've clicked the link. As for the language: I don't know yet. It just works for me. :)