Yeah no thanks. Soo `a-b` and `a - b` are both potentially valid and different?
Also allowing hyphens generally leads to issues when interoperating with other languages that don't support hyphens. Probably the best example of this is CSS which does allow hyphens, and Javascript which doesn't. `background-color` in CSS gets translated to `backgroundColor` in JS.
It's an annoying paper cut that trips up beginners and makes code less greppable. I generally avoid hyphens wherever possible for that reason.
> Yeah no thanks. Soo `a-b` and `a - b` are both potentially valid and different?
Like what the sibling comment said: `-b` should be illegal. And I don’t think this would be a big deal in practice for experienced users (used to these rules).
For beginners you could build in an error check: give a dedicated error message if you write `a-b` but you happen to have both variables `a` and `b`. Then the compiler can tell that you probably meant `a - b`.
> Also allowing hyphens generally leads to issues when interoperating with other languages that don't support hyphens.
Make underscore illegal in the language. It’s not like you need them anymore. In turn you have a bidirectional translator.
Sure... but I didn't use `-b`. Maybe I've misunderstood.
> give a dedicated error message if you write `a-b` but you happen to have both variables `a` and `b`
I guess, though the idea of having mutually exclusive sets of identifiers sounds like a nightmare. You can have `a` and `a-b`, or `a` and `b`, but not `a`, `b` and `a-b`... Maybe it wouldn't come up much in practice but it's still a pretty big WTF.
> In turn you have a bidirectional translator.
But the problem is that you have this translation in the first place. It makes the identifier ungreppable. Ideally any place you have an identifier it looks exactly the same through your whole codebase and if you have to translate it then that is no longer true. For example if you want to update all background colours in your project you might search for `background-color`... but miss `backgroundColor`.