Topics

Using Java Strings As Enums In Go

Drasko DRASKOVIC <drasko@...>
 

Hi all,
we have opened a discussion here:
https://github.com/drasko/edgex-export/issues/19 around the fact that
strings are used as enumed flags in Java, while Go does not really
have enums of this type. More info can be found here:
https://splice.com/blog/iota-elegant-constants-golang/


Here: https://github.com/edgexfoundry/export-domain/blob/master/src/main/java/org/edgexfoundry/domain/export/ExportCompression.java
for example you can see one of this enums in Java, or here also:
https://github.com/edgexfoundry/export-domain/blob/master/src/main/java/org/edgexfoundry/domain/export/ExportFormat.java.
And here is the proposed equivalent representation in Go:
https://github.com/drasko/edgex-export/blob/master/registration.go

My question is: do we really need this string values for the enum vars
like we use in Java, or maybe Java can switch to int types for these
flags and then be aligned with Go? I.e. why for a type of compression
we have to use string "NONE" or "GZIP" or similar, when instead we can
use just type codes - for example NONE = 0, GZIP = 1 - and then we
will know how to distinguish them (I have explained this in my
comments on PR here:
https://github.com/drasko/edgex-export/issues/19).

What do you think that it is the best way to handle this case?

Best regards,
Drasko DRASKOVIC
Mainflux Author and Technical Advisor

www.mainflux.com | Industrial IoT Cloud
-------------------------------------------------------------------
Engineering Division | Paris, France

LinkedIn: https://www.linkedin.com/in/draskodraskovic
Twitter: @draskodraskovic