by zarzavat · 2y ago · 0 comments
The problem with using strings is that nothing else uses strings (like say, your database), so you have to have this interminable roundtrip conversion between strings and integers.
JS programmers are in a bit of a bubble where using strings as enums is socially acceptable, if a C programmer saw this code
typedef struct {
const char* type;
} Animal;
they would yell at you.If a database engineer saw this schema:
CREATE TABLE animal (
id INTEGER PRIMARY KEY,
type TEXT
)
they would yell at you.It's way nicer to use integer enums from A to Z, because everything else has enums and people use them.
If you use plain integers instead of integer enums then the compiler has no visibility into what your tags are. So your diagnostics will be hard to read because the compiler doesn't know that 69 is AnimalType.frog
Pointing to a lower level language with a different use case doesn't justify int enums to me.