Comments (3)
This is unique to C++; it works fine in every other language.
This isn't a C++ problem - as we talk about in the Buf docs, the issue will lead to protoc not compiling definitions (regardless of whether it was meant to only protect against C++ issues). Your example above won't compile:
$ protoc -o /dev/null foo.proto
foo.proto:9:3: "UNSPECIFIED" is already defined in "foo".
foo.proto:9:3: Note that enum values use C++ scoping rules, meaning that enum values are siblings of their type, not children of it. Therefore, "UNSPECIFIED" must be unique within "foo", not just within "Bar".
We also find that nesting enums leads to issues with forwards compatibility that while not actually breaking compatibility, breaks the spirit, namely that developers typically think an enum only truly applies to their specific message, only later realizing it is a more global concept. This leads to references in other messages for nested enums, which is worse than standardizing on a prefix.
The Google Style Guide also uses it for their example https://developers.google.com/protocol-buffers/docs/style
We'll stick with this recommendation - we find that many people have opinions on Protobuf style, but the one that leads to the least amount of issues down the road, even if more verbose, is usually preferred, especially to help developers of all levels of familiarity with Protobuf.
from buf.
That sounds reasonable. :-)
from buf.
@bufdev your comment about nesting is valuable and worth referencing, because the prefix lint rule is the most hated on our team :D Would it make sense to add to https://buf.build/docs/best-practices/style-guide#enums?
from buf.
Related Issues (20)
- Adding "files to be ignored" option for buf format to buf.yaml HOT 2
- PROTOVALIDATE cannot be selected inside lint use HOT 1
- buf formatter dropping type when prefixed with url
- Field Deps Not Found in Type bufgen.ExternalConfigV1 HOT 2
- protoc_path only accepts string, not array like other plugin paths HOT 1
- Generated buf generate dart code not having the comments HOT 1
- Buf unable to build image when dependencies use conflicting extension numbers HOT 2
- Buf can't derive the format and compression with `.tar.zst` and `.tar.gz` extensions HOT 2
- could not read buf configuration file at /Users/admin/.config/buf/config.yaml: permission denied HOT 2
- [Feature] Official rust plugins HOT 1
- About using third-party dependencies locally
- csharp plugin fails in managed mode with same filename in different versions HOT 1
- Specifying Folders In `buf generate --path` Arguments Causes Massive Performance Hit HOT 3
- Feature request: Option on buf convert to set `DiscardUnknown` to false when unmarshalling input
- Question: Already defined dependency makes `buf generate` failed
- [feat] Option to generate enum with full prefix HOT 2
- mod update panics when dependencies are from multiple registries HOT 1
- Failure: 403 Forbidden HOT 4
- `buf generate` does not use correct `buf.lock` when using `--config` with `git` source HOT 2
- Generate implicit dependencies HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from buf.