Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

We are having an argument, where it has been proposed (among other things) to change requirejs statements like this:

define(['thing', 'xyzzyView', 'backbone'],
function(thing, XyzzyView, backbone) {
...
thing.doStuff();
...
var xyzzyView = new XyzzyView();
...
var myView = new backbone.View(...);
});

to this:

define(['thing', 'xyzzyView', 'backbone'],
function(Thing, XyzzyView, Backbone) {
...
Thing.doStuff();
...
var xyzzyView = new XyzzyView();
...
var myView = new Backbone.View(...);
});

The argument is that you see by the capitalization that something has been imported with requirejs.

I am against the change, as I see capital first letter as something that identifies a constructor function specifically, which I feel is more important to recognise than something that has been imported. I feel that this follows Crockford's line here:

... Most variables and functions should start with a lower case letter.

Constructor functions that must be used with the new prefix should start with a capital letter. JavaScript issues neither a compile-time warning nor a run-time warning if a required new is omitted. Bad things can happen if new is not used, so the capitalization convention is the only defense we have. ...

It can be argued that the backbone variable should have an uppercase first letter, since this occurs in many (most?) examples you find on the net, including backbone's own code. But I feel that this is just poor coding on Backbone's part.

Am I wrong? Is there some third option that might be better here?

share|improve this question

closed as primarily opinion-based by amon, GlenH7, MichaelT, durron597, Snowman Aug 27 at 14:25

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

3  
(1) Unlike many languages, JS does not have a concept of a module system or a module hierarchy. (2) Most languages with a module hierarchy tend to lowercase module names, e.g. Java or Python: reserve CamelCase for classes. (3) Some languages with a module hierarchy tend to CamelCase package names just like class names, e.g. Perl or Haskell: distinguish modules from variables and functions. (∴) There's no clear precedent, and either reason makes a lot of sense as long as you stay consistent. While I have a clear personal preference, this question is entirely opinion-based. –  amon Aug 27 at 12:08

Browse other questions tagged or ask your own question.