您如何命名变量对应用程序的内存使用量有影响吗? [英] Does how you name a variable have any impact on the memory usage of an application?

查看:102
本文介绍了您如何命名变量对应用程序的内存使用量有影响吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

声明一个变量名,其名称的长度对应用程序的总内存有多少影响(如果有的话)?反正有最大长度吗?还是我们可以根据需要自由地详细说明变量(和实例)?

Declaring a variable name, how much (if at all) impact does the length of its name have to the total memory of the application? Is there a maximum length anyway? Or are we free to elaborate on our variables (and instances) as much as we want?

推荐答案

实际上取决于语言.

如果您使用的是C ++或C,则不会产生任何影响.

If you're using C++ or C, it has no impact.

如果您使用的是解释语言,那么您正在传递源代码,因此可能会产生巨大的影响.

If you're using an interpreted language, you're passing the source code around, so it can have a dramatic impact.

如果您使用的是编译为中间语言(例如Java或任何.NET语言)的编译语言,则通常,变量名,类名,方法名等都属于IL.方法名称较长会产生影响.但是,如果您以后通过混淆器运行,这将消失,因为混淆器会将所有内容重命名为(通常)非常短的名称.这就是为什么混淆常常会对性能产生影响的原因.

If you're using a compiled language that compiles to an intermediate language, such as Java or any of the .NET languages, then typically the variable names, class names, method names, etc are all part of the IL. Having longer method names will have an impact. However, if you later run through an obfuscator, this goes away, since the obfuscator will rename everything to (typically) very short names. This is why obfuscation often gives performance impacts.

但是,我强烈建议使用描述性长的变量/方法/类名.从长远来看,这使您的代码易于理解,可维护和易读-远胜于任何细微的表现.好处.

However, I will strongly suggest using long, descriptive variable/method/class names. This makes your code understandable, maintainable, and readable - in the long run, that far outweighs any slight perf. benefit.

这篇关于您如何命名变量对应用程序的内存使用量有影响吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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