What's the advantage of case sensitive languages over case insensitive ones? [closed]

隐身守侯 提交于 2019-12-10 23:40:00

问题


I have been doing a number of projects in Delphi, which uses the case insensitive language Pascal, and I was wondering what the advantage of case sensitive languages is.
Jason argues that "Case insensitivity introduces much ambiguity". I don't agree. If you realize that the language is case insensitive you know that WHILE means the same thing as while, even if you never write the former. Same for variables and functions; camel casing is nice, but was the first letter also a capital or not? And what about functions whose name starts with an underscore? In case insensitive languages no problem: _fooBar will do just as nicely as _FooBar. So where's the ambiguity Jason refers to? Yes, you can write a variable in different ways, but the meaning is unambiguous! FooBar == foobar!

In the same thread Delnan says that Capitalization is the difference between "I had to help my uncle Jack off a horse.." and "I had to help my uncle jack off a horse..". Very clever :-). But rather a point against than pro case sensitivity: would you accept that your code goes haywire because of a single capitalization error? Again, in a case insensitive language, if Jack is a person, so is jack.

Question: is there anyone who uses this feature in case sensitive languages that you can define two different variables or functions just by different capitalization? Because that's the only advantage I can see in it. Sure, you'll say, I write the variable name with camel casing and the constant all uppercase. But IMO they're incompatible; userName as a variable makes sense, but USERNAME as a constant doesn't.

(I realize that many programmers use case sensitive languages, so I'm prepared for a unwelcome reception :-))

edit
The trigger for this question was Lynda.com's "ActionScript 3.0 in Flash CS3 Professional" training video, in which Todd Perkins spends half of his time emphasizing the capitalizations :-)


回答1:


Yes, I absolutely use this all the time in C#:

private readonly string name;
public string Name { get { return name; } }

I've tended to use case-sensitive languages, and haven't really seen downsides of them - aside from anything else, they force consistency of casing.

It's really a personal preference thing though, I think.




回答2:


I personally like neat and tidy code. If your language is not case sensitive it has the potential to be come messy if everyone doesn't stick to the rules.

private String myName = "Shawn";

  if(myname.equals("Shawn"){
    MYNAME = myname + "Vader";
  }

  System.out.println("His name is " + MyName);

Even in a case sensitive language we spend a lot of time making sure that everything is consistent, like running analysis tools to enforce naming conventions of fields and formatting rules and final method parameters.

So for me it's a question of conformity.



来源:https://stackoverflow.com/questions/3942489/whats-the-advantage-of-case-sensitive-languages-over-case-insensitive-ones

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!