-
Originally opened by @extemporalgenome in cuelang/cue#686 Reading through the tutorial and the spec, I see both Furthermore, it appears that definitions and aliases can all be spelled starting with either uppercase or lowercase letters. Under which circumstances should one letter-casing be preferred over another? I'm happy to submit a docs PR with whatever I learn here. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Original reply by @mpvl in cuelang/cue#686 (comment) This is a relatively new thing and the documentation needs to be updates. For details see https://cuelang.org/docs/references/spec/#definitions-and-hidden-fields But in short, exported definitions (those starting with There is one case where this is important though. Consider
Adding a definition to a struct is currently allowed in CUE, even if
Hidden fields, including definitions, always live in a different namespace per package (much like Go unexpected fields) and thus are safe to add. |
Beta Was this translation helpful? Give feedback.
-
Original reply by @mpvl in cuelang/cue#686 (comment) As for casing, the original CUE spec used casing for determine whether to export something or not, similar to Go. However, although this works well with Go, it doesn't work well for CUE as it may be used in conjunction with data with arbitrary casing. The convention is to use camel case for JSON, but in reality it is all over the place. So we introduced the use of As for a recommendation, normally I would say using |
Beta Was this translation helpful? Give feedback.
Original reply by @mpvl in cuelang/cue#686 (comment)
This is a relatively new thing and the documentation needs to be updates. For details see https://cuelang.org/docs/references/spec/#definitions-and-hidden-fields
But in short, exported definitions (those starting with
#
) are visible outside your package, whereas hidden ones are not. If you don't intend to share a package, then it doesn't matter much.There is one case where this is important though. Consider
Adding a definition to a struct is currently allowed in CUE, even if
foo.#Def
doesn't define it. This will be disallowed inv0.4.0
. See #543 for more de…