Naming schema #1702
Replies: 3 comments 8 replies
-
On documents, we put in "alternatives considered" sections that describe what we thought about. In this case, please see https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/naming_conventions.md#alternatives-considered |
Beta Was this translation helpful? Give feedback.
-
The standard in many C-family languages has become It would be much lower cognitive load for the largest number of users to follow that standard (which matches the standard in Java, Kotlin, JavaScript, and TypeScript, at the very least). Worse, that distinction is actively harmful. Sometimes a named value that starts its life as a compile-time constant can become configurable or even changeable at runtime, and needing to rename that constant where it's used feels like an unneeded cost/spurious technical debt. I question whether distinguishing values by their naming makes sense at all; types, on the other hand, are fundamentally different than values or functions, even if you consider types to be first-class values. They are first-class values in TypeScript (and Java and Kotlin), after all, but it still feels right to treat them differently than constants or methods, even when the type can be called as a method (which is true with some types in JavaScript). You can tell the difference between a function and a value by simply looking at how its used; if you're looking at an auto-complete, every good IDE will have a symbol next to each member telling you whether it's a function or a value (read-only or otherwise) as well. Naming functions with A lot of the decisions in Carbon feel jarring, and as such would make me hesitant to adopt the language. Switching from operators like Yes, Carbon looks like it would be nicer in some ways than C++. But as a C++ expert who also uses TypeScript (and C# and Java), I look at these seemingly arbitrary choices that will make my life harder for no good reason and I wonder whether it would be worth it to save some of the cognitive load of using C++ only to add new and different cognitive load when switching between languages. New language adoption always has a very high barrier to entry, and Carbon seems to be shooting itself in the foot with regards to many of its design decisions. It would be 100x better to use C++ conventions for everything that isn't necessary to gain an actual improvement, and if you do want to make it feel more like a modern Kotlin/TypeScript take on C++, then any change you do make should be to transition to something that operates more like one of those languages, for instance adopting their common naming conventions, and not something that's unnecessarily confusing like Just my opinion, for sure, but I don't think my opinion will be unique in this regard. |
Beta Was this translation helpful? Give feedback.
-
Personally I don't think any particular convention should be enforced/preferred. I happen to prefer snake_case as I find it easier to read. It is a subjective topic. I would recommend that keywords and basic types stick to lowercase (as they seem to currently). That is a common convention in many programming languages. If complex library types follow camelCase etc then fair enough, as long as I am not forced to use them. I would probably write my own anyway as I do with C++ today. If strings or slice became a builtin type i would strongly encourage string and slice over String and Slice for example. Main() is an interesting one. The name of one function won't bother me but it feels like it should be lowercase as it is a special function and kind of like a keyword. Even better would be making it easy to define the entry function ourselves. This could be useful with conditional compilation. I might have one main for sample A and another for sample B. |
Beta Was this translation helpful? Give feedback.
-
Why does carbon choses to use PascalCase for function and methods names as well instead of camelCase or snake_case?
Beta Was this translation helpful? Give feedback.
All reactions