[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Coroutines and Go
- From: Tony Finch <dot@...>
- Date: Thu, 12 Nov 2009 12:48:37 +0000
On Thu, 12 Nov 2009, Stephen Kellett wrote:
> They seem proud of not having enumerations. I'd have thought the dreadful
> mistake of omitting them from Java (which has now added them back into the
> language) had been learned by now. "iota" seems to be a passing nod to the
> concept of monotonically increasing values (which is how most enums, but not
> all, work). But integers are not a typesafe substitute for enums. Perhaps I've
> missed something about Go and enumerations (I was tired when reading about it)
> but I think that is something that needs addressing. If I've got that wrong,
> someone please correct me.
You can declare the type of a (set of) constant(s) making it safe since
there's no implicit conversion (even if the type is just an alias). See
for example the ByteSize enum defined at
f.anthony.n.finch <email@example.com> http://dotat.at/
GERMAN BIGHT HUMBER: SOUTHWEST 5 TO 7. MODERATE OR ROUGH. SQUALLY SHOWERS.
MODERATE OR GOOD.