4 ms·
I think it's more about reducing cognitive load. I wouldn't want "+" to be used for anything that isn't adding, for example. Having to differentiate a-b from a
by Vt71fcAqt7 4y ago
I think it's more about reducing cognitive load. I wouldn't want "+" to be used for anything that isn't adding, for example. Having to differentiate a-b from a - b sounds tedious and error prone.
- reuben364 4y agoAt most it's an error of 'a-b' not in scope. Unless you have dynamic scoping or somehow have a variable 'a-b' and also want to perform 'a - b'. I think the rule that binary operators must be separated by spaces is much easier to reason about then not having certain characters usable in identifiers.
- afiori 4y agoThe only solution being polish notation for all operators
- Someone 4y agoThat’s not the only solution. You can also use different characters. In fact, kebab–case should not use minuses, but dashes, like this: kebab-case // three tokens: ‘kebab’ ‘minus’ ‘case’ kebab–case // single token ‘kebab n–dash case’ kebab—case // single token ‘kebab m–dash case’ ;-)
- acomjean 4y agoA great solution for messing with people. Much like the “smart quotes”
- tirpen 4y agoPeople usually don't mix up pointers in C (foo) with multiplication (foobar) nor divisions (foo / bar) with comments ( // ). So I don't really think people would have a problem with kebab case after getting used to it for a couple of minutes.
- int_19h 4y agoThere's precedent for this, though - 123.456 is lexed as one token in most languages, but foo.bar is three. It doesn't seem to be causing much issue in practice for readability because the context is sufficiently distinctive. Having / not having whitespace around the character would be even more distinctive, though, no? FWIW I did write a fair bit of XPath (in XSLT context) and XQuery back in the day, which do allow kebab-case identifiers and use them for standard library names other than types, while also using minus as a binary operator. I don't recall ever consciously thinking about how to differentiate the two uses, not even when still learning the ropes coming from C++ and C#; it "just worked". Of course, this is anecdotal - it would be interesting to poll people with prior experience with kebab-case languages that have also been exposed to other styles regarding their overall preference and this specific ambiguity.