Support lowercase in enum values please

112 views
Skip to first unread message

Danny Pike

unread,
Aug 7, 2019, 2:48:33 AM8/7/19
to Protocol Buffers
I realise that the style guide for Protocol Buffers requires that enum values be in UPPER_CASE but I am finding that this is increasingly conflicting with more modern styles such as C#, C++11, TypeScript and maybe others that I am less familiar with.

So I find myself increasingly having to add shims manually like this:

enum MyTypes {
   
None = ProtoBufTypes.PT_UNSPECIFIED,
   
Elephant = ProtoBufTypes.PT_ELEPHANT,
   
Banana = ProtoBufTypes.PT_BANANA,
   
Motor = ProtoBufTypes.PT_MOTOR,
   
Alfafa = ProtoBufTypes.PT_ALFAFA
}

in order to conform to the style guides for the rest of my (non-protobuf) code, which naturally introduces a code maintenance issue that I would rather avoid.

If you don't want to "modernise" the Google Style guide to allow CamelCase for enums, may I suggest that you add an option to protoc that tells it to use the enums exactly as I supply them and not to change the casing? Is there something inside protoc that will break if you don't use all-uppercase?

Adam Cozzette

unread,
Aug 7, 2019, 2:28:21 PM8/7/19
to Danny Pike, Protocol Buffers
We usually try hard to avoid introducing new options because of the maintenance burden they add, so unfortunately I don't think we will be able to add an option for this. However, it should be pretty easy to auto-generate these shims if you want to have them for your own codebase. If you run protoc with --descriptor_set_out=some_file, it will output a serialized FileDescriptorSet proto. You can then have a simple program parse the descriptors, iterate over any enums and output the enum shims.

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/77d35ce4-14de-48a7-85e9-21108c826949%40googlegroups.com.

Danny Pike

unread,
Aug 7, 2019, 3:16:29 PM8/7/19
to Protocol Buffers
Thank you for your reply and the suggested workaround, which is appreciated. However, I have the same concerns over a maintenance burden and writing a tool just to work around this particular problem with Protocol Buffers would introduce more hassle for me than it would solve.

I would give you some advice of my own though (having been playing this game for several decades now). Please do consider seriously the cost of not adding this option (or something similar) to protoc. If you don't I fear that Protocol Buffers might be at risk of being consigned to the history books, along with a lot of other "good ideas at the time".

Requiring symbols to be all-uppercase is no longer a "good" coding style and it is not a good idea to believe that the rest of the world will stand still just because you want it to. :)

Reply all
Reply to author
Forward
0 new messages