几个问题的风格 [英] A couple questions of style

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

问题描述

我总是对这些风格问题感到好奇,如果看起来实际上是以某种方式做事的客观原因,那么这里就是

a更轻松的讨论。


1)默认构造函数。你总是为每个

类写一个构造函数,即使它没有做任何特殊的事情,或者你是否信任

默认生成一个?


2)区域。我非常喜欢区域功能,用于组织代码

并降低IDE中的噪音。我已经看到了很多代码,其中人们将所有私有类变量放在同一个顶级的

在他们自己的区域。最近我看到了代码,它们分散在实际使用它们的各个地区 - 例如,在相应的

属性代码附近。后者对某些人来说似乎更有用

喜欢我喜欢地区的人。

解决方案

嗨Daniel,

1)默认构造函数。你总是为每个
课写一个构造函数,即使它没有做任何特殊的事情,或者你是否信任它?
默认会生成一个?


我自己经常写一个构造函数(更确切地说,当你从IDE中添加一个新的
类时,空构造函数已经为你编写了)。

2)地区。我真的非常喜欢区域功能,用于组织代码和降低IDE中的噪音。我已经看到了很多代码,人们将所有私有类变量放在他们自己区域的类顶部。


这是我喜欢的款式。在我的课程中,我通常会组织像

这样的代码:


常数

私人会员

建设者

公共方法

公共财产

公共活动

受保护的方法

受保护的酒店

受保护的活动

内部方式

内部房产

内部事件

私有方式

私有房产

私人活动


如果有一些静态成员,他们会在实例之前进入上面列出的

订单。


-

Dmitriy Lapshin [C#/ .NET MVP]

X-Unity Test Studio
http:// x -unity.miik.com.ua/teststudio.aspx

将单元测试的强大功能带到VS .NET IDE


Daniel比林斯利" <分贝********** @ NO.durcon.SPAAMM.com>在消息中写道

新闻:%2 ****************** @ tk2msftngp13.phx.gbl ...我总是对某些人感到好奇这些风格问题,如果看起来实际上是以某种方式做事的客观原因,那么这里需要花费
来进行更轻松的讨论。

1)默认构造函数。你总是为每个
课写一个构造函数,即使它没有做任何特殊的事情,或者你是否信任它?
默认会生成一个吗?

2)区域。我真的非常喜欢区域功能,用于组织代码和降低IDE中的噪音。我已经看到了很多代码,人们将所有私有类变量放在他们自己区域的类顶部。最近我看到了代码,它们分散在
实际使用的各个区域 - 例如,靠近相应的
属性代码。对于像我这样喜欢地区的人来说,后者似乎更有用。






您好Daniel,


感谢您在此群组中发帖。

就个人而言,我认为:

1)。因为编译器会为你生成一个默认的构造函数,所以无论你是否创建一个空的构造函数,都有


2)。我认为如果一个类变量仅用于属性使用,我更喜欢

在属性定义的正上方创建变量。我将在同一地区放置其他

非静态变量。


这只是一种个人编程风格,让'听到其他人''

建议。


祝你好运,

Jeffrey Tan

Microsoft在线合作伙伴支持
安全! - www.microsoft.com/security

此帖子按原样提供没有保证,也没有授予任何权利。


Daniel ......我倾向于明确写一个空的构造函数,如果我

想要支持一个空的构造函数。如果有人更新你的代码

并添加了一个自定义construtor,默认构造函数将默默地移除



我通常会声明顶部的变量。如果变量在_ / $
本地代码段中使用了_only_

,那么我会把它放在代码附近。这是



接近原则,代码完成,Mcconnell。


问候,

Jeff

1)默认构造函数。你总是为每个



类写一个构造函数,即使它没有做任何特殊的事情,或者你是否信任

默认将生成一个?<

***通过Developersdex发送 http://www.developersdex.com ***

不要只是参加USENET ......获得奖励!


I''m always curious on some of these style issues if there seem to actually
be objective reasons for doing things one way or the other, so here goes for
a little lighter discussion.

1) Default constructors. Do you always write a constructor for every
class, even when it doesn''t do anything special, or do you "trust" the
default one that will be generated?

2) Regions. I really really like the region feature for organizing code
and reducing noise in the IDE. I''ve seen quite a bit of code where people
put all the private class variables together right at the top of the class
in their own region. Lately I''ve seen code where they are scattered in the
various regions where they are actually used - near the corresponding
property code, for example. The latter seems a bit more useful for someone
like me who loves regions.

解决方案

Hi Daniel,

1) Default constructors. Do you always write a constructor for every
class, even when it doesn''t do anything special, or do you "trust" the
default one that will be generated?
I usually write a constructor myself (to be more exact, when you add a new
class from the IDE, the empty constructor is already written for you).
2) Regions. I really really like the region feature for organizing code
and reducing noise in the IDE. I''ve seen quite a bit of code where people
put all the private class variables together right at the top of the class
in their own region.
This is the style I prefer. In my classes, I usually organize code like
this:

Constants
Private members
Constructor(s)
Public methods
Public properties
Public events
Protected methods
Protected properties
Protected events
Internal methods
Internal properties
Internal events
Private methods
Private properties
Private events

If there are some static members, they go before the instance ones in the
order outlined above.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Daniel Billingsley" <db**********@NO.durcon.SPAAMM.com> wrote in message
news:%2******************@tk2msftngp13.phx.gbl... I''m always curious on some of these style issues if there seem to actually
be objective reasons for doing things one way or the other, so here goes for a little lighter discussion.

1) Default constructors. Do you always write a constructor for every
class, even when it doesn''t do anything special, or do you "trust" the
default one that will be generated?

2) Regions. I really really like the region feature for organizing code
and reducing noise in the IDE. I''ve seen quite a bit of code where people
put all the private class variables together right at the top of the class
in their own region. Lately I''ve seen code where they are scattered in the various regions where they are actually used - near the corresponding
property code, for example. The latter seems a bit more useful for someone like me who loves regions.





Hi Daniel,

Thanks for posting in this group.
Personally, I think:
1). Because the compiler will generate a default constructor for you, there
is no matter whether you create a empty constructor or not.
2). I think if one class variable is only for property usage, I prefer to
create the variable just above the property definition. I will place other
non-static variables in the same region.

This is just a personally programming style, let''s hear some others''
suggestion.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Daniel.... I would lean to explicitly writing an empty constructor if I
wanted to support an empty constructor. If someone updates your code
and adds a custom construtor, the default constructor will be silently
removed!

I usually declare variables at the top. If the variable is _only_ used
in a
local section of code, then I would put it close to the code. This is
the
"principle of proximity," Code Complete, Mcconnell.

Regards,
Jeff

1) Default constructors. Do you always write a constructor for every


class, even when it doesn''t do anything special, or do you "trust" the
default one that will be generated?<
*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!


这篇关于几个问题的风格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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