9

There is a Style Guide for Protocol Buffers. But it does not clearly say how a .proto file should be named.

MyProtos.proto, my_protos.proto or my-protos.proto, which is the better name?

2 Answers 2

10
+50

I don't believe there's an appropriate answer to how any file "should be named" other than aim for consistency and clarity.

Consistency would mean following the file-naming conventions your project already has for sources and headers. If your sources are named using camel-case, do the same for the proto files. The most common choice seems to me to be the my_protos.proto version.

Clarity to me means that the file name should give some clue as to the contents. I generally favour naming files after the class which they implement, and usually have a separate file (pair) per class. I would recommend the same for the proto files. I prefer several small proto files each defining a single Message or very closely related Messages over a single huge proto file defining all your Messages in the one place.

3
  • 6
    Please note that there is kind of a restriction in Java. If you have a proto file named Person.proto, you can't declare a message named Person (with capital P). This is because the generated code creates a wrapper class with the name of the proto file: Person, and the declared message name creates a nested class with the same name (in this case).
    – noti
    May 20, 2014 at 13:59
  • 2
    @noti this does not seem to be the case any longer. Just tried this and the outer class is named PersonOuterClass. Not exactly sure when it was changed. May 22, 2018 at 18:00
  • Some of us might find it convenient to agree with 'I don't believe there's an appropriate answer to how any file "should be named" other than aim for consistency and clarity.' However, such a statement, even if true in general (which it is not), may not be the whole story w.r.t protobuf files. For tools like protobuf (that generate files for many different languages), the practical questions matter; e.g. "how are filenames generated in different languages?" and "How can we name files to avoid pain points?" For example, I've seen confusing behavior in tools around underscores and hyphens.
    – David J.
    Dec 15, 2018 at 22:31
9

Since the question is almost 8 year old, for those who people looking at this in 2020 s, now there is a style guide published by google.

Excerpt for file naming

Files should be named lower_snake_case.proto

https://developers.google.com/protocol-buffers/docs/style

Not the answer you're looking for? Browse other questions tagged or ask your own question.