C# (0分)

  • 主题发起人 主题发起人 yysun
  • 开始时间 开始时间
Y

yysun

Unregistered / Unconfirmed
GUEST, unregistred user!
Turbo Pascal 和 Delphi 的设计者 Anders Hejlsberg,
现在为 Microsoft 设计了新的一种程序语言: C# (读为 C sharp)
http://windows.oreilly.com/news/hejlsberg_0800.html
 
老猫以及好多人去不了那里,您给copy一些过来大家开开眼啊
 
好长啊!
Deep Inside C#:
An Interview with Microsoft Chief Architect Anders Hejlsberg
by John Osborn

--------------------------------------------------------------------------------
In July, O'Reilly editor John Osborn attended the Microsoft Professional Developer's Conference where he conducted the following interview with Anders Hejlsberg, Distinguished Engineer and Chief C# Language Architect about Microsoft's .Net framework and the C# programming language. Anders Hejlsberg is also known for having designed Turbo Pascal, one of the first languages available for PCs. Anders licensed Turbo Pascal to Borland and later led the team that created Delphi, a highly successful visual design tool for building client server applications. Also in attendance at the interview were Tony Goodhew, Microsoft C# product manager, and O'Reilly Windows editor Ron Petrusha.

--------------------------------------------------------------------------------
Osborn:
I've been looking at press stories about C# [pronounced "See sharp"] and notice that many of them seem to lead with the observation -- or perhaps the theory -- that C# is either a clone of or a Microsoft replacement for Java. If you could write the headlines, what would you like people to say about the language?
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, anddo
cumentation are all first-class language constructs. The work that we'vedo
ne 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 readabledo
cumentation 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 todo
, just as it's possible todo
object-oriented programming in C. It's just harder, and there's more housekeeping, and you end up having todo
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.

Osborn:
You gave an introduction to C# recently, and the first bullet on the first slide said, "The first component-oriented language in the C/C++ family."
Hejlsberg:
Yes, it's one of my primary goals. We talk about how everything is an object, which is also very key. Languages like Smalltalk and Lisp havedo
ne this before, but at great cost. I think C# contains some pretty interesting innovations that make component development easier, such as its notions of boxing and unboxing. Boxing allows the value of any value type to be converted to an object, while unboxing allows the value of an object to be converted to a simple value type. It's not as though this hasn't happened before, but the way we've applied it to the language is pretty innovative.
We've tried not to take an "ivory tower" approach to engineering C# and the .Net framework. We can't afford to rewrite all of our software. The industry just can't afford it, especially now when we're moving on Internet time. You've got to leverage what you have, and so I think interoperability is just key. We focused hard on giving programmers all of the right solutions for interoperating with Internet standards, such as HTTP, HTML, XML, and with existing Microsoft technologies, so youdo
n't fall off a cliff the minute you find that something isn't provided by the new .NET environment, or when you realize you want to leverage some existing API or component. You've seen all the COM interoperability that we have built into the language and into the common runtime;
you've seen how you can just import existing DLLs [Dynamically Linked Libraries] using the DllImport attribute;
and you've seen how even if thatdo
esn't get you there, we have the notion of unsafe code. Unsafe code allows you to write inline C code with pointers, todo
unsafe casts, and to pindo
wn memory so it won't accidentally be garbage-collected.

--------------------------------------------------------------------------------
Read more about the .NET platform in .NET vs. J2EE: Howdo
They Stack Up?. Jim Farley, author of Java Enterprise in a Nutshell, compares the two platforms.
--------------------------------------------------------------------------------
There's been a lot of discussion about unsafe code, and people seem to think we're on drugs or something. I think it's a misunderstanding. Just because code is marked "unsafe"do
es not mean that it is unmanaged. Of course, we're not just throwing in unsafe pointers and leaving people vulnerable todo
wnloading unsafe code over the Internet. Unsafe code is deeply tied into the security system. We give you the flexibility to stay within the managed code box and to get the jobdo
ne without falling off the cliff and having to jump into a different language and a different programming model for native code. And by keeping you within the box, we can make the code much safer because the system understands what's going on. The fact that you write unsafe codedo
esn't actually mean that you're leaving the managed space. So your unsafe code becomes much more efficient.

Osborn:
Tell me more about dealing with unsafe code in a managed environment.
Hejlsberg:
Yes. One of the things that characterizes managed execution environments, like Smalltalk, Java, and the .NET common language runtime, is that they provide garbage collection, and to provide garbage collection, at least with modern garbage collectors -- your "mark and sweep" garbage collectors -- you need to understand more about the code that's executing than youdo
about traditional unmanaged code. In order to find the dead objects by exclusion, you need to be able to walk the stack, to chasedo
wn all the live roots, and to figure out which objects are alive and which ones weren't visited. However, in order to be able todo
that, you need closer cooperation from the code you are executing. The code needs to be more descriptive. It needs to tell you how I am laying out the stack, where my local variables are located, and so on.
When you're writing unsafe code in C#, you have the ability todo
things that aren't typesafe, like operate with pointers. The code, of course, gets marked unsafe, and will absolutely not execute in an untrusted environment. To get it to execute, you have to grant a trust, and if youdo
n't, the code just won't run. In that respect, it's no different than other kinds of native code. The real difference is that it's still running within the managed space. The methods you write still have descriptive tables that tell you which objects are live, so youdo
n't have to go across a marshalling boundary whenever you go into this code. Otherwise, when you go out to undescriptive, unmanaged code (like through the Java Native Interface, for example), you have to set a watermark or erect a barrier on the stack. You have to remarshall all the arguments out of the box. Once you're using objects, you have to be very careful about which ones you touch because the GC [Garbage Collector] is still running on a different thread. It might move the object if you haven't pinned itdo
wn correctly by using some obscure method to lock the object. If you forget todo
that, you're just out of luck.
We've taken a different approach. We've said, "Let's integrate this into the language. Let's provide statements, like the fixed statement, that allow you to pindo
wn the object cooperatively with the GC and integrate it." In that way we provide the best means of bringing all existing code forward, instead of just throwing it away. It's a different design form.

Osborn:
So the memory that you're working with in unsafe code is in fact being watched by the garbage collector?
Hejlsberg:
Yes, it is. But, caveat emptor, it's unsafe. You can obtain a pointer and you cando
the wrong thing. But you cando
that in native code, too.
Osborn:
Another area of confusion, I think, is understanding where C# stops and the common runtime begin
s. What's the innovation in the C# language itself versus what it gets from the common runtime library?
Hejlsberg:
Well, I think some of this confusion comes from the fact that when people talk about Java, theydo
n't really know which is the language and which is the runtime. Some of this confusion arises when people talk about Java. Which is the language and which is the runtime? Whatdo
people mean when they say Java?do
they mean Java, the language, Java, the syntax, ordo
they mean Java, the platform? People lump these different aspects together. We've taken an approach that says we want to be a multilingual platform. We're going to build a platform that actually allows you to implement multiple programming languages and also have them share a common set of APIs (Application Programming Interfaces). Let's face it, some people like to program in COBOL, some people like to program in Basic, some like C++, and some will like C#, I hope. But we're not trying to tell you to forget everything you ever did. We're not saying, "Now that there's only one language, there shall be no further innovations in this race." We're saying that our industry advances by its flexibility. How did Java come about? It came about because there were programming languages before it and there will be programming languages after it. We want to build a platform where your preference for one language over anotherdo
esn't negate the whole value proposition. We want to create a platform where there can be innovation. Who's helping COBOL programmers today? Who's taking them to the Web? Only on the .NET platform can you embed Fujitsu COBOL in an ASP page. I mean it's truly revolutionary.
Osborn:
Given the availability of multiple languages for the .NET platform, why would you choose C# over Visual Basic, C++, or even COBOL? What is it that makes C# so compelling?
Hejlsberg:
First of all, with C# we were able to start with a clean sheet of paper, so to speak. We did not have any backward compatibility requirements, and that certainly made things simpler. And not just from an implementation standpoint, but also from a usage standpoint. For example, we only have one kind of class in C#, and it is always garbage-collected. Managed C++, on the other hand, has two because it has to preserve the non-garbage collected style of programming. So, C# simply has fewer concepts you have to understand.
Language is a funny thing: It's a matter of taste. Language is almost a religious thing, and it's a lifestyle choice for programmers. I mean, we realize that we can't walk out and say, "Here's a platform where you have one language base." Even if you coulddo
everything in that platform with one language, some people may not like its syntax;
they might like curly braces instead or some other block delimiter. That's what they're familiar with. That's what makes them feel at home and productive and enabled. And so our approach with C# has simply been to offer an alternative to C++ programmers who find that language too complicated and to Java programmers who miss certain features of C and C++ that were lost in the translation. We looked for ways to simplify C++ and then
put the result on a multilingual platform that provides greater interoperability, and that gives you all of these component concepts, and so forth.

Goodhew:
One of the interesting things that came out of our developer tracking study is that over 60 percent of all developers in the professional developer market use two or more languages to build their applications. And what that tells us, especially when we ask which tools programmers use, is that there isn't going to be one object-oriented programming language which is the end all and be all language that everyone will use. As Anders said earlier, people will want certain syntaxes for what they'redo
ing or how they feel. It's a personal choice. And that's what the whole .NET platform is about, providing developers with a choice of languages in which to implement. I think we'vedo
ne a pretty good job. You can basicallydo
the same tasks in Visual Basic, .NET, and C#. Visual Basic is still viewed as more accessible to programmers. C# has more headroom and more power than VBdo
es.
Osborn:
Meaning that you can accomplish more with fewer statements in C#?
Hejlsberg:
Well, meaning you have more power through the provision for unsafe code.
Osborn:
So you can't write unsafe code in VB?
Hejlsberg:
No, you cannot.
Goodhew:
But basically, both languages cando
the same thing. That's a fundamental change from where we were with Visual Studio 6. If you wanted to build a multi-threaded MTS object using Visual Studio 6.0 and you were a VB programmer, you couldn't. You'd have to use C++. Now, with the .NET framework, you can use whichever language you want.
Hejlsberg:
It's the thing I talked about in my general session talk: The unification of programming models, which the .NET framework offers. In the evolution of languages and frameworks, we always seemed to end up marrying a programming language to a particular API and a particular form of programming. VB was about rapid application development and forms, MFC (Microsoft Foundation Classes) was about sub-classing, and ASP was about putting stuff in web pages. In each case, your choice of programming model always dictated your choice of programming language and your choice of available APIs. It added to your workload the burden of learning new languages and APIs every time you switched frameworks. We have really tried to unify all of that. We provide one API, one supporting visual design tool, and we give you the flexibility to choose whichever language works for you.
Osborn:
I'm wondering what thisdo
es to the use of scripting languages such as VBScript and JScript?
Hejlsberg:
One of the wonderful things the .NET framework hasdo
ne for scripting languages is to make them compiled. Look at ASP+. Now, you're actually running real compiled code in your pages;
it's not late-bound, dispatch look-ups where youdo
n't see a runtime error until the user hits the page. ASP+ developers can use the full power of Visual Basic .NET instead of VBScript. And for the first time, they have the ability to use Perl, Python, and other popular languages if they so choose.
Petrusha:
Server-side JavaScript is now compiled?
Hejlsberg:
Yes, that's right.
Goodhew:
The .NET framework allows scripting languages to be used as full-featured languages because they now have access to a true programming framework and to the same base-class APIs. You should look at what the guys who aredo
ing the JScript implementation have accomplished. [Editors Note: JScript is the Microsoft implementation of the ECMA 262 language specification (ECMAScript Edition 3). With only a few minor exceptions (to maintain backward compatibility), JScript is a full implementation of the ECMA standard.] So the .NET platform provides a common language framework, which is a huge benefit to script writers.
Osborn:
We've talked about Java, C++, and scripting. I have heard a number of people here at the PDC argue that there really is no difference between .NET IL (IL is the Microsoft Intermediate Language that all compilers must produce to run in the .NET framework) and the Java byte code that is consumed by the Java Virtual Machine (JVM). It's clear from the talks you've given that youdo
not agree. Would you care to comment further on the distinction?
Hejlsberg:
Sure. First of all, the idea of ILs is a very old idea. You could trace the concept back to the UCSD Pascal p- machine (an early implementation of Pascal for personal computers) or to Smalltalk. p-code is used by Basic and Visual Basic. Parts of Word, internally, use a p-code engine because it's more compact. So, p-code is nothing new.
I think the approach we've taken with the IL is interesting in that we give you options to control when compilation -- or translation, if you will -- of the IL to native code occurs. With managed C++, you can actually generate native code directly from source. Managed C++ can also generate IL, as can C# and VB. And when you install your code we give you the option to compile it at that point;
to compile the IL to native at that point, so that when you run it there's no just-in-time compiler overhead. We also give you the option of running and compiling code dynamically, just-in-time compilation. And, of course, having an IL gives you many advantages, such as the ability to move to different CPU architectures and to introduce verifiability in type safety and then
build the security system on top of that.
I think one of the key differences between our IL design and Java byte code specifically, is that we made the decision up-front to not have interpreters. Our code will always run native. So, even when you produce IL, you are never running an interpreter. We even have different styles of JITs. For the compact framework, we have the EconoJIT, as we call it, which is a very simple JIT [Editor's Note: .NET Compact is a subset of the .NET framework designed to be ported to other devices and platforms.]. For the desktop version we have a more full-fledged JIT, and we even have JITs that use the same back end as our C++ compiler. However, those take longer so you would only use them at install time.
When you make the decision up-front to favor execution of native code over interpretation, you are making a decision that strongly influences design of the IL. It changes which instructions are included, what type information is included, and how it is conveyed. If you look at the two ILs, you'll notice that they're quite different. In a sense, our IL is type-neutral. There's no information in the instructions that specifies the type of the arguments. Rather, that is inferred by what's been pushed on the stack. This approach makes the IL more compact. A JIT compiler needs to have that information anyway, so there's no reason to carry it along in the instructions. So you end up with some different design decisions, which in turn makes it easier to translate IL into native code.

Osborn:
What distinction needs to be made between interpretation and the approach that you're describing?
Hejlsberg:
At the core of an interpreter is a loop that fetches some bytes out of a p-code stream, which then
falls into a big switch statement that says, "Oh, this was an ADD instruction, so it goes over here, but this wasn't" -- and so forth.
An interpreter emulates a CPU. We turn it upsidedo
wn and wedo
one pass -- we alwaysdo
one pass -- where we convert the instructions into machine code. Now, that machine code, in the case of EconoJIT, is actually very simple in that it just builds a list of calls and push instructions, and calls to runtime helpers. then
it sets off on that list instead. And, of course, that code executes much faster than interpreted code.

Osborn:
So, let me run through this: You're completely compiling the code. then
, when you'redo
ne, the bits are ready to run completely, though the point at which translation from IL to machine code occurs may vary.
Hejlsberg:
Yes. But then
we may, if it's in a memory-constrained environment on a small device, throw the code away after we've run it.
Osborn:
Jumping back to the particulars of language syntax: I'm wondering whether C# includes built-in support for regular expressions. I didn't see that support in the language reference, but maybe it's somewhere else
.
Hejlsberg:
First of all, there's a regular expression class in the base-class libraries. Wedo
n't have any direct support in the language for regular expressions, but wedo
have some features that are actually very similar. It's not worth making a big deal about them, but, for example, we give you the ability to write verbatim string literals where youdo
n't have to write two back slashes every time you want to specify one. It actually helps a whole bunch when you're writing regular expressions and when you're writing quotes within quotes. That's a little thing that helps, but clearly the core is in the .NET framework, which can be shared by all programming languages.
Osborn:
There appears to be a difference in the way we should view namespaces in C# and Java. Are they conceptually the same or are they implemented differently.
Hejlsberg:
Conceptually, yes, but they are implemented very differently. In Java, package names are also a physical thing that dictates the directory structure of your source code files. In C#, we have a complete separation between physical packaging and logical naming, so whatever you call your namespaces has nothing todo
with the actual physical packaging of your code. That gives you a lot more flexibility to package things together in physical distribution units without forcing you to also have a bunch of directories. In the language itself, there are clearly some differences. In Java, the packaging is also your physical structure, and because of this a Java source file has to be in the right directory and can only contain one public type or one public class. Since C#do
es not have that sort of marriage between physical and logical, you can name your source files anything you want. Each source file can contribute to multiple namespaces and can take multiple public classes. Further, you can choose to write all of your sources in one big file if you like, or you can spread them across smaller files. Conceptually, what happens with C# at compilation is that you give the compiler all of the source files that make up your project and then
it just goes off and figures out what todo
.
Osborn:
I have a question about generic programming:do
you think it is an important concept, one that ought to be part of an object-oriented language? And if so, what are your plans to make generic programming a part of C#.
Goodhew:
Well, some of what we had hoped to include in the first release has been constrained because -- unlike what everyone believes about Microsoft -- wedo
not have unlimited resources. We had to make some hard decisions in terms of what is actually in this first release.
Osborn:
How many people were involved in the development of C#?
Hejlsberg:
The language design team consisted of four people. The compiler team had another five developers.
Petrusha:
What about the framework?
Hejlsberg:
That's much bigger. The whole company is involved.
Goodhew:
In terms of the entire Visual Studio and .NET platform group, we are about a thousand-person division. That includes program management, developers, testers, all the build functions, the frameworks, the runtimes, the ASP programming models, and then
all of the people like myself, the management overhead.
Hejlsberg:
But with respect to the generics that you asked about, I definitely think generics are a very useful concept and you can certainly tell that from all the generics research that's taking place in academia and industry. Templates are one solution to the problem. In our internal discussions, we concluded that we wanted todo
it right for this new platform. But what we would really like is to have generics understood by the underlying runtime. This is different from how some of the generic prototypes have been built. Take Java's notions of "erasure" where there's really no knowledge of generics in the system. By having the common language runtime understand the concept of generics, multiple languages can share the functionality. You can write a generic class in C# over in one place and someone else
using a different language can use it.
But making generics part of the runtime also enables you todo
certain things much more efficiently. Instantiation of generics should ideally happen at runtime. With C++, instantiation of templates happens at compile time, and then
you have two options: you can either let your code bloat or you can try, in the linker, to get rid of some of the bloat. But, if you have multiple applications, you can forget about it. You're just going to get bloated code.
If you push the knowledge of generics into the common language runtime, then
the runtime can understand that when an application or a component asks for a list of "Foo's," it should first ask: "Do I already have an instantiation of a list of "Foo?" If so, use that one. Indeed, if Foo is a reference type, and if wedo
the design right, we can share the instantiation for all reference types. For value types, such as ints and floats, and we can create one instantiation per value type. But only when an application asks for it. We'vedo
ne a lot of the design work and groundwork necessary to add generics to the runtime.
It's interesting you asked earlier about the IL because deciding to add generics impacts the design of the IL. If the instructions in the IL embed type information -- if, for example, an Add instruction is not an Add, but is an Add int or an Add float or an Adddo
uble -- then
you've baked the type into the instruction stream and the IL is not generic at that point. Our IL format is actually truly type neutral. And, by keeping it type neutral, we can add generics later and not get ourselves into trouble, at least not as much trouble. That's one of the reasons our IL looks different from Java byte code. We have type neutral IL. The Add instruction adds whatever the two things are on top of the stack. In a generic world, that could translate into different code when the generic is instantiated.

Osborn:
Is that available to all .NET languages?
Hejlsberg:
Yes. Microsoft Research in Cambridge has created a generics version of the common language runtime and the C# compiler. We're looking at how to move that forward right now. It's not going to happen in the first release, that much we know, but we are working on making sure that wedo
things right for the first release so that generics fit into the picture.
Osborn:
What are the planned release dates for C#, the .NET framework, and the next version of Visual Studio?
Goodhew:
Well, we've brought the technology preview to the 6,500 attendees here at PDC. We expect to go to beta sometime in the fall (2000), and then
we'll release when ready. One of the really exciting things we'vedo
ne is take a good solid look at how the Windows 2000 launch release went and the way we involved key customers in the joint development and the joint deployment process. In the case of .NET framework and Visual Studio .NET, we will again work with customers to determine when the final product is ready to release. We're going to let them tell us when the product is ready. And, because we've got real customers involved in the process, we should get a much better product in terms of quality. Thedo
wnside of that is the process then
becomes a little indeterminate. This is a fundamental change. We are looking to hit a quality bar for the release of the product rather than just pick an arbitrary date and say we'll ship.
Osborn:
So, instead of a code completion date, we're looking at a "ready-to-go" date?
Goodhew:
Yes, that's right. I think developers will find the release of Visual Studio .Net to be one of the highest quality releases in Microsoft's history.
Osborn:
You have submitted C# to ECMA. Is standardization really a serious objective? Would you like C# to be available on other platforms?
Hejlsberg:
Absolutely. It's certainly our objective to present C# to the industry as a possible standard, which is why we've submitted it to ECMA. We certainly hope to gain support in ECMA for a process that will lead to a commonly designed language which has a common language infrastructure. And what I mean by a common infrastructure is the core set of class libraries this specification entails, such that if other companies using other platforms implement it, they could reasonably expect to find those classes available to their programs.
Goodhew:
I might point out that we're taking a true open standards approach with ECMA. When and if ECMA actually arrives at a standard for C# and a common language infrastructure, the result will be available under ECMA's copyright and licensing policies, which are truly open. Any customer, and any person, will be able to license the ECMA C# standard, subset it, superset it, and they won't have to pay royalties. They'll be able take it and go implement it on any platform or any device. We fully expect people todo
that. That is something fundamentally different from our competitors who wandered around the standards bodies, looking for someone to rubber-stamp their proprietary languages.
John:
One question I heard at breakfast and lunch was: "How is portability really possible on a platform thatdo
esn't have Microsoft COM baked into its infrastructure?"
Hejlsberg:
It's completely possible. COM is not a must for standardization of C# and a common language infrastructure. Not at all. C# has a class model that is completely rich, whereas COM is just another view of how applications can interoperate. But there's nothing in C# or the core common runtime that says there must be COM, GUIDS, HRESULTS, AddRefs, or Releases. There's none of that. The .NET common language runtime completely eliminates that. But it gives you great interoperability with COM, which I will continue forever to think is super important for the reason I gave earlier. But it's not a prerequisite at all.
Goodhew:
I think some of those comments were inspired by the initial version of the language reference that we provided to the public. Microsoft wrote it in Microsoft meetings in which we were thinking primarily in terms of Microsoft platforms. As a result, we make references to things like COM and DLLs in the spec when really a DLL is a specific case of the more general problem of how to invoke native code on a given platform. One of the benefits of going to a standards organization and working with people like IBM, with whom we worked on the SOAP specification, is that we ensure wedo
n't make any such references that tie us or lock us into something like the COM framework in future versions of the specification.
As Anders said, COM interop and COM support is critically important to us and to existing Microsoft customers. I think we'vedo
ne a great job supporting COM on the .NET platform. But people in the industry have been reading too much into our use of the words COM and DLL. They conclude that the .NET platform is for Windows platforms only, and that's absolutely incorrect.

Hejlsberg:
And I think that just as COM interop is important to Microsoft and to customers who are building solutions on Microsoft platforms, a standardization of C# and the common language infrastructure should allow for other implementations to add meaningful interop with any platform on which they choose to implement the language.
Osborn:
So you won't insist on there being a "pure C#" or a "pure .NET" implementation?
Hejlsberg:
What's "pure?" How many "pure" Java applications really exist? I venture to guess very, very few. That's what the numbers I'm seeing suggest. Let's face it, people need to leverage their existing code. It's just not possible to require companies to throw everything away.
Goodhew:
Have you had a chance to talk to Roger Sessions? [Editor's Note: Roger Sessions is president of ObjectWatch and the author of COM+ and the Battle for the Middle Tier.]
Osborn:
No, I haven't.
Goodhew:
Roger got the relevant section out of the Enterprise JavaBeans [EJB] specification, which talks about permissible vendor extensions. Not surprisingly, the vendor extensions include things like transactions management, which is fairly important in building enterprise systems, as well as security, messaging, and more. In an article, Sessions lists roughly eleven areas of functionality, which are vendor specific implementations that are permitted. So, if you pick IBM Websphere as your EJB implementation, the code that you write for your EJB application will inevitably lock you into Websphere. This notion that Java is 100% pure and gives you 100% portability just isn't true. There's a great interview with James Gosling on IBM's developer works site in which he directly addresses this issue. He said, yeah, the whole write-once-run-anywhere, 100%-pure-thing was a really goofy idea, and was more of a marketing thing. He says, in effect, "We didn't think we'd ever be able to deliver all that, and basically we haven't." Here's the inventor of the language saying that neither purity nor portability exists.
Osborn:
Have we missed any untold great features or innovations in C# that you'd like to talk about?
Hejlsberg:
There's one thing about the whole .NET framework and, by implication, about C# as well, that I'd like to mention, and that's the shift in how you build distributed applications. Not so long ago we were building two-tier client server apps, and then
object protocols such as CORBA, IIOP, RMI, and DCOM came along. That type of programming is really the underpinning of an EJB, which is implemented as either CORBA or RMI underneath. We have learned to build these strongly connected distributed systems, but theydo
n't scale. They justdo
n't scale on the Web because they're stateful, they hold state on the server, and you can't just roll in another machine, plug it into the farm and have the thing replicate itself.
When we first satdo
wn to design the .NET framework we took a step back and looked at what's actually happening on the Web. It's becoming this loosely connected, very distributed world, and we tried to understand what thatdo
es to your underlying programming model. And so we designed from the ground up with the assumption in place that distributed apps are built in a loosely connected, stateless fashion that gives you great scalability. You just scale out. You roll in more racks and plug them in. And once you make that fundamental assumption, it changes everything. It changes how you design your basic services, how you design all your messaging, and it even changes how you design your UI. It's a new programming model. We have chosen to use XML and SOAP as the means to make this model work. They are deeply integrated into .Net and this integration is so core to every decision we have made in designing the .NET framework that it's not something you could just walk in and sprinkle on later.

Osborn:
Could you point to one specific place where this would be evident to a programmer?
Hejlsberg:
One fairly good example of this is how XML integrates with C#. We have this notion of "attributes" in C# that allows you to add declarative information to types and members. Just as you can say a member is public or private, you also want to be able to say this one's transacted, or this one's supposed to be a Web service, or this one is supposed to be serializable as XML. So we've added attributes to provide this generic mechanism, but then
we utilize it in all of our Web services and XML infrastructure. We also give you the ability to put attributes on classes and on fields in your classes that say: "When this class goes to XML, it needs to become "this" tagname in XML and it needs to go into "this" XML namespace. You want to be able to say a specific field in one place becomes an element, and that another becomes an attribute. You also want to control the schema of the XML that goes out;
control it where you're writing your class declaration, so that all of the additional declarative information is available. When attributes are properly used in this way to decorate your C# code, the system can simply turn a specific class into XML, send it over the wire, and when it comes back we can reconstitute the object on the other side. It's alldo
ne in one place. It's not like additional definition files or assorted infos and naming patterns. It's right there. It gives you statement completion when you build it in the IDE, and we can then
provide you with higher-level tools thatdo
the work for you.
I know I'm on a tangent here, but some of the infrastructure we provide is truly exciting. Simply because we have these attributes, you can ask our XML serialization infrastructure or our Web services infrastructure to translate any given class into XML. When youdo
, we'll actually take the schema for the class, the XSD schema, and we'll build a specialized parser that derives from our generic XML parser (which is part of the .NET base classes), and then
override methods and add logic into the parser so that it is specialized for that schema. So we've instantiated a parser that at native code speed can rip through XML. If it's not correct, we'll give you a nice error message, which tells you precisely what went wrong. then
we cache it in our code-caching infrastructure, and it sits around until the next time a class with an identical schema comes by and it just goes, "Bam!" I mean, incredible, incredible throughput.

Osborn:
So, there's a lot of really interesting engineering under the covers.
Hejlsberg:
Yeah, and I just think that we're a generation ahead when it comes to the thinking in this space.
Osborn:
Great. Thanks for your time.
Hejlsberg:
You're welcome.
 
我也顺便从oreilly摘篇关于.net与j2ee的对比:
Even if youdo
n't write code dedicated to Microsoft platforms, you have probably heard by now about Microsoft .NET, Microsoft's latest volley in their campaign against all things non-Windows. If you've read the media spin from Microsoft, or browsed through the scant technical material available on the MSDN site, or even if you attended the Microsoft Professional Developers' Conference (where the .NET platform was officially "launched"), you're probably still left with at least two big questions:
What exactly is the .NET platform?
Howdo
es the .NET architecture measure up against J2EE?
And, if you think more long-term, you might have a third question rattling around your head:
What can we learn from the .NET architecture about pushing the envelope of enterprise software development?
The .NET framework is at a very early stage in its lifecycle, and deep details are still being eked out by the Microsoft .NET team. But we can, nevertheless, get fairly decent answers to these questions from the information that's already out there.
What is it?
Current ruminations about .NET in various forums are reminiscent of the fable of the three blind men attempting to identify an elephant: It's perceived as very different things, depending on your perspective. Some see .NET as Microsoft's next-generation Visual Studio development environment. Some see it as yet another new programming language (C#). Some see it as a new data-exchange and messaging framework, based on XML and SOAP. In reality, .NET wants to be all of these things, and a bit more.
First, let's get some concrete details. Here's one cut at an itemized list of the technical components making up the .NET platform:
C#, a "new" language for writing classes and components, that integrates elements of C, C++, and Java, and adds additional features, like metadata tags, related to component development.
A "common language runtime", which runs bytecodes in an Internal Language (IL) format. Code and objects written in one language can, ostensibly, be compiled into the IL runtime, once an IL compiler is developed for the language.
A set of base components, accessible from the common language runtime, that provide various functions (networking, containers, etc.).
ASP+, a new version of ASP that supports compilation of ASPs into the common language runtime (and therefore writing ASP scripts using any language with an IL binding).
Win Forms and Web Forms, new UI component frameworks accessible from Visual Studio.
ADO+, a new generation of ADO data access components that use XML and SOAP for data interchange.
Howdo
.NET and J2EE compare?
As you can see, the .NET platform has an array of technologies under its umbrella. Microsoft is ostensibly presenting these as alternatives to other existing platforms, like J2EE and CORBA, in order to attract developers to the Windows platform. But howdo
the comparisons play out item-by-item? One way to lay out the alternatives between .NET and J2EE is shown in the following table:
Microsoft.NET J2EE Key differentiators
C# programming language Java programming language C# and Java both derive from C and C++. Most significant features (e.g., garbage collection, hierarchical namespaces) are present in both. C# borrows some of the component concepts from JavaBeans (properties/attributes, events, etc.), adds some of its own (like metadata tags), but incorporates these features into the syntax differently.
Java runs on any platform with a Java VM. C# only runs in Windows for the foreseeable future.
C# is implicitly tied into the IL common language runtime (see below), and is run as just-in-time (JIT) compiled bytecodes or compiled entirely into native code. Java code runs as Java Virtual Machine (VT) bytecodes that are either interpreted in the VM or JIT compiled, or can be compiled entirely into native code.

.NET common components (aka the ".NET Framework SDK") Java core API High-level .NET components will include support for distributed access using XML and SOAP (see ADO+ below).
Active Server Pages+ (ASP+) Java ServerPages (JSP) ASP+ will use Visual Basic, C#, and possibly other languages for code snippets. All get compiled into native code through the common language runtime (as opposed to being interpreted each time, like ASPs). JSPs use Java code (snippets, or JavaBean references), compiled into Java bytecodes (either on-demand or batch-compiled, depending on the JSP implementation).
IL Common Language Runtime Java Virtual Machine and CORBA IDL and ORB .NET common language runtime allows code in multiple languages to use a shared set of components, on Windows. Underlies nearly all of .NET framework (common components, ASP+, etc.).
Java's Virtual Machine spec allows Java bytecodes to run on any platform with a compliant JVM.
CORBA allows code in multiple languages to use a shared set of objects, on any platform with an ORB available. Not nearly as tightly integrated into J2EE framework.

Win Forms and Web Forms Java Swing Similar web components (e.g., based on JSP) not available in Java standard platform, some proprietary components available through Java IDEs, etc.
Win Forms and Web Forms RAD development supported through the MS Visual Studio IDE - no other IDE support announced at this writing. Swing support available in many Java IDEs and tools.

ADO+ and SOAP-based Web Services JDBC, EJB, JMS and Java XML Libraries (XML4J, JAXP) ADO+ is built on the premise of XML data interchange (between remote data objects and layers of multi-tier apps) on top of HTTP (AKA, SOAP). .NET's web services in general assume SOAP messaging models. EJB, JDBC, etc. leave the data interchange protocol at the developer's discretion, and operate on top of either HTTP, RMI/JRMP or IIOP.
The comparisons in this table only scratch the surface. Here's an executive summary of .NET vs. J2EE:
Features: .NET and J2EE offer pretty much the same laundry of list of features, albeit in different ways.
Portability: The .NET core works on Windows only but theoretically supports development in many languages (once sub-/supersets of these languages have been defined and IL compilers have been created for them). Also, Net's SOAP capabilities will allow components on other platforms to exchange data messages with .NET components. While a few of the elements in .NET, such as SOAP and its discovery and lookup protocols, are provided as public specifications, the core components of the framework (IL runtime environment, ASP+ internals, Win Forms and Web Forms component "contracts", etc.) are kept by Microsoft, and Microsoft will be the only provider of complete .NET development and runtime environments. There has already been some pressure by the development community for Microsoft to open up these specifications, but this would be counter to Microsoft's standard practices.

--------------------------------------------------------------------------------
Read more on the .NET platform in this in-depth interview by O'Reilly Windows editor John Osborn:
Deep Inside C#: An Interview with Microsoft chief architect Anders Hejlsberg--John gets to the bottom of not only Microsoft's detailed plans for the C# programming language but also the .Net framework.

--------------------------------------------------------------------------------
J2EE, on the other hand, works on any platform with a compliant Java VM and a compliant set of required platform services (EJB container, JMS service, etc., etc.). All of the specifications that define the J2EE platform are published and reviewed publicly, and numerous vendors offer compliant products and development environments. But J2EE is a single-language platform. Calls from/to objects in other languages are possible through CORBA, but CORBA support is not a ubiquitous part of the platform.
The Bigger Picture
These last points highlight some of the key differentiators between .NET and J2EE, and point towards Microsoft's real play here. Microsoft isdo
ing two very notable things with .NET: It is opening up a channel to developers in other programming languages, and it is opening up a channel to non-.NET components by integrating XML and SOAP into their messaging scheme.
By allowing cross-language component interactions, .NET is enfranchising Perl, Eiffel, Cobol, and other programmers by allowing them to play in the Microsoft sandbox. Devotees of these languages are particularly amenable to gestures like this, since for the most part they have felt somewhat disenfranchised and marginalized in the Microsoft/Sun/Open Source wars. And by using XML and SOAP in their component messaging layer, Microsoft is bolstering their diplomatic face and adding an element of openness to their platform, providing ammunition against claims of proprietary behavior.
What's the correct response?
For Microsoft developers:
.NET is a good thing for those of you committed to Microsoft architectures. ASP+ is better than ASP, ADO+ is better, but different, than ADO and DCOM, C# is better than C and C++. The initial version of .NET won't be real until sometime in 2001, so you have some time to prepare, but this will undoubtedly become the default development environment for Microsoft platforms. And if you're developing within the Microsoft development framework now, you will undoubtedly benefit from adopting elements of the .NET framework into your architectures.
However, several of the goals of the .NET platform are fairly lofty and not at all guaranteed to fly, at least not in the short term. The IL common language runtime, for example, has some fairly significant hurdles to overcome before it has any real payoff for developers. Each language that wants to integrate with the component runtime has to define a subset/superset of the language that maps cleanly into and out of the IL runtime, and has to define constructs that provide the component metadata that IL requires. then
compilers (x-to-IL and IL-to-x) will have to be developed to both compile language structures (objects, components, etc.) into IL component bytecodes, and also generate language-specific interfaces to existing IL components.
There is some historical precedence here. Numerous bridges from non-Java languages to the Java VM have been developed, such as JPython, PERCobol, the Tcl/Java project, and interestingly enough, Bertrand Meyer and some other Eiffel folks put together an Eiffel-to-JavaVM system a few years back. With the possible exception of JPython, these tools have not been widely adopted, even within their respective language communities, even though they seem to offer a way to write code for the Java environment (albeit not the entire J2EE framework) using your favorite language. Why this lack of enthusiasm? I believe it's because people are hesitant to take on the headaches of adding yet another translation step from their development language to the target framework. If the Java environment is the goal, people will generally choose to learn Java. I predict that the same will be true of .NET: People will generally choose to learn C# and write .NET components in that language.
Another caution: Beware of performance issues with .NET's SOAP-based distributed communications. SOAP essentially means XML over HTTP. HTTP is not a high-performance data protocol, and XML implies an XML parsing layer, which implies more compute overhead. The combination of both could significantly reduce transaction rates relative to alternative messaging/communications channels. XML is a very rich, robust metalanguage for messaging, and HTTP is very portable and avoids many firewall issues. But if transaction rates are a priority for you, keep your options open.
For the Java and Open Source communities:
It would be easy to dismiss .NET as more Microsoft marketing-ware and continue on your merry way. Butdo
n't. .NET is a sign of a subtle but significant shift in Microsoft's strategy to evangelize their platforms. They have been fighting alternative frameworks and platforms at the management level pretty well, touting the usual questionable "statistics" about cost of ownership and seamless integration. Now they are fighting Java and open source initiatives on their own terms, putting their own spin on "open" and attempting to directly address the needs of developers, two things that they have been faulted for notdo
ing very well in the past. If you consider yourself an evangelist for Java or open source platforms, then
the nature of the war is changing. Be prepared.
Also, Microsoft's IL runtime has at least one notable, if improbable, goal: eliminate the programming language as a barrier to entry to the framework. Java eliminates the platform barrier (within limits, of course: You can't make up for missing hardware resources with software, for example), but in order to work in J2EE, you have to work in Java. .NET wants to let you use the language of your choice to build .NET applications. This is admirable, though there are big questions as to whether and when the IL approach in .NET will actually become broadly useful (see above). Regardless, this points to a weakness in the single-language J2EE approach. The importance of this weakness is questionable, but it exists nonetheless, and deserves some consideration by the Java community. If this is really desired by developers, then
maybe the efforts in Java bytecode generators for non- Java languages should be organized and consolidated.
Focusing on J2EE, there are a few issues that should be addressed immediately in order to bolster the advantages of that platform compared to what .NET is shooting for. First, XML support needs to be integrated seamlessly into the framework. I'm not talking about bolting an XML SAX/DOM parser to the set of standard services, or extending the use of XML in configuration files. XML messaging and manipulation need to be there, ready to use. Admittedly, you can use XML payloads on top of JMS messaging, but the platformdo
esn't facilitate this at all. The XML space is a cluttered mess of standards, de facto standards, APIs and DTDs, which is to be expected when you're dealing with a meta-language.
But Microsoft has put a stake in the ground with SOAP, and they're pushing hard to put something understandable and useful in the hands of developers. J2EE proponents need todo
the same with their platform. One possibility that comes to mind is to add an XML messaging "provider" layer on top of JMS, along the lines of the pattern followed by Java Naming and Directory Interface, or JNDI, with LDAP, NIS, COS Naming, etc. This in combination with a standard SOAP/BizTalk provider, an ebXML provider, etc. would be an impressive statement.
 
我靠!一个字也看不懂. :-(
 
大家觉得这是好事还是坏事?
 
这玩意有点神奇!听说的。
好事!以后大家不用再争VC和BCB、Delphi谁好谁坏了,反正你们说的优点都会在C#中体现
出来,全都用C#了。哈哈!!!
 
我记得有个网站好象有C#的中文资料的。csdn也有。
 
〉defox:那个网站?
 
我靠....
真得很牛啊
虽然觉得有些象是空中楼阁,但是Turbo Pascal 和Delphi的设计师,还有微软一起合作,
看起来是真的呢。
那程序员的好日子到了,还是黑暗的日子到了呢?
看来自动编程机器人的日子已经为时不远啦~~
以后我们的目标,就是用c#写自动编程程序拉 ~~~
 
http://www.chinaasp.com
http://www.csdn.net
都有关于C#的中文资料
 

Anders Hejlsberg早就被挖到micro$oft了啊,呵呵,主持开发了VJ++
C# sounds good, ;)
不过,我还是很期待 borland 的 Kylix, ;)
 
我认为C#只不过是Java的玩意。
 
C#也许不久跟大家见面了吧.据<中计报>最近消息,
预览版的MS Visual Studio.net中会有它的存在.
销售可能要等到2001年秋左右了.
 
还是认真学习VC++和delphi吧,相信有什么自动机器人,如果真有的话,那微软公司不是
喝西北风?!
 
大家可以到www.vctop.com上面有C#语言介绍!
 
怎么现在没有预览版或者beta版下载啊,这不是微软最喜欢做的吗
 
接受答案了.
 
后退
顶部