Why are many languages case sensitive?

后端 未结 30 1694
执念已碎
执念已碎 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 04:46

    How do you yell if you don't HAVE CAPS?! AHHH!

    You have to be expressive. But in all honesty, of all the people in the world, those who work with programming logic would be the first to insist that differences are in fact differences.

    0 讨论(0)
  • 2020-11-29 04:47

    Every example I've seen supporting case sensitivity is based on a desire to write bad, undescriptive code. e.g. the "date" vs. "myDate" argument - these are both equally undescriptive and bad practice. Good practice is to name it what it actually is: birthDate, hireDate, invoiceDate, whatever. And who in their right mind would want to write code like:

    Public Class Person
        Public Shared ReadOnly PERSON As Person
    End Class
    Public Class Employee
        Public person As Person = person.PERSON
    End Class
    

    Amazingly this is perfectly valid case insensitive VB.Net code. The thought that case sensitivity allows you to even more flagrantly disobey good programming practice is an argument against it, not for it.

    0 讨论(0)
  • 2020-11-29 04:48

    Because they're as dumb as a box of frogs, for precisely the reasons given for the opposite viewpoint in this thread (I'm not even gonna ask what that's about. Wood for the trees and all that).

    When FOOBAR = FooBar = foobar, you get to choose your convention, and other coders can do the same whether they share your preference or not. No confusion.

    They also can't get away with the stroke of genius that is having a constant, function and variable all with the same name in the same file, albeit with different caps. Again, no confusion.

    You call your variable WebSite, they call theirs Website, and which system gets confused? Not an easy catch either, when you're scanning.

    As for lookups, is it really that much more processing to convert the name to lowercase before looking it up? Doing your own premature optimisation is one thing, expecting it from the developer of your language of choice is a whole other level of missing the point.

    ...and yet, all these answers saying case-sensitivity reduces confusion. Sigh

    0 讨论(0)
  • 2020-11-29 04:48

    I think having a case-sensitive language ENCOURAGES people to write poor code.

    Const SHOESIZE = 9
    
    Class ShoeSize
    
    ShoeSize.shoesize = SHOESIZE
    
    call shoeSize(ShoeSize);
    
    function shoeSize(SHOEsize)
    {
       int ShoeSIZE = 10
       return ShoeSize
    }
    

    Duh. You couldn't think of a better variable name than "ShoeSize" for the different purposes? There is a billion different words you could use, but you choose to just keep using ShoeSize instead?

    0 讨论(0)
  • 2020-11-29 04:48

    If word separation is not important then why do we put spaces between words? Therefore I think that underlines between words in a name do increase readability. Also lower case with Capitalization of appropriate characters is easiest to read. Lastly, it is surely much easier if all words can be conveyed by word of mouth - "Corporate Underscore Customer" rather than "Capital C Lower Case o r p o r a t e Underscore Capital C Lower Case u s t o m e r"! - the former can be spoken 'in one's head' the latter cannot - I wonder how people who are happy with case sensitivity handle these case sensitive names in their brains - I really struggle. So I feel that case sensitivity is not at all helpfull - a retrogade step from COBOL in my opinion.

    0 讨论(0)
  • 2020-11-29 04:49

    There is another reason languages are case sensitive. IDs may be stored in a hash table and hash tables are dependent on hashing functions that will give different hashes for differing case. And it may not be convenient to convert all the IDs to all upper or all lower before running them through the hash function. I came across this issue when I was writing my own compiler. It was much simpler (lazier) to declare my language as case sensitive.

    0 讨论(0)
提交回复
热议问题