公约问题 [英] Convention question

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

问题描述

在一个类中,你是否使用了私有关键字作为

内部成员变量,还是像你一样把它留下来?

会为函数中的变量做什么? br />

Within a class, do you use the private keyword for your
internal member variables or do you leave it off like you
would for variables within a function?

推荐答案

GC< gc ******** @ yahoo.com>写道:
GC <gc********@yahoo.com> wrote:
在一个类中,你是否使用了内部成员变量的private关键字,或者你是否像函数中的变量一样将它关闭?
Within a class, do you use the private keyword for your
internal member variables or do you leave it off like you
would for variables within a function?




我把它留在C#中,但是在Java中使用它。重要的是,他们

*是私有的,但因为这是C#中的默认值,它不是真正的问题。
问题。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet/

如果回复小组,请做不要给我发邮件



I leave it off in C#, but use it in Java. It''s important that they
*are* private, but as that''s the default in C# it''s not really a
problem.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too


我是明确写这样的东西的粉丝 - 因为A)我不知道

那是C#的默认值,我确定还有其他人不会...... B)

当我8个月回到我的代码时(以及之后的几十个小项目) -

我将无法记住我所做的所有假设......


软件错误完全来自于假设。 (我的报价,虽然 - 我

继续提炼它......我很快就会有最后一个)


所以1/4秒它需要写这个,可能会在几个小时后节省我

当我(或一些可怜的灵魂)试图修复我的代码时...


Jon Skeet < SK *** @ pobox.com>在消息中写道

新闻:MP ************************ @ news.microsoft.com ...
I am a fan of explicitly writing things like that - because A) I didn''t know
that was the default for C# and I''m sure there are others that don''t.. B)
when I come back to my code 8 months (and dozens of small projects later) -
I''m not going to be able to remember all the assumptions I made...

"Software bugs are born solely from assumptions." (my quote, although - I
keep refining it.. I''ll have the final one soon)

So for the 1/4 second it takes to write this, might save me hours later on
when I''m (or some poor soul) is trying to fix my code..

"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
GC< gc ******** @ yahoo.com>写道:
GC <gc********@yahoo.com> wrote:
在一个类中,你是否使用了内部成员变量的private关键字,或者你是否像函数中的变量一样将它关闭?
Within a class, do you use the private keyword for your
internal member variables or do you leave it off like you
would for variables within a function?



我把它留在C#中,但在Java中使用它。重要的是它们是*私有的,但因为这是C#中的默认值,它不是真正的问题。

- < Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet/
如果回复小组,请不要给我发邮件



I leave it off in C#, but use it in Java. It''s important that they
*are* private, but as that''s the default in C# it''s not really a
problem.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too



Drebin< tR ************* @ hotmail.com>写道:
Drebin <tR*************@hotmail.com> wrote:
我是明确写这样的东西的粉丝 - 因为A)我不知道这是C#的默认值,我确定还有其他人别。


我个人希望与我合作的每个人都知道

语言,这足以让他们知道 - 否则他们会问。非私人

可写(或可变)成员变量足以令人大开眼界

我知道*如果我怀疑我会*检查发生了什么事我使用的一些代码

正在使用它们。

B)
当我8个月回到我的代码(以及之后的几十个小项目)时 -
我无法记住我所做的所有假设...


这是否意味着你不会接受所有其他的事情然后

C#规范明确说明了吗?

接受C#按照规范工作并不等于

假设某些东西的实现将以某种特定的(无证件的)方式工作。

软件缺陷完全来自假设。 (我的引言,虽然 - 我继续提炼它......我很快就会有最后一个)


软件错误通常来自* false *假设。

很容易*证明*在这种情况下假设是正确的 - 你只需要看看C#规范的


所以写1/4秒需要写这个,可能会在几个小时之后保存我
当我(或一些可怜的灵魂)试图修复我的代码时..
I am a fan of explicitly writing things like that - because A) I didn''t know
that was the default for C# and I''m sure there are others that don''t.
I would personally like to hope that everyone I work with will know the
language well enough to know that - or else they''d ask. Non-private
writable (or mutable) member variables are enough of an eye-opener that
I know *I''d* check what was going on if I suspected some code I was
working with was using them.
B)
when I come back to my code 8 months (and dozens of small projects later) -
I''m not going to be able to remember all the assumptions I made...
Does that mean you''re not going to accept all the other things that the
C# specification explicitly states then?

Accepting that C# works as per the specification isn''t the same as
assuming that the implementation of something will work in some
particular (undocumented) way.
"Software bugs are born solely from assumptions." (my quote, although - I
keep refining it.. I''ll have the final one soon)
Software bugs are often born from *false* assumptions. It''s easy to
absolutely *prove* that the assumption is true in this case - you just
look at the C# specification.
So for the 1/4 second it takes to write this, might save me hours later on
when I''m (or some poor soul) is trying to fix my code..



你能给出一个错误的例子吗?可能

因为?


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet/

如果回复该组,请不要给我发邮件



Could you give an example of a bug which leaving out "private" might
cause?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too


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

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