strum icon indicating copy to clipboard operation
strum copied to clipboard

Use proper SCREAMING_SNAKE_CASE conversion for EnumCount

Open meithecatte opened this issue 5 years ago • 3 comments

If an enum is called FooBarBaz, EnumCount will name the constant FOOBARBAZ_COUNT. I believe FOO_BAR_BAZ_COUNT would be more expected. This can be achieved by heck, which is already a dependency of strum.

meithecatte avatar May 03 '19 09:05 meithecatte

Thanks for bringing this up! I have a few thoughts on the issue.

  1. This would be a breaking change, which in my mind means there's a higher threshold to reach than simply adding a new feature.
  2. I definitely agree that FOO_BAR_BAZ_COUNT is cleaner in your example. I'm not sure that is true in all cases though. If the enum was called My_eNum1a2B, it wouldn't be obvious to me what the snake_case version is, but I can easily figure out the uppercase version.

I'm going to tag this as "feedback wanted" because I think more opinions on the matter would be useful.

You can also create a new constant and export that name while still getting most of the benefits of using strum

pub const FOO_BAR_BAZ_COUNT: usize = FOOBARBAZ_COUNT;

Peternator7 avatar May 03 '19 20:05 Peternator7

  1. This would be a breaking change, which in my mind means there's a higher threshold to reach than simply adding a new feature.

I am aware that this would be a breaking change. However, strum could generate both styles of constants, and mark the "simple uppercase" ones as deprecated and doc(hidden), to facilitate a transition period.

  1. I definitely agree that FOO_BAR_BAZ_COUNT is cleaner in your example. I'm not sure that is true in all cases though. If the enum was called My_eNum1a2B, it wouldn't be obvious to me what the snake_case version is, but I can easily figure out the uppercase version.

If that's what you name your enums, you did this to yourself. If it's just the fact that you're using a non-standard naming convention, heck handles this well - in fact, you don't even need to know the original "case".

meithecatte avatar May 04 '19 18:05 meithecatte

I would also like to see this change implemented. Currently enums with a few words in their names get hard to read generated constants for their count. Users are already expecting breaking changes because of semver rules about libraries below version 1.0.

ArekPiekarz avatar Jul 14 '19 14:07 ArekPiekarz