Why are many languages case sensitive?

后端 未结 30 2085
执念已碎
执念已碎 2020-11-29 04:35

Why are many languages case sensitive?

Is it simply a matter of inheritance? C++ is case-sensitive because C is, Java is case-sensitive because C++ is, etc.? Or is t

30条回答
  •  余生分开走
    2020-11-29 05:09

    By typical coding standards, Person would be a class, person a variable name, and PERSON a constant. It's often useful to use the same word with different capitalization to mean something related but slightly different.

    So, if you had three staff members in your business all called Robert, you'd refer to them as Robert, robert and ROBERT would you? And rely on people to know exactly which one you meant?

    Give them email addresses such as Robert@widgets.com, robert@widgets.com, and ROBERT@widgets.com if your email system was case sensitive?

    The potential for an unauthorised breach of personal data would be huge. Not to mention if you sent the database root password to the disgruntled employee about to be sacked.

    Better to call them Bob, Robbie, and Robert. Better still to call them Robert A, Robert B and Robert C if their surnames were e.g. Arthur, Banks, and Clarke

    Really - why on earth have a naming convention that invites mistakes or confusion, that relies on people being very alert? Are you so short of words in your volcabulary?

    And as for the person who mentions the supposedly handy trick "MyClass myClass" - why, why why? You deliberately make it difficult to see at a glance whether a method used is a class method or an instance method.

    Plus you lost the chance to tell the next person reading your code more about the particular instance of the class.

    For instance.

    Customer PreviousCustomer

    Customer NewCustomer

    Customer CorporateCustomer

    Your instance name needs to ideally tell your colleague more than just the class it's based on!

提交回复
热议问题