Replies: 2 comments 4 replies
-
Original reply by @mpvl in cuelang/cue#972 (comment) There isn't a single style yet. Part of the reason is that the style used may be forced by the underlying API that CUE intends to mode. Camel case (camelCase) seems to be most common style in use for JSON. But often this is not the case. Originally (before It may seem that there is more control over casing of definitions, but even that is often not the case. In some mappings, e.g. JSON Schema -> CUE, the source is mapped to definitions. This means that definitions are often camelCase as well. Of course, we could have a recommended style and then optionally do imports converting any given style to this style. But that can be cumbersome. There is also a matter of naming for aliases. There I think the more common style is to use PascalCase or even ALL CAPS.
In very early CUE we used capitalization as an export toggle. That turned out to be just too cumbersome because of the lack of standardization around JSON. Because of the clarity of this mechanism, we did adopt a leading character approach in the form of That said, if it were up to me, I would adopt a style a long the following lines:
The only ambiguity reading these is between regular fields and aliases though. So I would recommend adopting the opposed first-letter case for aliases of whatever is the style for the first letter of a regular field. |
Beta Was this translation helpful? Give feedback.
-
Given that CUE is intended to work with any stack, wouldn't it be better to stay agnostic of code style conventions and just have a configurable linter? |
Beta Was this translation helpful? Give feedback.
-
Originally opened by @seh in cuelang/cue#972
I am once again interested in advice for CUE style. In particular, how do we write identifiers?
Here are some examples I’ve seen:
#BigThing
).thingPart
).thing_part
).Of course, it's possible to avoid some of these decisions if all of your identifiers are made up of only one word.
JSON offers some precedent, using either snake case or lowercase-prefixed camel case for object field names. Prevailing YAML style seems to favor camel case. The prevailing Go style is camel case, forcibly using capitalization to indicate whether identifier is exported or not. In CUE, by contrast, we now have the leading underscore character rather than that capitalization toggle.
I looked at the unity project's corpus, and found mixtures of these styles even within a given project. Has anyone settled on a style they can recommend?
Beta Was this translation helpful? Give feedback.
All reactions