我使用一个不同于其类型的变量名称是不道德的吗? [英] Am I immoral for using a variable name that differs from its type only by case?

查看:144
本文介绍了我使用一个不同于其类型的变量名称是不道德的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,取这段代码:

var person = new Person();

或您的Pythonistas:

or for you Pythonistas:

person = Person()

是,但还没有看到这两行代码的不道德的例子。对我来说,人是一个人,试图给它另一个名字是浪费时间。我想在语法突出的前几天,这将是一个很大的交易。但是现在,除了变量名之外,很容易区分类型名。 Heck,它甚至很容易看到在这里的差异。

I'm told constantly how bad this is, but have yet to see an example of the immorality of these two lines of code. To me, person is a Person and trying to give it another name is a waste of time. I suppose in the days before syntax highlighting, this would have been a big deal. But these days, it's pretty easy to tell a type name apart from a variable name. Heck, it's even easy to see the difference here on SO.

还是有一些我缺少?

推荐答案

我使用它所有的时间用于临时对象引用。我会避免它像原始数据类型的瘟疫。

I use it all the time for temporary object references. I would avoid it like the plague for primitive data types.

Person person = new Person(); // okay

int Int = 42; // pure evil

这篇关于我使用一个不同于其类型的变量名称是不道德的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆