The case of capitalization and my in variables


#1

So along with doing codecademy lessons online I am learning code from my boss at work. He is what some would call "old style coding" back in the days when chat rooms online were popular. An interesting question came up when discussing capitalization in variables. Is the capitalization just a new style or is it necessary for the code to function properly? Also, does the my in the examples below do anything (just there for looks) or does it play a part. The question mostly came out of examples like these below.


var = myDude var = mydude var = MyDude var = MYDUDE


#2

It is just a "coding style," but it has been adopted wildly enough to be a coding standard.

  • When someone else is reviewing your code, they expect variables that start with a lowercase to be, well, variables.
  • When something is started with an uppercase, that is typically expected to be a class.
  • When something is all uppercase, that is typically expected to be a constant.
    etc.

For more details on coding standards, visit the official website for your language of choice.

Here's the one for naming convention in Python:
https://www.python.org/dev/peps/pep-0008/#naming-conventions

Here's one from Mozilla Developer Network:
https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Coding_Style

As far as the "my" in your examples, what that does is ensure you don't accidentally use a reserved keyword (which would affect the functionality of your code) when trying to be descriptive about naming your variables. Example: the word new is reserved, so you may want to declare your variable var newentry or var newEntry instead of var new.


#3

Thank you very much! Well explained. I would like that Javascript link too if you still got it


#4

Since Mozilla covers a range of language standards within that page besides JavaScript, I decided to correct the statement listed. They are still a good source for JavaScript, since they did create JavaScript vanilla back in the days of Netscape.

There is another JavaScript standardization body called ECMA that you can visit the specification for:
http://www.ecma-international.org/ecma-262/5.1/

ECMAScript (or ES)[1] is a trademarked[2] scripting-language specification standardized by Ecma International in ECMA-262 and ISO/IEC 16262. It was based on JavaScript, which now tracks ECMAScript. It is commonly used for client-side scripting on the World Wide Web. Other implementations of ECMAScript include JScript and ActionScript.


#5

Yeah I saw that after i asked the question. These will be very nice resources. But yeah thanks for that links!


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.