I like enums and the more i use them, the less i miss classic inheritance. But i dont want to end up with giantic case statements.
In my mind, nim would be able to turn:
type MyEnum = enum meA, meB, meC
proc doStuff(me: MyEnum.meA, i: int) = discard #Or me: meA
proc doStuff(me: MyEnum.meB, i: int) = discard #Or me: meB
into this:
proc doStuff_meA(me: MyEnum, i: int) = discard
proc doStuff_meB(me: MyEnum, i: int) = discard
proc doStuff(me: MyEnum, i: int) =
case me:
of meA: doStuff_meA(me, i)
of meB: doStuff_meB(me, i)
else: discard
Araq says: but it is only a macro away! Yeah, but it would require me to declare every proc inside the same macro block, which is my main complaint when using enums
Why not go all the way:
proc doStuff(me: MyEnum, i: int) if me == meA = discard
proc doStuff(me: MyEnum, i: int) if me == meA or i < 5 = discard
This has its problems of course, because more than one declaration can apply ;)