Earlier quoted context omitted.
Sure, the syntax is unique, but it's fairly easy to get over that. I guess I'm comparing to Rust, where not only is syntax different, but data structures like a tree with parent references aren't as straightforward (nor idiomatic), and there's a lot more explicit methods that requires knowing which are important and which are just noise (e.g. unwrap, as_ref). I would argue that after a short tutorial on basic syntax,…
to me Rust syntax is less alienating, they adapted ML syntax which is probably second most popular(scala, typescript, kotlin) after C style syntax, while Go from whatever reasons got something totally new.
Why Go Can't Try
61–70 of 74 posts
Re: Why Go Can't Try
#62Earlier quoted context omitted.
to me Rust syntax is less alienating, they adapted ML syntax which is probably second most popular(scala, typescript, kotlin) after C style syntax, while Go from whatever reasons got something totally new.
Which aspects of Rust syntax are adapted from ML? Semantics sure, but to me the syntax seems a lot more similar to C++ (e.g. semicolons, type parameters using , etc.)
Re: Why Go Can't Try
#63Earlier quoted context omitted.
When you see .unwrap in Rust code, you know it smells bad. When you see x, _ := in Go code, you know it smells bad. > But if you don't know Go, it's just an underscore. And if you don't know rust, .unwrap is just a getter method.
> When you see x, _ := in Go code, you know it smells bad. What if it’s a function that returns the coordinates of a vector and you don’t care about the y coordinate?
x, _ :=
With the topic of .unwrap() _ is referencing an ignored error. Better laid out as: func ParseStringToBase10i32AndIDoNotCare(s string) {
i, _ := strconv.ParseInt(s, 10, 32)
return i
}
Un-handled errors in Go keeps the application going were rust crashes .unwrap().Ignoring an output data value or set is just fine. Don't always need the key and value of a map. Nor a y axes in vector math.
Re: Why Go Can't Try
#64Re: Why Go Can't Try
#65Earlier quoted context omitted.
How so? In Rust you also need an allocator to allocate anything. Zig's diagnostics idiom is just that, an idiom. It would be very weird to do this in Rust, but then it's a pretty weird choice in Zig, they've just decided to do it anyway.
What I meant by "you need an allocator" is "you need to explicitly pass the allocator of your choice to the function" [if you want to attach some data to the error]. In rust you can simply return anything as error, not only an enum variant.
Re: Why Go Can't Try
#66Earlier quoted context omitted.
The problem with the zero value business is that it also makes adding these QoL things in libraries difficult or outright impossible. Case in point, I tried building a library for refinement types, so you can have a newtype like, type AccountName string except you write it like (abridged) type AccountName refined.Scalar[AccountName, string] func (AccountName) IsValid(value string) bool { return accountNameRegexp.Matc…
You're missing the point, Go does not want these QoL features. Arguing about why they are hard to add is pointless because, philosophically, they are undesirable and not going to be accepted.
The old guard is slowly stepping away, for good or ill. QoL changes are not off the table, but they do have to fit into the language.
Re: Why Go Can't Try
#67"Here's the uncomfortable truth: a try keyword in Go without fixing the error type is just syntax sugar. You'd get slightly less typing but none of the real benefits - no exhaustiveness checking, no compiler-inferred error sets, no guarantee that you've actually handled every case." ... So what? From what I can tell that's all anyone has asked for in the context of something to just return nil/error up the call stack…
Exactly. I don't like that many people say "It's not perfect so it's useless.". I don't want to write or read the `if err != nil` statement over and over again. It is messy. It is tiresome. It could be solved by syntactic sugar.
A little syntax sugar that won't break backwards compatibly and makes the intent of the code clearer is a win-win. I've never seen a really reasonable response from the Go team on why they don't want to do it.
Re: Why Go Can't Try
#68The programmer is explicitly throwing away the error returned by ReadFile (using the underscore) in the criticism of Go. data, _ := os.ReadFile(path) Saying that is not explicit is just wrong.
file.Close()
Did you see the non handled error here? The compiler doesn’t care.Re: Why Go Can't Try
#69These AI written articles carry all the features and appearance of a well reasoned, logical article. But if you actually pause to think through what they're saying the conclusions make no sense. In this case no, it's not the case that go can't add a "try" keyword because its errors are unstructured and contain arbitrary strings. That's how Python works already. Go hasn't added try because they want to force errors to…