monterail / guidelines

[DEPRECATED] We are Ruby on Rails experts from Poland. Think hussars. Solid & winged. These are our guidelines.
71 stars 17 forks source link

Javascript naming #193

Closed chytreg closed 10 years ago

chytreg commented 10 years ago

How do you deal with the naming in CoffeeScript? Do you use underscore as in Rails or camelCase as the Javascript prefer?

I tried to use in my latest Angular app to use JS convention and have some naming mismatch. Example

    $scope.accountGroups = []

    SharedWith.fetch().then (response) ->
      $scope.sharedWith = response.data
     # but in reponse data I get the Array and each object has account_group method :(

Maybe variable write using underscore convention but functions in camelcase

So I would have

$scope.my_nasty_var = 'Some secret text'

$scope.myAwesomeFunction = (no_camel_case) ->
  console.log 'Fuuuuuu'
jandudulski commented 10 years ago

Using underscore for methods would mix with camelCased methods in e.g. angular (like isObject), so it's quite ease choice for me here.

For variables it is harder. My inclination is to use camelCase (as in ruby we use underscores both in methods and variables), but I wouldn't die defending this proposal :)

sheerun commented 10 years ago

Fine for me. It's easier to distinguish variables from functions.

teamon commented 10 years ago

How about https://github.com/apotonick/roar/issues/57 ?

sheerun commented 10 years ago

No one sane uses camel case in JSON.

JavaScript community is insane imho.

On Sun, Feb 16, 2014 at 3:53 PM, Tymon Tobolski notifications@github.comwrote:

How about apotonick/roar#57 https://github.com/apotonick/roar/issues/57?

— Reply to this email directly or view it on GitHubhttps://github.com/monterail/guidelines/issues/193#issuecomment-35198539 .

sheerun commented 10 years ago

The only thing I'm afraid some other libraries use camel case for variables so it would be inconsistent.

On Sun, Feb 16, 2014 at 3:55 PM, Adam Stankiewicz sheerun@sher.pl wrote:

No one sane uses camel case in JSON.

JavaScript community is insane imho.

On Sun, Feb 16, 2014 at 3:53 PM, Tymon Tobolski notifications@github.comwrote:

How about apotonick/roar#57 https://github.com/apotonick/roar/issues/57?

— Reply to this email directly or view it on GitHubhttps://github.com/monterail/guidelines/issues/193#issuecomment-35198539 .

teamon commented 10 years ago

Just one random example - https://github.com/brianreavis/selectize.js/blob/master/docs/usage.md everything is camelCased. The biggest issue I can see in returning camelCased fields from API is that often those same fields are used for updates so they would need to be converted back and forth to make rails happy. Personally I would leave it as is - write js in camelCase and treat under_scored properties as a hint that they are part of the JSON API

teamon commented 10 years ago

@Ostrzy @thion @szajbus ?

szajbus commented 10 years ago

I like the idea.

Camel case for all JS, except for JSON API.

I just reviewed some of the JS code I have written lately and it more or less following this conventions.

sheerun commented 10 years ago

JSON API should be rather wrapped in service anyway, so maybe it's good idea

On Sun, Feb 23, 2014 at 11:33 PM, Michał Szajbe notifications@github.comwrote:

I like the idea.

Camel case for all JS, except for JSON API.

I just reviewed some of the JS code I have written lately and it more or less following this conventions.

— Reply to this email directly or view it on GitHubhttps://github.com/monterail/guidelines/issues/193#issuecomment-35846310 .

teamon commented 10 years ago

PR?

jcieslar commented 10 years ago

I like idea: variables -> underscore, methods -> camelcase

hodak commented 10 years ago

I like idea: variables -> underscore, methods -> camelcase :+1:

venticco commented 10 years ago

Two naming conventions for better consistency? Seriously? I think in JS everything should go camelCase.

sheerun commented 10 years ago

:-1: For underscore variable names. Only JSON is underscore.

teamon commented 10 years ago

I stand with "Personally I would leave it as is - write js in camelCase and treat under_scored properties as a hint that they are part of the JSON API"

nicieja commented 10 years ago

I would go with camelCase.

Ostrzy commented 10 years ago

I like idea: variables -> underscore, methods -> camelcase

:+1: Easy to remember, consistency with all things we get form api and send to api. I won't fight for this much, but I give :-1: for other concepts presented here.

tommy92 commented 10 years ago

+1 for using only camel case convention

teamon commented 10 years ago

Any more comments? If not I'm going to close this with "camelCase for everything, except JSON" at the end of this week.

/cc @monterail/dev