Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

hyphen-case is worth the grammar concessions (like making whitespace between binary operators mandatory).


sPoNgEbOb-CaSe combined with hyphens is the only viable solution


kebab-case and SCREAMING-KEBAB-CASE are often found in urls too


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.


> Soo `a-b` and `a - b` are both potentially valid and different?

You shouldn't be able to start a name with a hyphen, so `a -b` and `a - b` can be both valid.

But I mostly just came to acknowledge your fitting username ;)


> 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.


> `-b` should be illegal

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`.


They’re only mutually exclusive as far as getting a good error message is concerned.


I don't really follow you. If `a = 1; b = 2; a-b = 3; foo = a-b; bar = a - b;` is legal then there would be no error message. Do you mean a warning?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: