3 ms·
Why not both and neither? IMHO this is one of those things where people seem to congregate and advocate for one side religiously, but I don't see much value in
by userbinator 4y ago
Why not both and neither? IMHO this is one of those things where people seem to congregate and advocate for one side religiously, but I don't see much value in that. Why can't the style simply imply how much scope and importance an identifier has? I've never liked naming dogma, but this is what I find to be natural:
trivialidentifier - local variables inside a function, usually < 3 words/abbrs
slightly_important_identifier - function names with limited scope
ImportantIdentifier - widely-used functions, class/struct names
More_Important_Identifier - classes/structs that are quite important
VERY_IMPORTANT_IDENTIFIER - global constants and (rarely) classes/structs
- __ryan__ 4y agoWhy can't the style simply imply how much scope and importance an identifier has? Because lack of underscores doesn’t unanimously imply lack of importance or scope.
- kelnos 4y agoThat seems less understandable to me. I think it's easier to grok if certain classes of things always use the same casing. So all functions would use snake_case, type names would use PascalCase, global constants use UPPER_CAMEL_CASE, etc. "Importance" is subjective, and regardless, IMO not really an important measure of anything.
- layer8 4y agoBecause everyone will have a different opinion about the importance of any given name.
- andreareina 4y agoHell I'll have differing opinions about the importance of the same name at different times of day.
- rootusrootus 4y agoThat's sort of what Python's PEP8 recommends. CamelCase for class names, snake_case for the rest, and SNAKE_CASE for constants.
- cpeterso 4y agoAnd Ruby and Rust.
- jjgreen 4y agoShame that the standard library doesn't follow those recommendations (hello unittest).
- pavo-etc 4y agoalso startswith(), endswith()
- dotancohen 4y agoInterestingly, PHP's PSR family specifically does _not_ take a stance on naming conventions for locally-scoped variables.
- scns 4y agoI call it CONSTANT_CASE and use it for constants.
- layer8 4y agoIt’s commonly called ALL_CAPS (e.g. https://gcc.gnu.org/codingconventions.html#C_Names https://gcc.gnu.org/codingconventions.html#C_Names).