码迷,mamicode.com
首页 > 编程语言 > 详细

Is C# a clone of a Microsoft replacement for Java?

时间:2014-10-25 09:13:12      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:des   io   os   ar   java   for   strong   sp   on   

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.

Is C# a clone of a Microsoft replacement for Java?

标签:des   io   os   ar   java   for   strong   sp   on   

原文地址:http://www.cnblogs.com/wangnmhb/p/4049679.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!