On Friday, August 14, 2020 at 2:52:20 PM UTC-4 Joe Marty wrote:
>
>> If I know that a value exists, or am fine using the zero value (again,
>> that's the majority of my personal use-cases for maps at least), having to
>> use a statement just to discard the extra bool is annoying.
>>
>
> Rig
On Fri, Aug 14, 2020 at 8:52 PM Joe Marty
wrote:
>
>> If I know that a value exists, or am fine using the zero value (again,
>> that's the majority of my personal use-cases for maps at least), having to
>> use a statement just to discard the extra bool is annoying.
>>
>
> Right, so this brings me
>
>
> If I know that a value exists, or am fine using the zero value (again,
> that's the majority of my personal use-cases for maps at least), having to
> use a statement just to discard the extra bool is annoying.
>
Right, so this brings me back to a nice solution to both our use cases,
wh
On Fri, Aug 14, 2020 at 6:17 PM Joe Marty
wrote:
> Yeah, I can see how the convention of "always testing for failure" is
> better than a panic, in that it requires you to handle the possibility of a
> failure for things that may commonly fail. In that respect though, I don't
> understand why the
Thanks for the insights!
Yeah, I can see how the convention of "always testing for failure" is
better than a panic, in that it requires you to handle the possibility of a
failure for things that may commonly fail. In that respect though, I don't
understand why the "comma OK" is optional. Elm,
Joe, your question is perfectly answered by Axel.
I'll just share a few (personal) Go "style" comments:
Go likes you to test explicitly for failure where that is possible: did the
open fail, did the pipe break, etc.Multiple return values make this clear
by avoiding the need for a "reserved" error
No, there isn't, but you can check if the value exists:
x, ok := m[k]
if !ok {
panic("does not exist")
}
You can also wrap that with methods, if you want to avoid the extra check.
I disagree with you that panicking on a non-existent key is better - either
in general, or in the majority of ca
I'm very new to Go - apologies in advance if I'm missing something:
I find it frustrating that there's no way to create a map that does *not*
automatically return a zero value for undefined key access by default.
I love the fact that Go doesn't return "nil" for this use case (I love
Ruby, but I