持续滥用? [英] Constant abuse?
问题描述
const int ZERO_RECORDS = 0;
const int FIRST_ROW = 0;
const int DEFAULT_INDEX = 0;
const int STRINGS_ARE_EQUAL = 0;
有没有人见过这样的东西?有没有办法合理化使用常量来表示语言结构? IE:C#在数组中的第一个索引在位置0.我认为如果开发人员需要依赖一个常量来告诉他们语言是基于0,那么就会有一个更大的问题。
这些常量的最常见用法是处理数据表或在for循环中。
是代码气味?我觉得这些不是一个好多了:
const int ZERO = 0;
const string A =A;
滥用,IMHO。
虽然STRINGS_ARE_EQUAL可能很容易,但为什么不是.Equals?
I have run across a bunch of code in a few C# projects that have the following constants:
const int ZERO_RECORDS = 0;
const int FIRST_ROW = 0;
const int DEFAULT_INDEX = 0;
const int STRINGS_ARE_EQUAL = 0;
Has anyone ever seen anything like this? Is there any way to rationalize using constants to represent language constructs? IE: C#'s first index in an array is at position 0. I would think that if a developer needs to depend on a constant to tell them that the language is 0 based, there is a bigger issue at hand.
The most common usage of these constants is in handling Data Tables or within 'for' loops.
Am I out of place thinking these are a code smell? I feel that these aren't a whole lot better than:
const int ZERO = 0;
const string A = "A";
Abuse, IMHO. "Zero" is just is one of the basics.
Although the STRINGS_ARE_EQUAL could be easy, why not ".Equals"?
Accepted limited use of magic numbers?
这篇关于持续滥用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!