News for hackers. Stuff that matters.
Re:CamelCase vs. Underscores: Revisited by yakubin on Wednesday January 25, 2023 @05:59PM (#34525366)
Do you have a moment to talk about our lord and saviour kebab-case?
Re:CamelCase vs. Underscores: Revisited by tmtvl on Wednesday January 25, 2023 @06:15PM (#34525532)
I'll second that, kebab-case is easy to type, has nice readability, and fits well with regular English constructions like case-sensitive, human-sized, looking-glass, and so on.
Re:CamelCase vs. Underscores: Revisited by alexisread on Wednesday January 25, 2023 @06:20PM (#34525590)
The problem I've had with kebab case is cross language / devops systems. Some languages and systems don't like kebab case whereas snake case appears more compatible eg. Rpc calls to a named (kebab or snake endpoint).
Re:CamelCase vs. Underscores: Revisited by taeric on Wednesday January 25, 2023 @06:40PM (#34525781)
I thought this was mainly because of infix math operators?
Re:CamelCase vs. Underscores: Revisited by roenxi on Wednesday January 25, 2023 @06:26PM (#34525641)
maybe it is some sort of status thing. since people have to be able to afford a fancy keyboard with a shift key to use camel case or underscores, it shows they can afford nicer things than us kebab-cases.

more seriously, it is the unfortunate fact that a lot of systems interpret named-thing and named minus thing. many people don't have the option of using kebab-case. it isn't a good style because it is often impossible to use. which is unfortunate because it is more ergonomic.

Re:CamelCase vs. Underscores: Revisited by waiting4shoe2 on Wednesday January 25, 2023 @06:57PM (#34525957)
The obvious solution is to make `kebab‐case` a name, `kebab−case` a subtraction, and `kebab-case` an error.
Re:CamelCase vs. Underscores: Revisited by Waterluvian on Wednesday January 25, 2023 @06:06PM (#34525432)
onlyifwehavetimetotalkaboutflatcase
Re:CamelCase vs. Underscores: Revisited by aloukissas on Wednesday January 25, 2023 @06:13PM (#34525510)
ALLCAPSCASEPLSFIX
Re:CamelCase vs. Underscores: Revisited by TylerE on Wednesday January 25, 2023 @06:34PM (#34525718)
ThErEArRWOrSeOpTiOnSCaSe
Re:CamelCase vs. Underscores: Revisited by Zamicol on Wednesday January 25, 2023 @06:45PM (#34525822)
We've dubbed this "ridicule" case.

Upper case is majuscule.

Lower case is miniscule.

Mixed case is ridicule.

https://en.wikipedia.org/wiki/Letter_case#Terminology

Re:CamelCase vs. Underscores: Revisited by txbuck on Wednesday January 25, 2023 @06:57PM (#34525955)
I've seen it dubbed "sponge-case" and am pretty fond of the term.
Re:CamelCase vs. Underscores: Revisited by TylerE on Wednesday January 25, 2023 @06:51PM (#34525885)
Mine is actuall a bit more specific. Capitalize every other letter PLUS the start of each word
Re:CamelCase vs. Underscores: Revisited by downvotetruth on Wednesday January 25, 2023 @06:57PM (#34525959)
WoXCvSZ: randomly only capitalizing C,O,S,V,W,X,Z
Re:CamelCase vs. Underscores: Revisited by tmtvl on Wednesday January 25, 2023 @08:17PM (#34526573)
There arr worse options? Is that Pirate Case?
Re:CamelCase vs. Underscores: Revisited by djbusby on Wednesday January 25, 2023 @06:25PM (#34525630)
Doesn't match \w+
Re:CamelCase vs. Underscores: Revisited by choult on Wednesday January 25, 2023 @06:12PM (#34525497)
kebab-case = doner meat
Re:CamelCase vs. Underscores: Revisited by txbuck on Wednesday January 25, 2023 @06:44PM (#34525817)
The fact that kebab-case support is a rarity constantly boggles my mind, nevermind that it isn't the de facto default for any language created after *sh/lisp. Readability, ease-of-typing, parallel with the way it's used in (Romantic) natural language. If I were writing a new language I intended to popularize this would be one of the features I would emphasize.

Spicy semi-snarky aside: if your counterpoint is that kebab-case prevents crushing your arithmetic operators together, I strongly suggest you either reconsider or never write any code you think may be read by another human being (and possibly yourself).

Re:CamelCase vs. Underscores: Revisited by int_19h on Wednesday January 25, 2023 @07:06PM (#34526057)
It is (was?) the default for XSLT and XQuery, if we're talking about something relatively mainstream. Beyond that I can think of Dylan and REBOL.
Re:CamelCase vs. Underscores: Revisited by capableweb on Thursday January 26, 2023 @03:18AM (#34529100)
CSS is probably the most mainstream language allowing dashes in names.
Re:CamelCase vs. Underscores: Revisited by int_19h on Thursday January 26, 2023 @03:40AM (#34529239)
Depends on whether you count all the serialized data on the wire or not; if you do, it's probably XML. ~

But I think OP meant programming languages, not styling or markup.

Re:CamelCase vs. Underscores: Revisited by gpderetta on Thursday January 26, 2023 @06:24AM (#34530376)
Everybody forgets about shell scripts! Bash allows dashes in executable names (how it couldn't) and in function names, but not in variable names, at least not without a lot of effort.
Re:CamelCase vs. Underscores: Revisited by Arch-TK on Wednesday January 25, 2023 @06:57PM (#34525950)
It's a bit hard to parse it outside of languages like lisp because of infix.
Re:CamelCase vs. Underscores: Revisited by thaumasiotes on Wednesday January 25, 2023 @07:08PM (#34526077)
Infix has nothing to do with it. We can already parse expressions of the form "x - 20". The change would be to stop interpreting "x-20" as being the same set of three tokens as "x - 20".
Re:CamelCase vs. Underscores: Revisited by taeric on Wednesday January 25, 2023 @07:28PM (#34526227)
That is the point, though? Is "x- 20" the same as "x - 20" the same as "x -20" In the vast majority of modern programming languages, that is a yes. If you allowed dashes in the names, not so much.

Now, I grant the point that it is doable. But the point is it complicate things. Now, fair, we have some of these complications already by virtue of the fact that we allow numbers in variable names. "foo3" is already allowed in many languages, and that clearly gets altered as you add space between the characters.

Re:CamelCase vs. Underscores: Revisited by thaumasiotes on Wednesday January 25, 2023 @07:49PM (#34526375)
> Is "x- 20" the same as "x - 20" the same as "x -20"[?] In the vast majority of modern programming languages, that is a yes.

Is that really true? I wouldn't exactly feel comfortable with "x -20", though I suspect you're right about at least a large number of languages determining the meaning of the hyphen through local syntactic context ("I just saw an identifier; that must be a non-unary hyphen").

Now I'm interested in whether the corpus of existing code shows any bias between "y = -x" (perfectly allowed, I think) and "y = -1 * x".

Re:CamelCase vs. Underscores: Revisited by Arch-TK on Wednesday January 25, 2023 @08:26PM (#34526634)
Distinguishing unary minus from binary minus is not done by spacing in parsers. Most modern language parsers ignore whitespace except where it would cause the concatenation of two identifiers (or in the case of languages like python or nim, where it is at the beginning of a line).

I know this for a fact since I've studied their grammars.

Infix notation and - are really the reasons why nobody does this, some people like to use spacing to indicate precedence too (writing code such as "a - 1*g") so it would break some workflows and realistically having a language which is whitespace agnostic except for identifiers AND the minus operator just seems too irregular for people to commit to it.

Re:CamelCase vs. Underscores: Revisited by Joker_vD on Thursday January 26, 2023 @04:55AM (#34529745)
Depends on the parser. See e.g. [0] for Elm's take on it: it already had special logic for differentiating "(.)" and "( . )".

[0] https://elm-lang.org/news/0.9

Re:CamelCase vs. Underscores: Revisited by Arch-TK on Thursday January 26, 2023 @07:17AM (#34530779)
That's why I said most. Obviously there exist languages, such as elm, where this is not the case, but in the case of those languages, the teaching literature (as is the case with elm) explains these things. Most languages don't do this precisely because their designers made the judgement call that the additional parsing complexity (both for the actual parser and the human) outweighed the benefits of allowing you to have minuses in identifiers.
Re:CamelCase vs. Underscores: Revisited by gnulinux on Wednesday January 25, 2023 @07:00PM (#34525986)
I think you're maybe just a little confused, or I'm missing something. Kebab case is in general not viable to implement unless you have very a special/quirky syntax, because there is no way differentiate to `a-b` from `Id("a-b")` and `Subtract(Id("a"), Id("b"))` from syntax alone. Now, there are of course options that introduce trade-offs.

First obvious option is to get rid of the infix "-" operator, which is what Lisp does. In lisp-like languages you don't write "a - b" instead you write "- a b", this way there is nothing to confuse "a-b" with.

Another option is to require a space between operators. E.g. you are not allowed to write "a+b" to mean "add a to b". You have to write "a + b". This is used in Agda programming language. This is very useful because then you can have identifiers like "a+b", or even identifiers like "a+[b+c-d]" etc... As long as any char doesn't have a special meaning (e.g. in Agda "(", ";", "," etc have special meanings) you can use it in an identifier. The trade-off is that, well now you're not allowed to condense arithmetic operations. This may or may not be a problem, depending on the programming language designer. When you said:

> I strongly suggest you either reconsider or never write any code you think may be read by another human being (and possibly yourself).

I'm guessing your opinion is that you're ok with this trade-off. Fact of the matter is that this a very fringe syntax for any programming language to have. As an Agda programmer, I like it, and it is useful, but I'm not convinced something like this would find mass appeal.

The last option I'm aware is to have semantic differentiation. When you find a statement like "c = a-b" you need to ask two things. One, are there identifiers "a", "b" and "a-b". If "a-b" exist and "a" or "b" doesn't exist, you're all set. If all three exist, second question is, are "a" and "b" subtractible? If the answer is yes then programming language designer can choose to prioritize "a - b" over identifier "a-b". Alternatively, you can always choose to prioritize identifier "a-b" as long as it exists. I'm personally not aware of any language that implements something like this, however I have implemented toy languages that go through this, it's pretty easy. It's a matter of making the decision to introduce this type of complexity into your language.

All in all, although I love kebab case, in order to have it in your language you need to make pretty significant trade-offs. Given this, I'm not surprised any mainstream non-lisp-like language doesn't have it.

Re:CamelCase vs. Underscores: Revisited by txbuck on Wednesday January 25, 2023 @07:26PM (#34526205)
(Hot damn, that was a super thorough/thoughtful reply in a short amount of time.)

You're spot on about the quirky syntax, but I don't think it's as serious a trade-off or addition in complexity (or even a change), given that:

- (IIRC) many style-guides/formatters already enforce spaces between binary operators and their operands (but especially identifiers) and in my super-subjectively-opinionated opinion you should already be doing that even without a formatter

- I don't feel particularly strongly one way or another about any other special characters like "+", so really in this case I'm only considering the dash

- Requiring the dash between alpha/alphanumerics makes it play nice with unary operators

- The language would be terrible for code-golfing, but that's a relatively niche application I'd definitely consider worth spurning

Re:CamelCase vs. Underscores: Revisited by thaumasiotes on Wednesday January 25, 2023 @07:11PM (#34526106)
> First obvious option is to get rid of the infix "-" operator, which is what Lisp does. In lisp-like languages you don't write "a - b" instead you write "- a b", this way there is nothing to confuse "a-b" with.

This is a gross error. In your sense, Lisp does not even have operators, only identifiers. The reason there is no confusion between "(- a b)" and "(-ab)" is the spacing that separates the three identifiers in the first case.[1]

Your comment is especially weird because you go on to discuss Lisp's approach as being "an alternative option to what Lisp does".

[1] However, Lisp does have a potential problem with identifiers that begin with a hyphen, due to the need to support literal numeric values like -3. Thus the Common Lisp decrement function is named "1-" despite not returning the value (1 - operand).

Re:CamelCase vs. Underscores: Revisited by cornstalks on Wednesday January 25, 2023 @11:08PM (#34527569)
> Your comment is especially weird because you go on to discuss Lisp's approach as being "an alternative option to what Lisp does".

I assume you're talking about GP's third paragraph here. Assuming that's true, I think you've misinterpreted it: GP was talking about using infix operator notation, which is most certainly not what Lisp does.

Re:CamelCase vs. Underscores: Revisited by thaumasiotes on Thursday January 26, 2023 @01:44AM (#34528423)
No, that's irrelevant.

Lisp will treat (a - b) as 5 tokens, just the same way it will treat (- a b) as 5 tokens. Infix operators are completely unrelated to this problem. What lisp is doing is determining tokens by reference to spacing (the parentheses don't need to be spaced; I believe they are reader macros but in any event they are special-cased) and then acting on the tokens. What C is doing is not that; the concept is that you eliminate all spacing before you decide what the tokens are.

So in C, there is no such thing as "a - b", only "a-b", and that's why "a-b" cannot be used as an identifier.

If you want to write your lisp in infix notation, you can, but it will remain true that (a - b) is a list with 3 elements and (a-b) is a list with 1 element, which is what matters here.

Re:CamelCase vs. Underscores: Revisited by bmacho on Thursday January 26, 2023 @05:52AM (#34530167)
What GGP wrote:

> First obvious option is to get rid of the infix "-" operator, which is what Lisp does. In lisp-like languages you don't write "a - b" instead you write "- a b", this way there is nothing to confuse "a-b" with.

> Another option is to require a space between operators. E.g. you are not allowed to write "a+b" to mean "add a to b". You have to write "a + b". This is used in Agda programming language.

is kinda not good, Lisp allows "-" in names the same reason as Agda: it tokenize by spaces (correct me if I'm wrong). This may seem as a gross error for one, and an only implied who cares error which is even true if taken word-by-word, for an other.

Re:CamelCase vs. Underscores: Revisited by gnulinux on Thursday January 26, 2023 @09:51AM (#34532292)
This is true, I apologize for the error.
Re:CamelCase vs. Underscores: Revisited by kaba0 on Thursday January 26, 2023 @04:52AM (#34529722)
> As long as any char doesn't have a special meaning (e.g. in Agda "(", ";", "," etc have special meanings) you can use it in an identifier. The trade-off is that

I would say the trade off is variable names like “a+b” themselves. I fail to see any reason why would I want something like that, like even in Math where the grammar is very hand-wavy to accommodate human parsing you would be insane to write that (though to be fair, math does have their own share of problem with identifiers, enumerating all the letters in different alphabets is not a sustainable solution)

Re:CamelCase vs. Underscores: Revisited by goerz on Thursday January 26, 2023 @07:10AM (#34530707)
I would totally want that! Specifically, `a+b = a + b` where `a + b` is an expensive operation. Julia allows stuff like that to some extent, e.g. https://github.com/JuliaQuantumControl/Krotov.jl/blob/3132f0..., but unfortunately not with `+`
Re:CamelCase vs. Underscores: Revisited by kaba0 on Thursday January 26, 2023 @07:18AM (#34530784)
Why not just give it some temporary name, like ‘t’, supposedly it is only used in a very tight scope. Haskell and similar languages often do these things with `let in ..` or `.. with t=a+b`.
Re:CamelCase vs. Underscores: Revisited by goerz on Thursday January 26, 2023 @07:24AM (#34530835)
Because `a+b` is a much better variable name than `t`? Why `t`? If anything, `a_plus_b` or `apb`
Re:CamelCase vs. Underscores: Revisited by kaba0 on Thursday January 26, 2023 @07:50AM (#34531020)
Not really better at all, but I feel this is a bit contrived example. If it really is just numeric addition that just let the compiler do its job, otherwise I’m sure there are better names for whatever you actually try to do. And, random helper variables are a thing even in math, you don’t name the thing the way you calculate that thing because then you don’t spare any character.
Re:CamelCase vs. Underscores: Revisited by jostylr on Thursday January 26, 2023 @08:02AM (#34531123)
One could also not have subtraction but simply negation, so instead of a-b being subtraction, one could have a+-b. It probably already works in most languages. Doubt it would be embraced.
Re:CamelCase vs. Underscores: Revisited by txbuck on Wednesday January 25, 2023 @08:18PM (#34526578)
For reference, something like like this (Python regex):

  ^[a-zA-Z_]+[a-zA-Z0-9_]*(-?[a-zA-Z0-9_]+)*$

  some-name
  some2-name
  some-2-name
  some-2name
  some-name2
  some-name-2
  some2other-name
  some-other2name
  some-othername2
  some-2othername
  some-0-other-name
  a-0-name
  a0-0a-0a-a0
  kebab-case-pls
  tbh-didnt-write-any-underscore-tests

  -negated
  -negated-variable
  -(negated)
  -(also-negated)
  -(-double-negated)
  binary - operation
  binary + operation
  double - binary - operation

  2-syntax-error-4-me
  2syntaxerrorforme
  1-2-3-4-syn-tax-err-or
  80086-syntax-error
  syntax+error
  syntaxerror+
  syntax-error+
  syntax-error-
  syntax-(error)
  (syntax)-error
  syntax--error
  syntax++error
Re:CamelCase vs. Underscores: Revisited by kibwen on Wednesday January 25, 2023 @10:18PM (#34527320)
Make your language syntax require whitespace around arithmetic operators, and then we can finally live in a glorious paradise of kebab-case and `foo/bar` for namespaces.
Re:CamelCase vs. Underscores: Revisited by Gibbon1 on Thursday January 26, 2023 @04:20AM (#34529482)
My snarky suggestion is we switch to emoji's for arithmetic operators. Semi serious incorporate syntax highlighting via markup into the language.
Re:CamelCase vs. Underscores: Revisited by kaba0 on Thursday January 26, 2023 @04:47AM (#34529692)
I mean, not even a bad idea. I would honestly prefer operators to be more explicit like a-variableanother-varsomething-else. (EDIT: HN removed my emojis, but imagine a plus/minus emoji inbetween ids :( )

With a good font it would basically look similar to what a good IDE with syntax highlighting already does (different color for operators).

Re:CamelCase vs. Underscores: Revisited by Lio on Thursday January 26, 2023 @05:19AM (#34529919)
I think this would be a bad idea because emoji are hard to type.

This might be a bit old school but I prefer things limited to plain ASCII. There's only so many keys on a keyboard and want to be able to touch type everything without thinking or looking at a special emoji bar.

Re:CamelCase vs. Underscores: Revisited by kaba0 on Thursday January 26, 2023 @05:40AM (#34530066)
That I absolutely agree with, but I think it is about time we let go of “programs as plain text” axiom. With good tooling/IDE — which are already sort of visual editors only converting to and from to plain text on save — you could enter a ‘+’ and get autocomplete show the “emoji +” as an option for example. Because the actually important question to ask here in my opinion is “what is the easiest way to read/comprehend programs”, and we seem to have implicitly agreed that syntax highlighting is already a must (which works on even not yet valid program text!). Slightly more reliance on tooling doesn’t seem too bad to me.
Re:CamelCase vs. Underscores: Revisited by goerz on Thursday January 26, 2023 @07:12AM (#34530736)
With a proper keyboard layout, you can type a lot of unicode: https://michaelgoerz.net/notes/the-us-international-scientif...
Re:CamelCase vs. Underscores: Revisited by Joker_vD on Thursday January 26, 2023 @04:50AM (#34529712)
I actually have a toy language that uses emojis for keywords, allows me to reduce tokenizing to basically "split by whitespace, split into runs of characters of the same class (every character is its own class except for [A-Za-z0-9_-] which make up a single class), then post-process tokens for finer distinctions". Strings are somewhat more painful, but using \q instead of \" to escape the double quotes helps.
Re:CamelCase vs. Underscores: Revisited by inopinatus on Wednesday January 25, 2023 @06:47PM (#34525843)
I’ve always liked the readability, but interaction is a problem when many UIs treat the hyphen as a break character. Most (all?) browsers do, and even some (albeit not good) IDEs cannot be configured otherwise. When you’re in a hurry, it’s easy to miss a bit off the end.
Re:CamelCase vs. Underscores: Revisited by layer8 on Wednesday January 25, 2023 @11:16PM (#34527624)
Luckily Unicode has the non‑breaking hyphen U+2011. This‑is‑a‑long‑identifier‑that‑should‑not‑break‑at‑any‑of‑the‑hyphens.
Re:CamelCase vs. Underscores: Revisited by inopinatus on Friday January 27, 2023 @05:40PM (#34552840)
Alas, that doesn't seem to be a general solution. Sure, it doesn't break in my IDEs, nor does it linebreak in browsers, but it's still a selection break in everything except IDEs, it's harder to type, and it's harder to grep.
Re:CamelCase vs. Underscores: Revisited by infradig on Wednesday January 25, 2023 @07:16PM (#34526138)
I had never heard of kebab-case before as kebab refers to cooked chunks of meat.Soon it dawned that shish (meaning skewer) was meant, as in shish-kebab-case. Sorry to be that guy.
Re:CamelCase vs. Underscores: Revisited by bsder on Wednesday January 25, 2023 @07:18PM (#34526146)
Then we have to talk about the devil token which indicates variables/names.

You can't have infix minus and kebab case without something to differentiate between the two.

Lisp chooses to remove infix minus. Other than old-school BASIC, I don't remember anything else which uses tokens for variables.

Re:CamelCase vs. Underscores: Revisited by yakubin on Wednesday January 25, 2023 @08:30PM (#34526662)
> Lisp chooses to remove infix minus.

Infix has nothing to do with it. - refers to the subtraction function regardless of whether it is placed in prefix or infix position. Infix will trigger a type error, not a syntactic error — it will tell you that e.g. it cannot call a fixnum. Lisp quite ordinarily requires function names to be separated from their arguments by spaces, which is just a special case of the rule that atoms need to be separated by spaces. That’s all.

Re:CamelCase vs. Underscores: Revisited by lispm on Thursday January 26, 2023 @02:24AM (#34528708)
In many Lisps (+ + +) means this: call the function named + on the two values from the variables named +. The function is then a function object and the values of + can be anything they are currently set to.

Thus + serves more than one purpose: function or variable and both may be different values.

Thus the position actually matters.

What we have below the Lisp syntax are s-expressions: nested lists of symbols and other objects. In s-expressions, symbols need to be separated by whitespace, parentheses or possibly by some special character type (-> terminating character). Characters like +, -, /, *, _, ... are valid characters for any symbols.

Thus Lisp does not require functions to be separated by characters but symbols. That's a part of the reader mechanism for reading s-expressions (-> symbolic expression).

Re:CamelCase vs. Underscores: Revisited by yakubin on Thursday January 26, 2023 @04:27AM (#34529535)
Right, I was thinking about Lisp-1. Good call-out.
Re:CamelCase vs. Underscores: Revisited by gonzus on Thursday January 26, 2023 @05:49AM (#34530140)
... which is the one and only Lisp. Long live Scheme!