JavaScript Style
ozmm.org
ozmm.org
Can anyone point out advantages of underscored_names that I may be missing?
One can also make the argument that code is read more often than written.
Code gets read more than once. If it makes code easier to read, I'll do it, even if it takes me a tiny bit longer to write that extra character.
Should the json keys be camelCased or underscore_cased? It's a bit ambigious.
doc.set({related_article : 'http://...'});
Even though you might have: doc.openRelatedArticle();
As a method on the JS model. Definitely less than ideal.except if you're trying to subtract:
c = a-b
which is why languages with arithmetic don't allow '-' in variable names. (Then function/method names get the same rule. KISS.)But often times it is used exclusively (or in majority) on the server-side. If the server side language follows the underscore_case convention. That's where the ambiguity creeps in.
Basically, I try to follow the conventions of whatever language I'm working in because that just makes it easier for people working in that language to incorporate your lib.
And yes, lowerCamel seems to be the default for JS.
For a JSON wire protocol it's different, because it's not a language specific API that you're exposing, it's a protocol, which is a different beast.
For text-based wire-protocols I prefer to 'ignore' case (because of ambiguity) by sticking with lowercase all the way. Names need separators and the underscore works nicely for that everywhere.
Keys I use for sending over the wire therefore follow the Ruby style.
o["foo bar"]
You know, actual spaces? Spaces don't make for valid variable/method identifiers in most languages, yes, but it's not like keys you received from the network should be leaking into your identifier namespace anyway—that's how MITM attacks start.