3 ms·
While I find snake_case more readable when looking at the identifier alone, it has the downside that _ is mostly whitespace with the glyph at the bottom of the
by int_19h 4y ago
While I find snake_case more readable when looking at the identifier alone, it has the downside that _ is mostly whitespace with the glyph at the bottom of the character cell, and so it visually groups more with punctuation like "." than with letters. Which wouldn't be so bad if "." wasn't so common in property / method call chains, so you end up with stuff like:
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()
- layer8 4y agoAlso, when using a proportional font it gets worse, because underscores become wider (significantly wider than a normal space) and dots become narrower, suggesting the wrong grouping in syntax like `foo.bar_baz.blah()` (the words in "foo.bar" are closer together than in "bar_baz"), or just when having a snake_case_identifier in normal text ("a snake" is close together than "snake_case", etc.). This problem is less pronounced with kebab-case. Underscores can also clash with hyperlink underlines, depending on the font. I've seen documentation with linked identifiers where that was confusing.
- kelnos 4y agokebab-case is fine in strings, but many languages will parse that as BinaryExpression(Identifier("kebab"), Identifier("case"), Operator.MINUS) I admit there's personal preference and just quirks of vision involved, but I don't think I've ever had an issue distinguishing '_' and '.'. One thing you can do, which helps also with breaking up long chains of calls that would give you a really long line, is break it up with newlines, e.g.: foo .bar_baz .blah()
- int_19h 4y agoI believe that syntactic limitation to be a historical mistake that we keep doubling down on for no good reason. There's really no practical purpose to parse a-b as (a - b), as evidenced by popular style conventions for pretty much ever language with a binary minus operator.
- Vt71fcAqt7 4y agoI 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 ago
- citrin_ru 4y agoLua uses : for a method call and IMHO it is easier to read than with a dot.
- rollcat 4y agoI think it's the most underrated "wart" of Lua. It's not strictly speaking a method call operator; it's a shorthand used to provide the LHS object (a table) as the first argument in a function call (where the function is looked up from that table). So if you've implemented some form of inheritance (usually via metatables), you can trivially up/down-cast by using the dot notation and specifying the desired class/prototype for the method, and some instance/object as the first argument. (Speaking of up/down-casting, classes, and instances in Lua is a bit awkward. I have a very quick & dirty "class.lua" file that I copy&paste between projects, I wish something like that was just a part of the stdlib.)
- camgunz 4y agoYeah will +1 this. If you mess it up it's pretty hard to find where you did it. ':' is very close to '.'.
- ripe 4y agoThis is a really good point. Not sure if the study included this case. Yes, I do like kebab-case. Common Lisp!