On 14 March 2017 at 08:48, Eyal Posener <pose...@gmail.com> wrote:
> I was thinking about the type safety of uint in go, and comparing it for a
> similar problem.
>
> If I have this go code:
>
> var x uint
> x--
>
> The value of x is then the maximal value of uint, which is probably not what
> the gother wanted (I think, is there any particular use cases for that that
> you know of?)
>
> So my question is: why does go allow that, and for example panics on index
> out of range of an array? Doesn't it make sense that it also should panic in
> this case?
>
> Cheers,
> Eyal

It's because of this pitfall that int is generally preferred over uint,
even when you always expect values to be non-negative.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to