Category: Todo

A Conversation with Anders Hejlsberg, by Bill Venners with Bruce Eckel(August 4, 2003)

Posted by – 2009/01/05

A Conversation with Anders Hejlsberg,
by Bill Venners with Bruce Eckel
August 4, 2003

These conversation includes 8 parts:

  • In Part I: The C# Design Process, Hejlsberg discusses the process used by the team that designed C#, and the relative merits of usability studies and good taste in language design.
  • In Part II: The Trouble with Checked Exceptions, Hejlsberg discusses versionability and scalability issues with checked exceptions.
  • In Part III: Delegates, Components, and Simplexity, Hejlsberg discusses delegates and C#’s first class treatment of component concepts.
  • In Part IV: Versioning, Virtual, and Override, Hejlsberg explains why C# instance methods are non-virtual by default and why programmers must explicitly indicate an override.
  • In Part V: Contracts and Interoperability, Hejlsberg discusses DLL hell and interface contracts, strong names, and the importance of interoperability.
  • In Part VI: Inappropriate Abstractions, Hejlsberg and other members of the C# team discuss the trouble with distributed systems infrastructures that attempt to make the network transparent, and object-relational mappings that attempt to make the database invisible.
  • In Part VII: Generics in C#, Java, and C++, Hejlsberg compares C#’s generics implementation to Java generics and C++ templates, describes constraints in C# generics, and describes typing as a dial.
  • In Part VIII: CLR Design Choices, Hejlsberg discusses IL instructions, non-virtual methods, unsafe code, value types, and immutables.
  • CIL Programming: Under the Hood of .NET

    Posted by – 2008/12/25

    在实现DTE的过程中难以避免的读或写IL,《CIL Programming》这本书给我带来很大帮助。在此记录下一些知识。

    堆栈信息基础(Basic Stack Information)

    四个数字类型: int32, int64, native int, F
    一个对象引用类型: 0
    两个指针类型: native int, &

    传递参数(Passing Arguments)

    .class SimpleType
    {
        .method public instance int64 SomeMethod(int32 arg1, float64 arg2,
            class [System.Windows.Forms]System.Windows.Forms.Form thisForm) {}
    }

    这个例子中
    int32
    float64
    class [System.Windows.Forms]System.Windows.Forms.Form
    都是对参数的描述,前两个是primitive type,最后一个是引用类型。

    有三个可以用来修饰参数的属性in,out,opt.
    in – 调用方(caller)负责将已初始化的变量作为参数传入方法。
    out – 被调用方(callee)负责在方法结束之前,将参数设置成正确的类型。
    opt – 表示参数是可选的,需用.param 指令(directive)

    使用.NET泛型集合(Generic Collection)

    Posted by – 2008/12/23

    StackOverflow上看到一个关于泛型类型检查的问题
    定义一个泛型类时,可以使用where关键字对初始化时用做类型参数(type arguments)的类型加以约束(constraints )。如果不符合约束则抛出编译时错误(compile-time error)。
    支持的约束有:

    约束 描述
    where T : struct 类型参数必须是值类型。除了Nullable
    where T : class 类型参数必须是引用类型,包括类、接口、委托和数组。
    where T : new() 类型参数必须包含一个公共的无参构造函数,这个约束必须放在所有的其他约束之后。
    where T : <base_class_name> 类型参数必须是此基类或者此基类的派生类
    where T : <interface_name> 类型参数必须实现指定接口,可以指定多接口,或者泛型接口。
    where T : U T的类型参数必须是U,或者U的类型参数派生类。所谓裸类型约束(naked type constraint)。

    .NET泛型支持,泛型参数,泛型接口,泛型方法等。Code Project上一篇讲解.Net泛型集合的文章

    C5项目
    CollectionBase应该是Java中的Set,是众多集合的基类。

    Java集合与C5集合对比

    Java中的 C5中的
    java.util.Set C5.CollectionBase
    java.util.HashSet C5.HashSet
    java.util.List C5.IList
    java.util.TreeSet C5.TreeSet
    java.util.Collection C5.ICollection
    java.util.Map C5.IDictionary

    使用1:

    Set<Entry<VALUE>> newHead = new HashSet<Entry<VALUE>>();

    使用2:

    Map<KEY, Set<Entry<VALUE>>> head = new HashMap<KEY, Set<Entry<VALUE>>>();
    for (Collection<Entry<VALUE>> entries : head.values())
    {
        // ...
    }

    使用3:

    public static <T> List<T> asList(T... a) {
        return new ArrayList<T>(a);
    }

    CLR如何创建运行时对象

    Posted by – 2008/12/04

    MSDN Mag上的Drill Into .NET Framework Internals to See How the CLR Creates Runtime Objects 一文描述了CLR创建对象时的过程。