只读的变量和可读写的变量_上帝将他的只读变量放在哪里?

只读的变量和可读写的变量

只读的变量和可读写的变量

I've got one more physics class and two math classes to finish my 11 year quest for a 4 year degree.  As I was sitting in Physics yesterday we were talking about the Ideal Gas Constant and Avogadro's number and the thousand other constants that make It All Work.  And I was thinking...in my programming I'm always trying to avoid superfluous constants when possible, and use enums to group related consts when possible. 

我还有一门物理课和两门数学课来完成我11年的4年制学位课程。 当我昨天坐在物理学上时,我们在谈论理想气体常数Avogadro的数值以及其他使它全部起作用的常数。 我当时在想...在我的程序设计中,我总是尽可能地避免多余的常量,并在可能的情况下使用枚举对相关的const进行分组。

But in the Universe, for It All To Work we seem to need a lot of very precise and specific Constants and learning physics for me has been as much learning another person's code and algorithms as it has been understanding the constants they needed to get the job done.

但是在宇宙中,要使一切都正常工作,我们似乎需要很多非常精确和特定的常量,对我来说,学习物理学就像在学习别人的代码和算法一样,也一直在理解他们获得这份工作所需的常量。完成。

My real question is, did God put these constants as a readonly field in a static constructor or a singleton pattern, or assuming parallel universes, a factory pattern? Either way, it makes me think when I write C# code, how would God write this loop? :)

我真正的问题是,上帝是否将这些常量作为静态构造函数或单例模式中的只读字段,或者假定为并行宇宙,即工厂模式? 无论哪种方式,这都使我想到编写C#代码时,上帝将如何编写此循环? :)

(and please note God's use of a modified Hungarian naming convention)

(请注意,上帝使用了经过修改的匈牙利命名约定)

public Reality
{
      public readonly double dblAvogadrosNumber = 6.022137*10^23....etc;      /* additional Reality Code removed for clarity... */      private static Reality singletonInstance;      private static int cReference;      public static Reality GetInstance()
      {
          if(singletonInstance== null)
          {
              singletonInstance= new Reality("Let there be light, etc");
          }
          cReference++;
          return singletonInstance;
      }          

}

公共现实{ 公共只读精度dblAvogadrosNumber = 6.022137 * 10 ^ 23 .... etc; / *为了清楚起见,删除了其他Reality代码... * / 私有静态现实singletonInstance; private static int c参考; 公共静态现实GetInstance(){如果(singletonInstance == null ){singletonInstance = new Reality(“让光等等”);}cReference ++;return singletonInstance;}          }

翻译自: https://www.hanselman.com/blog/where-did-god-put-his-readonly-variables

只读的变量和可读写的变量

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值