News for hackers. Stuff that matters.
Re:CamelCase vs. Underscores: Revisited by hypertele-Xii on Thursday January 26, 2023 @07:35AM (#34530914)
An underscore is a word-separating space that selects as part of the sentence.

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?

Re:CamelCase vs. Underscores: Revisited by paulcole on Thursday January 26, 2023 @08:03AM (#34531128)
CamelCase doesn’t need to be more readable, it just needs to be readable enough. And when you keep names short, it is.
Re:CamelCase vs. Underscores: Revisited by nmz on Thursday January 26, 2023 @08:56AM (#34531620)
3 wordsIsTheLimit, afterThat, its_better_to_use_underscores.
Re:CamelCase vs. Underscores: Revisited by __ryan__ on Thursday January 26, 2023 @08:44AM (#34531487)
There’s plenty of things that are done in code that we don’t adopt in prose and vice versa. You could just as easily make the case for adopting underscores in place of spaces in prose to increase readability, but we haven’t done that.

In code, you have to balance readability in many contexts.

Snake case and kebab case look more readable in isolation, but do they look better when used as part of a larger expression, for example part of a chain of member access and method calls and argument passing? I don’t think the answer is obvious, and it probably depends on other formatting affordances (e.g. breaking the expression up on multiple lines).

I’m on mobile and I don’t trust HN’s formatting to do any justice with examples, but it might be worth trying it out in your code editor.

Re:CamelCase vs. Underscores: Revisited by TomSwirly on Thursday January 26, 2023 @09:20AM (#34531867)
It'sSimplyNotVeryNaturalToReadTextWhereCapitalLettersTakeThePlaceOfSpaces,AndThereIsThe"NASAIs"ProblemToo.

In_most_fonts,_the_underscore_character_is_visually_like_a_space,_and_you_can_distinguish_"NASA_is"_and_Mike_vs_mike.

Re:CamelCase vs. Underscores: Revisited by __ryan__ on Thursday January 26, 2023 @11:20AM (#34533746)
I’m specifically saying that prose/text and code are different contexts that don’t necessarily benefit from the same styles of writing.

What I was saying is that just because spaces in prose naturally improves visibility does not _necessarily_ mean that underscores and dashes improve overall readability across many contexts _in real code_, because code and prose are different. It could be the case, but it’s not the obvious innate property people are suggesting it is.

If it such an obvious innate improvement in readability, then why don’t we replace spaces with underscores in prose and handwriting? It would remove any ambiguity between intentional separation and awkward unintentional spacing or kerning. But we don’t and haven’t done that for some reason, so there must be something else at play.

Your examples (and many examples in this thread) of long sentences in these formats are not what code actually look like.

Real code has meaningful symbols and syntax that occur between identifiers that carry semantic meaning. Maybe the lack of symbols in identifiers in camel and pascal case make it easier to identify these other symbols and syntactic elements, so you end up with better overall readability. Maybe adding to that the flexibility of using camel and pascal and upper snake case for different "types" of identifiers improves mental mapping of code concepts that you'd lose if you always used snake case.

Again, I'm only making the argument that readability in code and readability in prose are two totally different things, and the effects of different casing and different identifier naming schemes are likely more subtle than what is better clearly separating words in the identifier.

Re:CamelCase vs. Underscores: Revisited by Clamchop on Thursday January 26, 2023 @04:17PM (#34538972)
Is it not natural or are you just unpracticed at it?
Re:CamelCase vs. Underscores: Revisited by jfk13 on Thursday January 26, 2023 @08:46AM (#34531504)
I don't think the issue with spaces is primarily about selection; it's about parsing.
Re:CamelCase vs. Underscores: Revisited by hypertele-Xii on Saturday January 28, 2023 @03:41AM (#34556177)
When I write code I'm not thinking about parsing. When I write code, I'm thinking about writing code. Underscores makes coding easier (for improved selection behavior). Ergo, the issue with spaces is primarily about selection (for me).
Re:CamelCase vs. Underscores: Revisited by tgv on Thursday January 26, 2023 @08:51AM (#34531559)
> So they replaced the space with a character that is effectively identical

I don't think that's the reason. The reason was ease of parsing. It's harder to write a token recognizer if spaces are allowed in identifiers and distinguish them from type names and reserved words.

ALGOL-68 famously did allow spaces in identifiers, e.g. https://rosettacode.org/wiki/Boustrophedon_transform#ALGOL_6...

Re:CamelCase vs. Underscores: Revisited by dgb23 on Thursday January 26, 2023 @09:00AM (#34531659)
I like the notion of discriminating the general kind that names refer to with different separation styles. I think the most common are:

- camelCase

- PascalCase

- snake_case

- kebab-case

- |sentence case|

I think the last one can be used in CL, but not 100% sure.

Some examples:

- Clojure prefers kebab-case mostly, but some types and definitions use PascalCase to imply that there is a more direct mapping to a Java class. Clojure prefers to use namespaces to name things that belong together over long, prefixed names. Single letter names are common for function parameters such as 'm' for maps, 's' for strings and so on.

- Go prefers camelCase for private/local types fields and functions. When PascalCase is used, then the name is exported. Go generally prefers short, often abbreviated names (Unix/C heritage).

- Rust prefers PascalCase for type definitions, snake_case for function names, locals and parameter names.

- Both in Go and Rust, packagas/modules/crates give additional naming structure but also control visibility. So those things have multiple jobs.

So generally the-wayWe_Type/And-NameThings in different languages can give us a bit more structure and meaning without cluttering the syntax with additional keywords. A big side-benefit is that we then don't need to decide which style to use! It's better to have a uniform style than your personally preferred one IMO.

Re:CamelCase vs. Underscores: Revisited by atombender on Thursday January 26, 2023 @09:40AM (#34532118)
I never understood why some languages like Rust are so inconsistent here: snake_case for non-type identifiers, but PascalCase rather than Snake_Pascal_Case for types.

Maybe OP's study is real, but the underscore has always bothered me. I'm fine with it in principle, but it creates visual noise, since pretty much all fonts put the underscore below the baseline.

Here's a mockup that fixes the vertical placement of the underscore (right hand side):

https://i.imgur.com/5sF3QMH.png

Much better!

Re:CamelCase vs. Underscores: Revisited by toastal on Thursday January 26, 2023 @09:14AM (#34531806)
If you think that last bit of wacky casing combinations is offensive, wait BEM-style CSS selectors—not the philosophy or separation of components, just the selectors themselves. Basically any other naming or separator selection would have been better.
Re:CamelCase vs. Underscores: Revisited by kagevf on Thursday January 26, 2023 @04:28PM (#34539085)
> I think the last one can be used in CL, but not 100% sure.

You can create a symbol that way:

  (let ((|my symbol| 123))
    |my symbol|)

  => 123
Re:CamelCase vs. Underscores: Revisited by ulizzle on Thursday January 26, 2023 @10:25AM (#34532817)
Because "normal" writing (prose) isn't code.

The medium dictates the delivery.

Re:CamelCase vs. Underscores: Revisited by hypertele-Xii on Saturday January 28, 2023 @03:46AM (#34556200)
Normal writing and code are both text to be read by humans. They are the same medium with regards to readability. Our brains use the same circuits we developed to read normal writing to read code. I haven't seen any evidence to the contrary.