3 ms·
> given Go's lack of exceptions, such a feature would be entirely impossible. Haskell is a nice programming language, but ultimately if a program written in la
by jrockway 7y ago
> given Go's lack of exceptions, such a feature would be entirely impossible.
Haskell is a nice programming language, but ultimately if a program written in language A can run on your computer, a program can be written in language B that can run on your computer and do the same things.
If you think "return foo, err" is a lot different than return "Left foo" or "Right err", then you might want to think more about how you think about computer programs.
- whateveracct 7y agoIf you think those two things are the same, you're just in the wrong. This isn't an opinion thing - I can easily prove that the Haskell way is strictly more precise than the Go way! Not all Turing complete languages are the same. Curry-Howard shows that. Haskell's type system subsumes Go's and allows you to express richer propositions about program behavior.
- deleted 7y ago[deleted]
- _bxg1 7y agoPedantry is unhelpful. Technically this project could be written in assembly. Have fun doing that.
- macintux 7y agoThe point isn’t that the software couldn’t be written in Go; it’s that the language feature that makes that particular problem easier to deal with doesn’t exist. You could write this tool in Go, but it would have an entirely different flow.
- dllthomas 7y agoIf you think x * y is a lot different than x + y, then you might want to think more about how you think about algebraic expressions, yeah?
- harry8 7y agoimplement x * y with no * using only + ans = 0; for(i = 0; i !=y; ++i) { ans += x; } Turing completeness is a thing. For a particular data transformation language A might be easier to write than language B. Language C easier to read. Language D easier to maintain, Language E less chance of a latent bug. And language F might be brainf&^k. As soon as you think about it as a data transformation and note you can write an interpreter an any language A,B,C,D,E... to execute any other of those languages source code it becomes obvious.
- dllthomas 7y agoTuring Completeness is an important and interesting thing. It doesn't have very much to do with fitness-for-purpose of a programming language. Of course you can write * using +. That doesn't mean using one mightn't be significantly more appropriate to the problem at hand, or that returning error codes in a product type isn't the wrong call.
- harry8 7y agoThis is a discussion of the phrase "such a feature would be entirely impossible" You're now explaining to me in response to my previous post that some languages are a better fit in certain dimensions to perform a data transform? I think this is a discussion that needs to end now.
- dllthomas 7y agoI'd been addressing the snarky finishing line. The feature that was called "entirely impossible" was resumable exceptions. The difficulties are practical not theoretical, but it's not the difference between (r, err) and (Either r err).
- harry8 7y agoNeeded to stop but didn't for which clearly it is all my fault because someone is wrong on the internet!! Being snarky about features being only possible in $language is one of the few entirely appropriate uses of snark and you don't object to snark per se, do you? Which feature of this discussed data transform is called "template meta-programming?" Excuse me, my bad, is called "resumable exceptions?" Or are resumable exceptions a language feature/idiom used with a particular choice of language to perform a data transform? Really. "The feature of using C++ is impossible with a different language selection." Come. On. It must rankle. It must. Maybe this isn't just yet another "any criticism of a language boosterism piece must be met with fire and fury because I've invested time and want career payoff." Yeah maybe there's something else going on here but I genuinely can't see it. And it's a pattern also visible with rust boosterism articles (and I like rust too!) and clojure (again, it has some merit!) and even Haskell. Yeah, Haskell is fun! (No! Silence the Heretic. The emperor's threads are fine indeed! "Let me repeat what you just said but with me explaining it to you to show how stupid you really are." Yeah well I know I'm pretty stupid, often, but not so stupid as all that, yeah?)
- saurik 7y agoLeft foo and Right err alone do not act like exceptions: you need more baggage for that, which Haskell supports and encourages. When you define this in terms of a monad--not just a data type that has the same features, but part of a reusable category of types--you can provide special syntax for it, which Haskell does: if you have a language claim to have "monadic exceptions" without having a type class for monad and some reasonable support for working with monads, you should frankly question whether the people who designed the language understood what monads were in the first place. In Haskell, you can define operators on Either which allow you to use the generic do notation to achieve something with the feel of exceptions but with fully programmatic behavior: languages like Go and even Rust seem to want the downsides without gaining the benefits, which is just depressing.
- bjt 7y ago"return foo, err" can return 4 kinds of responses: - foo, nil - nil, error - nil, nil - foo, error What's the right behavior when the function returns both a result and an error? What's the right behavior when it returns two nils? At best, you make everybody agree to language conventions to prevent that from happening. In Haskell (or even Swift and Kotlin with their optional types) the compiler guarantees those cases cannot happen. In Go, you just hope they never happen because almost no code handles them. I code in Go every day. But I can't defend its decision here. I'd much rather have a richer type system where the compiler can guarantee that I'll get an error or a result, but not both or neither.
- jrockway 7y agoI think you just treat an error being returned as the value being ignored, which is what 99.9% of go programs do. As for two nils being returned, I think it's reasonable for a program to run successfully without returning a result. Search for some work to do, return a list of tasks -- if there are none, the list is empty (nil) but there was no problem checking, so there is also no error. I don't see a problem. As for the compiler checking, try running "func f() (value, error)" like "foo := f()". It blows up. What you do with the error is up to you; all Haskell adds with the Error monad is that it short-circuits to the end of the do {} block with the error value. No different than a Java exception; all of the upsides, all of the downsides. Regardless, I stand by my original point that if you want to handle runtime errors, Haskell doesn't really add anything over any other language. Semantic has cases that handle errors. So would the program written in any other language. The author should have just said, "I wrote it in Haskell because I felt like it" instead of making up reasons that simply aren't true.