Is C# a clone of a Microsoft replacement for Java?
Is C# a clone of a Microsoft replacement for Java?Let's look at what Anders Hejlsberg Said.
Hejlsberg: First of all, C# is not a Java clone. In the design of C#, we looked at a lot of languages. We looked at C++, we looked at Java, at Modula 2, C, and we looked at Smalltalk. There are just so many languages that have the same core ideas that we're interested in, such as deep object-orientation, object-simplification, and so on.
One of the key differences between C# and these other languages, particularly Java, is that we tried to stay much closer to C++ in our design. C# borrows most of its operators, keywords, and statements directly from C++. We have also kept a number of language features that Java dropped. Why are there no enums in Java, for example? I mean, what's the rationale for cutting those? Enums are clearly a meaningful concept in C++. We've preserved enums in C# and made them type-safe as well. In C#, enums are not just integers. They're actually strongly typed value types that derive from System.Enum in the .NET base-class library. An enum of type "foo" is not interchangeable with an enum of type "bar" without a cast. I think that's an important difference. We've also preserved operator overloading and type conversions. Our whole structure for name spaces is much closer to C++.
But beyond these more traditional language issues, one of our key design goals was to make the C# language component-oriented, to add to the language itself all of the concepts that you need when you write components. Concepts such as properties, methods, events, attributes, anddocumentation are all first-class language constructs. The work that we've done with attributes -- a feature used to add typed, extensible metadata to any object -- is completely new and innovative. I haven't seen it in any other programming language. And C# is the first language to incorporate XML comment tags that can be used by the compiler to generate readable documentation directly from source code.
Another important concept is what I call "one-stop-shopping software." When you write code in C#, you write everything in one place. There is no need for header files, IDL files (Interface Definition Language), GUIDs and complicated interfaces. And once you can write code that is self-describing in this way, then you can start embedding your software, because it is a self-contained unit. Now you can slot it into ASP pages and you can host it in various environments where it just wasn't feasible before.
But going back to these key component concepts, there's been a lot of debate in the industry about whether languages should support properties or events. Sure, we can express these concepts by methods. We can have naming patterns like a "get" block or a "set" block that emulate the behavior of a property. We can have interfaces and adapters that implement an interface and forward to an object. It's all possible to do, just as it's possible to do object-oriented programming in C. It's just harder, and there's more housekeeping, and you end up having to do all this work in order to truly express your ideas. We just think the time is right for a language that makes it easier to create components. Developers are building software components these days. They're not building monolithic applications or monolithic class libraries. Everyone is building components that inherit from some base component provided by some hosting environment. These components override some methods and properties, and they handle some events, and put the components back in. It's key to have those concepts be first class.
译文:
首先,C#不是Java的克隆。在设计C#期间,我们考察了很多种语言,如C++、Java、Modula 2、C、Smalltalk等。很多语言都有我们感兴趣的相同的核心思想,比如深度面向对象、简化对象等等。
C#和这些别的语言尤其是Java的关键不同点是它非常接近C++。在我们的设计中努力使然。C#从C++直接借用了大多数的操作符、关键字和声明。我们还保留了许多被Java抛弃的语言特性。为什么Java中没有枚举,道理何在?我的意思是,抛弃它们是基于何种理论基础?在C++中,枚举显然是一个很有意义的概念。在C#中,我们保留了枚举并同样使其类型安全,并且,枚举不只是整型,它们实际上是从.NET基类库里的System.Enum派生下来的强类型的值类型。如果没有造型转换,枚举类型“foo”和枚举类型“bar”不可互换。我认为这是个重要的差异。我们还保留了操作符重载和类型转换。C#名字空间的整体结构也非常接近C++。
但是,超越这些传统的语言论题,我们设计语言的一个关键的目标是使C#面向组件。我们向语言自身加入了你在编写组件时所需要的所有概念。例如属性[译注:即property,翻译为“属性”,由来已久。我怀疑如果先有attribute的话,property会不会被翻译为“性质”、“特性”,而attribute才是“属性”:JL]、方法、事件、特性[译注:即attribute,截至目前,此名词译法仍较混乱。有的翻译和property不区分,也译为“属性”;有的译为“特性”;有的译为“属性信息”。在该名词译法尚未统一之前,本着精简原则,笔者先把它翻译成“特性”。但注意,XML中的attribute的译法一般比较统一,即为“属性”(因为XML中没有一个类似于property的东西会与之混淆)。因此,本文最后交叉描述C#和XML的部分,请留心“特性”、“属性”各有所指。]和文档等,它们都是一流的语言结构。我们对特性所做的工作是全新的和创新的。利用特性可为任何对象加入有类型的、可扩展的元数据。这在目前任何其它程序语言里都看不到的。C#也是第一个合并XML注释标记的语言,编译器可以用其直接从源码中生成可读的文档。
另外一个重要的概念是我所说的“一站购物式软件”[one-stop-shopping software]。一旦你用C#写代码,你就在这一个地方写了一切。不再需要头文件、IDL(接口定义语言)文件、GUID和复杂的接口。因为它是自包容的单元。一旦用这种方式写自描述的代码,你就可以把你的软件嵌入到ASP页面或植入各种不同的环境,这在以前是不可能的。
但是让我们再回到组件这个重要的概念。语言是否应该支持属性或事件,业界有很多争论。没错,我们是可以用方法表达这种概念。我们可以用诸如“get”或“set”之类的程序块的命名模式模拟属性的行为。我们可以用接口和实现接口的适配器并转发到对象。这都是可能实现的,就象可能在C语言里进行面向对象编程一样。只是它太困难了,需要太多的手工劳动,为了表达你真正的思想,你最终不得不去做所有的工作。我们认为是时候了,应该有个语言使得创建组件变得容易些。今天程序员在创建软件组件。他们并不是创建整个应用或整个类库。每个人都是在创建从宿主环境提供的基组件继承下来的组件。这些组件重载一些方法和属性,它们处理一些事件,并把组件安装回系统。树立这些概念是关键的第一课。
Is C# a clone of a Microsoft replacement for Java?的更多相关文章
- 对象复制、克隆、深度clone
-------------------------------------------------------------------------------- ------------------- ...
- 详解Java中的clone方法:原型模式
转:http://developer.51cto.com/art/201506/478985.htm clone顾名思义就是复制, 在Java语言中, clone方法被对象调用,所以会复制对象.所谓的 ...
- 温故而知新 clone
浅复制(浅克隆) 被复制对象所有变量都含有与原来对象的相同值,对象中对其他对象的引用仍然指向原来的对象,换言之,复制对象只复制考虑的对象,而不复制所引用的对象.继承自java.lang.Object类 ...
- clone 深拷贝 浅拷贝
1. 定义:知道一个对象,但不知道类,想要得到该对象相同的一个副本,在修改该对象的属性时,副本属性不修改,clone的是对象的属性 2. 意义:当一个对象里很多属性,想要得到一个相同的对象,还有set ...
- Java基础——clone()方法浅析
一.clone的概念 clone顾名思义就是复制, 在Java语言中, clone方法被对象调用,所以会复制对象.所谓的复制对象,首先要分配一个和源对象同样大小的空间,在这个空间中创建一个新的对象.那 ...
- HDOJ 5000 Clone
所有的属性,以满足一定的条件,是,财产和等于sum/2结果最大. Clone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
- 转:Java中的Clone()方法详解
Java中对象的创建 clone顾名思义就是复制, 在Java语言中, clone方法被对象调用,所以会复制对象.所谓的复制对象,首先要分配一个和源对象同样大小的空间,在这个空间中创建一个新的对象.那 ...
- Java中的clone()----深复制,浅复制
这篇文章主要介绍了Java中对象的深复制(深克隆)和浅复制(浅克隆) ,需要的朋友可以参考下 1.浅复制与深复制概念 ⑴浅复制(浅克隆) 被复制对象的所有变量都含有与原来的对象相同的值,而所有的对其他 ...
- java clone()
Java中对象的创建 clone顾名思义就是复制, 在Java语言中, clone方法被对象调用,所以会复制对象.所谓的复制对象,首先要分配一个和源对象同样大小的空间,在这个空间中创建一个新的对象 ...
随机推荐
- leetcode 题解:Binary Tree Inorder Traversal (二叉树的中序遍历)
题目: Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary ...
- (Android学习系列)一,用按钮实现时间的显示
我们先用AndroidStudio新建一个项目,选择空白模板,然后像其中拖入两个Button,将他们的id分别命名为btDate(显示日期),btTime(显示时间),他的模板XML代码很简单 < ...
- Android隐藏状态栏实现沉浸式体验
转自: Android状态栏微技巧,带你真正理解沉浸式模式 什么叫沉浸式? 根据百度百科上的定义,沉浸式就是要给用户提供完全沉浸的体验,使用户有一种置身于虚拟世界之中的感觉. 那么对应到Android ...
- 《算法导论》习题解答 Chapter 22.1-2(邻接矩阵与链表)
链表如图: 矩阵: 1 2 3 4 5 6 7 1 0 1 1 0 0 0 0 2 1 0 0 1 1 0 0 3 1 0 0 0 0 1 1 4 0 1 0 0 0 0 0 5 0 1 0 0 0 ...
- Linux常用命令之grep
标题:grep命令的使用 作用:grep可以解析一行文字,取得关键字,若该行存在关键字,就会整行列出. grep [-acinv] [--color=auto] '查找字符串' filename ...
- SpringData JPA详解
Spring Data JPA 1. 概述 Spring JPA通过为用户统一创建和销毁EntityManager,进行事务管理,简化JPA的配置等使用户的开发更加简便. Spring Data ...
- Linux的SOCKET编程详解
1. 网络中进程之间如何通信 进 程通信的概念最初来源于单机系统.由于每个进程都在自己的地址范围内运行,为保证两个相互通信的进 程之间既互不干扰又协调一致工作,操作系统为进程通信提供了相应设施,如 U ...
- 插件介绍 :cropper是一款使用简单且功能强大的图片剪裁jQuery插件。
简要教程 cropper是一款使用简单且功能强大的图片剪裁jQuery插件.该图片剪裁插件支持图片放大缩小,支持鼠标滚轮操作,支持图片旋转,支持触摸屏设备,支持canvas,并且支持跨浏览器使用. c ...
- Unity3d之动态连接Mesh Renderer和Collider
using UnityEngine; using System.Collections; public class dynaMesh : MonoBehaviour { public Skin ...
- MySQL之学生名次问题
--对输入的数据进行约束create table t(studentID char(10), [name] varchar(8), startDate char(10) Check (isdate(s ...