Am I using Enums correctly? If so, is there a performance difference compared to strings?

Also, I’m not against

This was added to avoid having to write:

color == Color::Red
# vs.
color.red? # much easier to read and write!

I understand other developers like this, and it is easier to write, but on the other hand, I feel there should be an equivalent way that works for the actual Enum value itself, not a lowercase variant.

If a lead developer does not agree with my views, just tell me. I will prefix CMD::, it’s fine.

I’ve created a repo for case when enum value checking compared to case when string checking.

Please help if anyone has time to increase the quality of this benchmark! So far, it seems like Enum value checking is faster, however, I’m not sure if .shuffle is distorting the benchmark.

Current results:

@asterite Well it was a RFC and I like it the way it is now partially because it’s compatible with my custom enums that do macro magic to replicate that behavior of Crystal enums plus allowing instance variables like Java’s: https://gist.github.com/Exilor/168d9a94196c3a2eb301a394a793a2bf

But if the community prefers #is? then #is? it is.

I started to convert all my code to use Enums, however, I stopped because of https://github.com/girng/CaseWhenEnumVsCaseWhenString/issues/1

I can’t create a proper benchmark to show the performance differences between checking the value of an enum, compared to checking the value of a string. So, I have no idea if switching to Enums is even worth it. Only thing I do know, is it decreases bandwidth usage.

Can someone please post a proper benchmark (if you have time)