Sitecore-Community / Sitecore.Speak.Guidance

Living SPEAK guideline used internally to share same structure and code style. It is work in progress and you are welcomed to pull request it.
http://sitecore-community.github.io/Sitecore.Speak.Guidance
12 stars 8 forks source link

Names of JavaScript files #11

Open ivan-korshun opened 9 years ago

ivan-korshun commented 9 years ago

The following is written in JavaScript.md:

  • Use camelCase when naming functions and variables

Maybe we should add a rule for names of JavaScript files.

dervalp commented 9 years ago

Could you elaborate on that? What rules would you add on naming convention?

ivan-korshun commented 9 years ago

UploadMedia dialog has the "UploadMediaDialog.js" page code file. So we should use PascalCase when naming JS page code files.

If duplicated code had been extracted from serveral page codes into a separate JS file, then this file should also use PascalCase naming.

However SPEAK components use internal JS modules that use camelCase naming. For example, "userProfile.js".

dervalp commented 9 years ago

Shouldn't we use the same casing for ALL the JavaScript files?

ivan-korshun commented 9 years ago

Yes, we should. But some of third party JS files use lowercase naming (bootstrap.js, fusioncharts.js). The others use "-" or "." as a separator (jquery.ui.js, jquery-ui.js). SPEAK core JS uses camelCase naming (sitecore-1.0.2.js).

kerrybellerose commented 9 years ago

I don't think we need to worry about 3rd party JS files (they are out of our control).

I'm not hearing a definite decision about this. What are the implications if we decide that all Sitecore provided file names follow the same casing rules, and this means that we need to change the name of some existing files?

dervalp commented 9 years ago

URL are case insensitive so renaming should not be a problem (but for sure, their could be exception with some handlers). but anyway we should not start to rename all the files that we have.

We should just make sure that from now on, all new files follow the same rule.

MartinSvarrer commented 9 years ago

Requirejs is case sensitive when requiring.

kerrybellerose commented 9 years ago

OK, so perhaps we could add a bullet saying:

ivan-korshun commented 9 years ago

I like the lower.case.with.point.separator.js naming.

dervalp commented 9 years ago

Do not think it is a good idea. You end up with people arguing about where to put the ".". Moreover a "." suffix generally expresses the file type or sub type.

Also, it could break some code (I hope not but let's be defensive) with people doing something like:

name.split(".")[1]

to get the file type.

ivan-korshun commented 9 years ago

I am voting for camelCase, then.

kerrybellerose commented 9 years ago

Thanks for that discussion, shall I add the following bullet then?

ivan-korshun commented 9 years ago

Yes, please. Pierre agrees with it.

kerrybellerose commented 9 years ago

Done.

MaxReimerNielsen commented 9 years ago

Damn I missed this discussion, but I am still not sure why this approach has been chosen.

The normal approach in the .NET world is to create files in PascalCasing. And since this is for PageCode only, then I think it is a wrong choice to go camelCasing, since it will mainly be "SPEAK customers" who will use this guideline.

Now if we also apply this to our components, then I also think it is wrong, since all the other files in the SPEAK project (.cshtml, .cs, .less etc.) are also in PascalCasing.

So I still think it is hard to understand why we should use camelCasing, since Sitecore general usually using PascalCasing.

MartinSvarrer commented 9 years ago

Everything else that we have in the project is currently in PascalCasing, I see no reason to change that.