命名对象的标准是什么? [英] What is the standard for naming objects?

查看:69
本文介绍了命名对象的标准是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发了一篇关于命名字符串

构建器对象的标准。我担心的是我没有使用什么str前缀

,因为它用于字符串,但不知道在

的地方使用什么。我收到的一些回复表明这样的前缀在.Net中不需要更长时间,并且应该放弃。这是正确的

方法吗?我正在努力确保在我的

代码中使用最佳实践。


-Thanks

I did a recent post about what the standard was for naming a string
builder object. My concern was that I did not what to use "str" prefix
since this is used for strings but did not know what to use in its
place. A few responses I received indicated such prefixing is no
longer necessary in .Net and should be abandoned. Is this the correct
approach? I am striving hard to make sure I use best practices in my
code.

-Thanks

推荐答案

Rsine,


语言不需要它。但是没有人可以说你不应该使用它。


虽然我看到它很少用在这些新闻组中,但我说的不是/>
关于VB。


但是要尽量避免不必要的全局声明和

甚至尝试将字段声明为紧需要它们的地方。


但我只想到它。


Cor


< ; RS *** @ stationeryhouse.com> schreef在bericht

新闻:11 ********************** @ i40g2000cwc.googlegr oups.com ...
Rsine,

The languages don''t need it. But there is nobody who can say you should not
use it.

Although I see it seldom used in these newsgroups, where I am than talking
about VB.

However try than as well than to avoid not necessary global declarations and
even try to declare fields as tight as where they are needed.

But just my thought about it.

Cor

<rs***@stationeryhouse.com> schreef in bericht
news:11**********************@i40g2000cwc.googlegr oups.com...
我最近发布了一篇关于命名字符串
构建器对象的标准。我担心的是我没有使用什么str前缀
因为它用于字符串但不知道在其位置使用什么。我收到的一些回复表明.Net中的这种前缀不再需要,并且应该放弃。这是正确的方法吗?我正在努力确保在我的代码中使用最佳实践。

-Thanks
I did a recent post about what the standard was for naming a string
builder object. My concern was that I did not what to use "str" prefix
since this is used for strings but did not know what to use in its
place. A few responses I received indicated such prefixing is no
longer necessary in .Net and should be abandoned. Is this the correct
approach? I am striving hard to make sure I use best practices in my
code.

-Thanks



Hello < a href =mailto:rs *** @ stationeryhouse.com> rs *** @ stationeryhouse.com ,


我想出了一个我特别喜欢..随意使用,滥用,猛击,

讨厌,破坏和破坏它:


我主要使用VB,所以我的例子将在然而,对于几乎任何语言的修改都可以很好地工作

以允许语法。


首先,一些规则:

1.会员变量永远不会直接暴露,而是通过房产公布

公约:

首先,所有变量都具有描述性名称。当前缀

(见下文)不足以确定对象的类型(对象)时,那么

变量名称应该可以解决这个问题。

示例:一个对象,其中包含代表某人摔倒的日期

在沟里喝醉可能会被命名为:oDrunkInDitchDate


首先。 5:所有标识符将大写每个独立的第一个字母

构成标识符的单词。

示例:可以调用制作狗叫的方法:MakeDogBark( ),

或BarkTheDog()。

它不会是:makeDogBark(),makedogbark(),makedogBark()等。


第二:成员变量,以及godforbid,全局变量(vb varaibles

在模块中公开,YECH!)将以单个字符开头:

o - 以下未涵盖的对象

s - 字符串

b - boolean

i - 任何数值数据类型(来自Integer,但是一世 发现我没有

需要区分数字数据类型..所以我坚持作为前缀)


示例:将某人的年龄存储在一个byte:Dim iAge As Byte

存储一个标志来确定我们是否应该停止:Dim bStop As

Boolean

a组合框在WinForm上选择地毯的颜色:oCarpetColorCombo


第三:所有本地范围的变量(函数参数,在函数中声明的变量

等)都要加上前缀t。

t代表temerary。不需要在局部变量上键入数据

因为函数/属性/等通常很小,你可以通过简单地查看几个来引用

到数据类型线。一个人不应该尝试修改一个函数而不先阅读并完全理解它。

所以前缀中缺少数据类型对于维护程序员来说不是问题

要么。


差不多了。


-Boo
Hello rs***@stationeryhouse.com,

I''ve come up with one I particularly like.. feel free to use, abuse, bash,
hate, maim and mangle it:

I use VB primarily so my examples will be in that, however it seems to work
well for just about any language with minor modifications to allow for syntax.

First, a few rules:
1. Member variables will never be exposed directly, but rather they will
be exposed through properties.
Convention:
First and foremost all variables will have descriptive names. When the prefix
(see below) is not enough to determin an object''s type (object) then the
variable name should pick up the slack.
Example: an object that holds a date representing the day someone fell down
drunk in the ditch might be named: oDrunkInDitchDate

First.5: All identifiers will capitalize the first letter of each independant
word that makes up the identifier.
Example: A method for making the dog bark could be called: MakeDogBark(),
or BarkTheDog().
It would not be: makeDogBark(), makedogbark(), makedogBark(), etc.

Second: member variables, and, godforbid, global variables (vb varaibles
declared public in a module, YECH!) shall be prefaced with a single character:

o - objects which are not covered below
s - string
b - boolean
i - any numeric datatype (came from Integer, but I found that I do not
need to distinguish numeric data types.. so i stuck as the prefix)

Examples: storing someone''s age in a byte: Dim iAge As Byte
storing a flag to determin if we should stop something: Dim bStop As
Boolean
a combobox on a WinForm for selecting a color of carpet: oCarpetColorCombo

Third: all locally scoped variables (function arguments, variables declared
within a function, etc) are to be prefixed with t.
t stands for temerary. There is no need for data typing on local variables
because functions/properties/etc are usually small enough that you can refer
to the data type by simply looking up a few lines. One should never try
to modify a function without first reading and understanding it in its entirety
so the lack of data type in the prefix is not a problem for maintenance programmers
either.

Thats pretty much it.

-Boo
我最近发布了一篇关于命名字符串
构建器对象的标准的帖子。我担心的是我没有使用什么str
前缀,因为它用于字符串但不知道在
中使用什么。我收到的一些回复表明.Net中的这种前缀不再需要,并且应该放弃。这是正确的方法吗?我正在努力确保在我的代码中使用最佳实践。

-Thanks
I did a recent post about what the standard was for naming a string
builder object. My concern was that I did not what to use "str"
prefix since this is used for strings but did not know what to use in
its place. A few responses I received indicated such prefixing is no
longer necessary in .Net and should be abandoned. Is this the correct
approach? I am striving hard to make sure I use best practices in my
code.

-Thanks



您好, rsine,


我同意Cor。我找到了三个字母类型前缀约定

在我之前使用过的语言中非常有用,但是在.Net和任何大型项目中都没有很多优势。 >
太多类型都无法记住所有类型的前缀。

在.Net中,大多数本地名称的范围非常狭窄,而IDE

提供有关它们的非常好的信息。但是我仍然倾向于使用一些约定来表示更广泛的范围名称(例如私人类

变量和偶尔的全局变量)但到目前为止我还没有确定

应该是什么。


干杯,

兰迪

Cor Ligthert [MVP]写道:
Hello, rsine,

I agree with Cor. I have found three letter "type prefix" conventions
to be very useful in languages I have used previously, but there is not
much advantage to these in .Net and in any sizable project there are far
too many types to be able to remember the prefixes for all of them.

In .Net the scope of most local names is very narrow, and the IDE
provides very good information about them. But I''m still inclined to
use some convention to denote wider scope names (e.g. private class
variables and the occasional global) but so far I haven''t determined
what it should be.

Cheers,
Randy
Cor Ligthert [MVP] wrote:
Rsine,

语言不需要它。但是没有人可以说你不应该使用它。

虽然我看到它在这些新闻组中很少使用,但我在谈论关于VB的事情。

然而,请尽量避免不必要的全局声明,甚至尝试将字段声明为需要的地方。

但只是我的想法。

Cor

< rs *** @ stationeryhouse.com> schreef in bericht
新闻:11 ********************** @ i40g2000cwc.googlegr oups.com ......
Rsine,

The languages don''t need it. But there is nobody who can say you should not
use it.

Although I see it seldom used in these newsgroups, where I am than talking
about VB.

However try than as well than to avoid not necessary global declarations and
even try to declare fields as tight as where they are needed.

But just my thought about it.

Cor

<rs***@stationeryhouse.com> schreef in bericht
news:11**********************@i40g2000cwc.googlegr oups.com...
我最近发布了一篇关于命名字符串
构建器对象的标准。我担心的是我没有使用什么str前缀
因为它用于字符串但不知道在其位置使用什么。我收到的一些回复表明.Net中的这种前缀不再需要,并且应该放弃。这是正确的方法吗?我正在努力确保使用我的
代码中的最佳实践。

-Thanks
I did a recent post about what the standard was for naming a string
builder object. My concern was that I did not what to use "str" prefix
since this is used for strings but did not know what to use in its
place. A few responses I received indicated such prefixing is no
longer necessary in .Net and should be abandoned. Is this the correct
approach? I am striving hard to make sure I use best practices in my
code.

-Thanks




这篇关于命名对象的标准是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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