rhombus-prototype
rhombus-prototype copied to clipboard
Naming conventions: underscores instead of hyphens
One thing that bothers me regularly is hyphens and their many usages.
In Racket, they can be:
- a naming convention for sticking words together to make an identifier
- how struct field accessor and mutator identifiers are generated
- used for arithmetics, such as
(define 1-α (- 1 α))
Regarding the first point, I find underscores significantly easier to read, in particular to distinguish them from spaces. For example, how many identifiers are there in the following sentence?
There are-more-things in-Heaven and Earth-Horatio-than are dreamt-of in-your philosophy
Where do the identifiers start and end? One need to carefully look at mid-character level to look for hyphens or their absence. Doing so is noisy due to the different shapes of the letters. In particular it's troublesome next to an e or even an a which have mid-character level horizontal lines. By contrast, for
There are_more_things in_Heaven and Earth_Horatio_than are dreamt_of in_your philosophy
one just needs to look at the base level, which I find easier.
Regarding struct fields, I believe a dot notation would really make sense, since it's already quite widespread, is distinctive, while not cluttering the visual field (by contrast to using & for example).
Regarding arithmetics, if we adopt infix notation by default, sticking to hyphens in identifiers would only make the problem worse I guess.
See here for a different opinion on the subject though.
Strong vote against underscores. They are an utter pain to type, and it seems unlikely that hyphen-minus would be somehow banned from use in symbols. They also open up the useless bikeshedding about CamelCase vs snake_case, but since I doubt that rhombus will move away from whitespace delimited tokens, this seems moot. I will disclose that I'm a huge fan of not having to deal with the naming convention nonsense that show up in other languages because basic grammar rules make kebab-case possible. (Disclosure, I'm a big fan of the current style guide.)
With regard to infix notation, I (again) think that whitespace delimited tokens prevent the issue. The brain parser does pretty well once it knows to look for spaces.
I also think that the example you are using is fundamentally misleading, because you are presenting a sentence where there should always be spaces between words so the brain simply reads the words and struggles to see where the hyphens (that should not be there) are present. This issue is rarely the case in code because code rarely triggers the "this is a sentence" part of the brain.
In my opinion, infix - is the most convincing argument against the kebab-case, though that doesn't mean we can't have it as @tgbugs pointed out above (and this is what Pyret does).
The readability argument doesn't feel satisfying to me. When it comes to HTML and CSS, no one says it's hard to read.
I like hyphens in names, because they are both readable within an identifier, while they are also easily distinguished from spaces. This means if there are words, dashes, and spaces mixed together, the dashes imply a grouping while the spaces imply a separation.
In the sentence-you-are-now-reading, when words are grouped-together by dashes, it implies a speed-of-reading that can help parse the sentence-phrases.
If I used _ underscores, that advantage would go away.
In my opinion, infix
-is the most convincing argument against the kebab-case, though that doesn't mean we can't have it as @tgbugs pointed out above (and this is what Pyret does).The readability argument doesn't feel satisfying to me. When it comes to HTML and CSS, no one says it's hard to read.
Indeed, CSS itself supports both infix - and kebab-case. From the spec:
In addition, white space is required on both sides of the + and - operators. (The * and / operators can be used without white space around them.)