持续滥用? [英] Constant abuse?

查看:115
本文介绍了持续滥用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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屋!

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