恒滥用? [英] Constant abuse?

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

问题描述

我已经跨越了一堆代码,具有以下常量几个C#项目运行:

  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基础的,有手头一个更大的问题。

$ B。
$ b

这些常数的最常见的用法是在处理或内数据表关于'环



我是出来的地方思考这些是一个代码味道?我觉得这些都不好过了一大堆:

  const int的ZERO = 0; 
常量字符串A =A;


解决方案

滥用,恕我直言。 零只是是基础之一。



虽然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天全站免登陆