by aloukissas on 1/25/23, 10:38 PM with 257 comments
by layer8 on 1/26/23, 3:48 AM
- Typing "ABC" Ctrl+Space gives me code completion for AsynchronousByteChannel (and the like), whereas "abc" Ctrl+Space gives me code completion only for what strictly starts with "abc". I.e. uppercase means "words starting with that letter". Of course you could have something equivalent for non-CamelCase naming conventions, but for CamelCase it is a very natural fit.
- It provides the two variants lowerCamelCase and UpperCamelCase (often used for variable names vs. type names), whereas lower-kebab-case & Upper-Kebab-Case or lower_snake_case & Upper_Snake_Case seem more awkward in comparison (more keystrokes for the "upper" variant).
- When lowerCamelCase is used for function names, the case distinction often maps nicely to verb + noun (`createFooBar()`, `validateBazQuz()`).
- You still have underscore available to occasionally "index" a name (`transmogrifyFooBar()`, `transmogrifyFooBar_unchecked()`) unambiguously.
- The fact that CamelCase does not match normal English spelling has the advantage that it can't clash with it. CamelCase can stand both for hyphenated-compound-words as well as for open compound words (or just a phrase), whereas other naming conventions may look like the one although the words really stand for the other.
- Minor advantage: You can fit slightly more words into a line.
Apart from that, I'm pro-kebab-case.
by int_19h on 1/26/23, 12:24 AM
foo.bar_baz.blah()
being difficult to parse when quickly skimming through code. OTOH kebab-case solves this nicely because "-" is not in the same place as "." in the character cell, and being in the middle, groups more naturally with letters: foo.bar-baz.blah()
Then again, maybe the established formatting conventions for member access are just suboptimal? Suppose that we put a space before every "."; then: foo .bar_baz .blah()
by inDigiNeous on 1/25/23, 11:11 PM
I tried to convince my co-workers toTransitionFromCamelCase to the world_of_easy_reading_snake_case, but alas, the codebase alreadyUsingCamelCase won.
Maybe it's the idea that "shorter == better", or whatever, but if I could choose, I would use snake_case_everywhere man.
by hypertele-Xii on 1/26/23, 12:35 PM
If you use spaces in your normal writing, there's no reason you shouldn't use spaces in programming - except that a space prevents you from easily selecting the whole phrase, a very common operation programmers face.
So they replaced the space with a character that is effectively identical, but works better.
Some people figured they could just remove it. WellTellMeThis,DoesItMakeMyTextMoreReadableToYou? If you argue that camelcase is better, then shouldn't we adopt it into normal writing too? Why not?
by tlb on 1/26/23, 9:57 AM
Screenshots at https://visibot.com/post/kebab-case
This is for a custom language & IDE, but someday I'll get around to making VSCode do the same.
by jjice on 1/25/23, 11:35 PM
Snake is my preferred. The Python/Rust use of snake case and Pascal case for their respective purposes is my favorite.
by asiachick on 1/26/23, 3:41 AM
Many modern computer languages (JavaScript, Rust, Swift, ...) allow non-ascii identifiers so if you pick camelCase, then someone writing Japanese, Chinese, Korean has no way to obey. That doesn't mean snake_case would be all that better in those languages though.
var 画面_幅 = ...;
var 窓_縦 = ...;
The point is, both camelCase and snake_case are a thing based around western languages.by wodenokoto on 1/26/23, 4:22 AM
Why yes. Kebab case would be so much better.
Or dots, like R uses.
Neither of those are compatible with most languages, but they are a better options for current keyboards.
by CoolGuySteve on 1/25/23, 11:01 PM
Goldman Sachs' Slang language allowed spaces in tokens which was actually much better but I guess your grammar has to support that from the ground up.
by pavlov on 1/26/23, 10:18 AM
It's like if file systems were forever stuck on FAT and everybody was quietly resigned to the idea that you can simply never, ever have more than 8+3 characters in a file name. "That's just how computers work. Anyway, I'll share you the latest budget spreadsheet on Google Docs, it's called BDG2023A.GDC"
by userbinator on 1/26/23, 3:17 AM
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
by pleb_nz on 1/26/23, 7:38 AM
Assuming as they're similar they're being used interchangeably in this context?
by yakubin on 1/25/23, 10:59 PM
by r2b2 on 1/26/23, 7:08 AM
TypeName, ClassName
functionName, methodName
variable-name, symbol-name # if possible
variable_name, symbol_name
by ldh0011 on 1/26/23, 1:55 PM
by dools on 1/26/23, 11:19 AM
1) functionsLikeThis
2) variables_like_this
3) ClassesLikeThis
by danbruc on 1/26/23, 8:24 AM
by frereubu on 1/25/23, 11:17 PM
by Zigurd on 1/26/23, 12:15 AM
by pyrolistical on 1/25/23, 11:56 PM
by claytongulick on 1/26/23, 4:20 AM
I do lowercase snake for_variable_names, camel case forFunctions() and title case ClassNames.
In markup, CSS class names are kebob-case but IDs follow snake_case rules (this is so that they can be referenced easily and are valid identifiers in js).
I like this approach because I can tell at a glance by the naming convention what kind of identifier I'm dealing with.
I dislike the common js style of everythingIsCamelCase, I find it more difficult to read - and in a language where functions are a primary type, I think it's good practice to differentiate stylistically a variable from a function within the closure or prototype chain.
by Mikhail_Edoshin on 1/26/23, 6:32 AM
Lx_DoThis -- function
Lx_DoThis_Gen -- generic impl.
Lx_DoThis_Gcc -- GCC-specific
LxMyType -- type (class)
LxMyType_DoThat -- method
That is if I use underscore to separate words, I get names that appear to be composed of an arbitrary number of parts. I want that apparent composition to be meaningful.In a more sophisticated language where types, methods, and variants have native support, this reduces to essentially camel case. Which still looks better to me because a single thing appears as as single word, not a random number of words.
by HarHarVeryFunny on 1/26/23, 2:02 PM
e.g. MyType myType;
I'm not quite sure what made me switch, but nowadays I used lower case and underscores for all identifiers other than constants, and use a "_t" suffix to distinguish types.
e.g. color_t color; string_list_t list;
I think it's certainly easier on the eyes and more readable.
At the end of the day though it's personal preference, unless you're working on an existing code base where you should adopt the naming and formatting conventions of the code base.
by cpeterso on 1/26/23, 5:29 AM
by MetaWhirledPeas on 1/25/23, 10:57 PM
by robomartin on 1/26/23, 6:19 AM
Computers do not care. Seriously. I don’t know about others, I have far more important and urgent things to worry about in the course of completing a project than this_case or thatCase. I prefer this_case, probably out of habit. Yet, it isn’t important. I’ll use anyCase if required. My bank account also could not care less.
by cassepipe on 1/26/23, 9:48 AM
You want arguments? Even though they're post rationalizations of what I like best?
OK, well first I hate to type caps, then I hate CAPS, so more than one in a word is unbearable. ThenIThinkItsHardToRead. Finally I like that we have a visible symbol to mean space that's still visible. Who is going to use it if we programmers don't?
by jacobsenscott on 1/25/23, 11:55 PM
by Pxtl on 1/26/23, 3:47 AM
by benreesman on 1/26/23, 10:33 AM
by psychoslave on 1/26/23, 4:37 PM
However it doesn’t in any Shell I tried (bash, fish, zsh) nor C#, Go or Java.
by innocentoldguy on 1/25/23, 11:04 PM
This may be why I tend to gravitate towards languages like Elixir and Ruby, who prefer snake_case, and away from languages like Go, which use camelCase.
by bitwize on 1/26/23, 1:21 AM
by inopinatus on 1/25/23, 11:43 PM
by cb321 on 1/26/23, 11:14 AM
by teddyh on 1/26/23, 10:58 AM
by emodendroket on 1/26/23, 7:00 AM
by dec0dedab0de on 1/25/23, 11:36 PM
by osigurdson on 1/26/23, 1:55 PM
by every on 1/26/23, 6:02 AM
by kovac on 1/26/23, 7:32 AM
On a more serious note, I feel like a reasonable middle ground is to agree to use one-word identifiers only.
by rpaddock on 1/26/23, 7:16 PM
by jws on 1/26/23, 12:11 AM
How about Unicode "Thin Space" 0x2009 for a legal identifier character? (HN isn't letting me put the Thin Space in there.)
How about Unicode "Middle Dot" 0x00B7 for a legal identifier·character?
Best if you aren't in a fixed with editor for those.
I used middle dot in an experimental language which was Unicode heavy so already didn't like fixed width fonts. It parses trivially and reads well.
I haven't tried the thin space in earnest, but the example code I typed up looked reasonable.
by MichaelMoser123 on 1/26/23, 3:29 AM
by metadat on 1/25/23, 11:41 PM
Thank goodness for PyCharm auto-complete. Typing every variable name fully manually in snake_case 24/7 everyday was begging for me to develop RSI.
by 0x073 on 1/25/23, 11:18 PM
by skerit on 1/26/23, 8:43 AM
by teddyh on 1/26/23, 12:10 AM
by transfire on 1/26/23, 8:29 AM
by thrown1212 on 1/26/23, 1:21 PM
by kybernetyk on 1/26/23, 5:32 AM