区分大小写的语言相对于不区分大小写的语言有什么优势?

发布于 2024-09-27 18:45:55 字数 1205 浏览 9 评论 0原文

我一直在Delphi中做一些项目,它使用不区分大小写的语言Pascal,我想知道区分大小写的语言的优点是什么。
Jason 认为“不区分大小写会带来很多歧义”。我不同意。如果您意识到该语言不区分大小写,您就会知道 WHILEwhile 含义相同,即使您从未编写过前者。变量和函数相同;驼色大小写很好,但是第一个字母也是大写吗?那么名称以下划线开头的函数又如何呢?对于不敏感的语言没有问题:_fooBar 将与 _FooBar 一样好。那么杰森所说的歧义在哪里呢?是的,您可以用不同的方式编写变量,但含义是明确的! FooBar == foobar

在同一线程中,Delnan 大小写是“I had to help my Uncle Jack off a horse..”和“I had to help my Uncle Jack off a horse..”之间的区别。非常聪明:-)。但反对而不是赞成区分大小写:你会接受你的代码因为一个大写错误而变得混乱吗?同样,在不区分大小写的语言中,如果 Jack 是一个人,那么 jack 也是一个人。

问题:是否有人在区分大小写的语言中使用此功能,您可以仅通过不同的大小写来定义两个不同的变量或函数?因为这是我能看到的唯一优点。当然,你会说,我用驼峰式大小写写变量名,而常量全部大写。但在我看来,它们是不兼容的; userName 作为变量有意义,但 USERNAME 作为常量则没有意义。

(我意识到许多程序员都使用区分大小写的语言,因此我准备好接受不受欢迎的接待:-))

编辑
引发这个问题的是 Lynda.com 的“Flash CS3 Professional 中的 ActionScript 3.0”培训视频,其中 Todd Perkins 花了一半的时间强调大写:-)

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 :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以为你会在 2024-10-04 18:45:55

是的,我绝对一直在 C# 中使用这个:

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

我倾向于使用区分大小写的语言,并且还没有真正看到它们的缺点 - 除了其他任何东西之外,它们强制 套管的一致性。

我认为这确实是个人喜好问题。

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.

睫毛上残留的泪 2024-10-04 18:45:55

我个人喜欢整洁的代码。如果您的语言不区分大小写,那么如果每个人都不遵守规则,则可能会变得混乱。

private String myName = "Shawn";

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

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

即使在区分大小写的语言中,我们也会花费大量时间来确保一切都一致,例如运行分析工具来强制字段的命名约定以及格式化规则和最终方法参数。

所以对我来说这是一个一致性问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文