1

It appears the Batarang plugin for Chrome has just updated. A new feature Angular Hint is added and gave me a bunch of warnings today. And there is an instruction that says:

Name controllers according to best practices (9551)

Controller names should start with an uppercase character and end with the suffix Controller. For example: UserController.

Consider renaming homeController to HomeController.

Haven't we Angular developers always use camel-cased names for JavaScript object? Anyone can tell us why Batarang prefers the pascal case instead?

And more questions:

  • Where can we find the documentation for the latest "best practices"?
  • If we don't want to follow this "best practice" for the existing web apps, how to turn of that type of "Hints"?
Blaise
  • 21,314
  • 28
  • 108
  • 169
  • 1
    Batarang can be turned off under `chrome://extensions/`. As I inspect scopes from the console anyway, indiscriminate hint spamming has rendered the extension useless to me. – semiomant Dec 11 '14 at 11:45
  • I now completely uninstalled it. – Golo Roden Dec 12 '14 at 16:24
  • I think Batarang updated again. And there is a checkbox to enable/disable Batarang now. We don't have to completely uninstall it. – Blaise Dec 12 '14 at 18:58

1 Answers1

4

Batarang suggests this, as controller functions are actually constructor functions, and constructor functions begin - by convention - with an uppercase character in JavaScript.

This is different from other artefacts, such as filters or services. They are written using a lowercase character, as they are not treated as constructors.

For controllers, it actually makes a lot of sense, as you may want to have multiple instances of a single controller within one single website.

In JavaScript, it's actually best practice to lowercase everything, except constructors: This way the developer knows when to use new with a function and when not to use it. The underlying problem is that technically there's no difference between a function and a constructor in JavaScript. Both are just functions, they just deal differently with the this keyword (and this is what new influences under the hoods).

For the "best practices" part… I'd go with the Angular documentation on how to define controllers. There it says that it's a constructor (although, to be true, it's quite hidden).

As for how to turn it off… no, I'm sorry, I don't know whether this is actually possible (and if so, I don't know how to). On the other hand, I would recommend to ask yourself if you really want to do it differently, if there IS a common best practice.

Golo Roden
  • 140,679
  • 96
  • 298
  • 425
  • Thanks, Golo. That does make sense. Do you know where to find the "best practice" documentation? and how can we temporarily disable `Angular Hint`? (My Chrome Console is now flooded with Angular Hint warnings. – Blaise Dec 10 '14 at 15:20
  • PS: The console of my Chrome is flooded too, and the new Batarang version broke some websites (including the menu of the official Angular website itself), so I disabled it. I've never used it a lot, anyway. – Golo Roden Dec 10 '14 at 15:24
  • Ugh. Batarang is killing my page, too. – Scott Dec 12 '14 at 15:34