Weight-Transfer particle space: C #, natural progress

Source: Internet
Author: User
Tags definition export class garbage collection inheritance new features thread web services visual studio
C #, Natural progress
With Visual J + + fading, Microsoft introduced C # to fill this gap

Michael L. Perry.
Mallard Software Designer
August 2000

Microsoft's new vision of the Internet is a far cry from the web of today's online content. Microsoft foresees the future of the Internet as an interconnected service developed by different people in different languages on different hardware platforms that can be run on different internet operating systems.

The company offers the. Net Platform for the bold vision of this new world. In fact,. NET is not a traditional platform;. NET is actually a collection of protocols that allows Internet applications to take advantage of different services running on different machines.

The result of Microsoft's new strategy is that the next generation of Microsoft Visual Studio will have a redesigned language, especially to support the. Net platform. Java will no longer be in this package, and Visual J + + will no longer have a new version. Don't worry, Microsoft will launch a new language C # to fill this gap. The company uses its best resources, including star language expert Anders Hejlsberg, to develop C #.

Non-he: Anders Hejlsberg, language architecture architect
Considering Hejlsberg's experience, it would not be surprising that Microsoft gave him the responsibility. After all, C # will not be his first big overhaul of the way software is developed.

As Borland's chief architecture architect, Hejlsberg secretly turned Turbo Pascal into an object-oriented, truly visual environment and an application development language that features exceptional database access. Once touted as "VB killer" of the Delphi is still Borland (now Inprise/borland) of the fist products.

After hiring Hejlsberg with generous salaries, stock options and huge franchise bonuses, Borland has filed charges of recruiting new members by improper means. Borland also claimed-provided little detail to support the allegation that-hejlsberg was developing "Delphi for Java". The lawsuit ended with a Borland victory, but since then Microsoft has been letting Hejlsberg work.

Hejlsberg enriched Microsoft's Java products, and it was particularly noteworthy that in order to keep up with the current version number of other Visual Studio languages, he artificially raised his version number from 1.1 to 6.0 in a release. In fact, this version of the jump does not exaggerate the difference between 6.0 and its previous version. Hejlsberg added functionality has made the language a powerful Windows application development platform. Added features include access to Windows APIs, so programs that take advantage of these new features are no longer portable.

Hejlsberg changes to Microsoft's Java products prompted Sun to sue Microsoft for violating the Java License Agreement. Sun claims that the Visual J + + language extension does not maintain Java platform neutrality, but rather locks developers on the Microsoft platform. Although Microsoft's Visual J + + is in fact the best Java compiler, and the company's virtual machine (the Run-time module that executes Java bytecode) is the fastest type of VM, Sun's lawsuit has effectively blocked Microsoft's competition in the Java arena.

Microsoft's response was to completely exit from Java and replace it with a new basic internet Platform-.net-and a new banner language-c#. Anders Hejlsberg is the natural choice for completing the latter work.

Proving the rationality of a new programming language
Some recent news about C # Controversy claims that developers will not accept another programming language. While it is true that there are several useful languages available for developers to use, there is still room for another language-if it fills a need that is still unmet. A new language is, after all, just another tool that professionals can use to create software solutions. Let's analyze Microsoft's goals for C # and other languages that have so far not met these goals.

Rapid application development: one of the most important goals Microsoft has set for C # is to support RAD. Internet applications must be developed in the rhythm of the Internet; a new language must be easy to learn and debug, and must generate easily updated code. Although Delphi and VB are excellent in these respects, but C + + is not so successful. The language itself is complex and difficult to master, and few useful C + + libraries provide a simple interface. In addition, the manual memory management of C + + and the complex type conversion model make it difficult to debug.
Also, as we'll see below, C + + essentially does not prevent potential problems caused by version incompatibility. Although Microsoft and Borland have made great efforts in this language, C + + is still not suitable for rapid application development.



Cross-platform deployment: By definition, the Internet language should support cross-platform deployments. Because the internet is a network of different systems, services must be deployed to a wide variety of hardware and software. In addition, client software should be able to run on multiple types of devices, including PDAs and cellular cordless telephones. This flexibility is, in fact, a challenge for all languages except Java. VB, in particular, can only generate Windows applications that run on intel-based microprocessors. Delphi is also subject to the same restrictions. Delphi for Linux will soon be released, but it also does not support Internet devices. Both VB and Delphi do not meet the goal of Cross-platform deployment.


Access to the resources inherent to the platform: according to Microsoft, developers need access to the resources inherent to the platform. This access is sometimes essential for writing powerful target applications. Visual J + + 6.0 allows developers to access Windows Api,java typically does not allow such access. Java provides cross-platform deployments by defining the minimum common denominator standards that each virtual machine implements. Java developers write code based on this weakened standard, rather than leveraging more powerful services that only some platforms offer. In this way, Java does not meet the goal of providing access to the inherent resources of the platform.


Support for COM and. NET platforms: Microsoft has identified support for COM and. NET platforms as the most important goal of C #. Of course, no language currently supports the. Net platform because it is still being built. Unlike. Net, COM has been there for quite some time, but it still lacks strong language support. Most languages, including C + + and Delphi, require developers to create an additional IDL declaration, a class factory, and a dedicated adornment for each COM object that they create.
Some language vendors have provided wizards to automate many of the common COM and OLE tasks, but these tools do not completely hide the complexities of COM. VB does successfully hide the complexity of COM, but it is at the expense of the function for the price. VB not only lacks the power of object-oriented language, it also cannot support low-level functions of COM-for example, multiple interfaces, aggregation, and custom choreography. In short, there is no existing language that fully supports COM like C #.

Although these four goals are quite high for a new language, Hejlsberg has come up with his best experience at work to ensure that C # achieves these goals. The result is a language that borrows as much from Java and Delphi as it borrows from C and C + + (if not more). Please note that the following information is based on the C # operating procedure and may not accurately represent the final product release.

C # is a RAD environment

C # provides Java-style garbage collection: One of the most important RAD features provided by C # is Java-style garbage collection. Any objects that are not referenced are automatically deleted at any time during the runtime. By freeing developers from manual memory management tasks, garbage collection makes program development easy and error-prone. However, automatic garbage collection is time-consuming and unpredictable. As a result, C # allows developers to partially disable garbage collection in the event of real-time performance requirements-by marking code as unsafe.


C # Implements the Java and Delphi-style value/reference type system: To further support rad,c# always process the C + + pointer model with a Java and Delphi-style value/reference type System. In this system, built-in types (integer, real, string, and so on), enumerations (enumeration), and structs (structure) are value types. The assignment and comparison operators copy and examine the values of these types of variables. interfaces, classes, and authorizations (which will be described later) are reference types. The assignment and comparison operators copy and examine the identity of objects referenced by these types of variables.
This value/reference type system is much simpler than the C + + pointer model. It makes it easier to handle objects and eliminates many memory errors that plague C and C + + programs.



C # interfaces are declared independent of classes: C # also supports interface models like Java and Delphi, which are declared independently of classes. This is opposed to the C + + model, where interfaces are actually abstract base classes. Interfaces and classes can inherit multiple interfaces. The class can inherit a base class, and the interface cannot inherit the class at all. This model avoids multiple inheritance problems in C + +, and implementations in different base classes in C + + may conflict. Therefore, complex mechanisms such as virtual inheritance and explicit scopes are no longer needed. C # 's simplified interface model helps to accelerate application development.


The Declaration and definition of a class method are grouped together: Another aspect of C # 's simplification is the combination of declarations and definitions of class methods, much like the Java approach. C + + developers must maintain separate files for the declaration (header file) and definition (implementation file), resulting in complex software development processes. C # can even automatically find relationships between source code modules, freeing developers from an additional chore. Although C + + needs to use the #include (Delphi needs to use uses) to locate the relevant source files, C # does not require any additional statements.


C # uses method references, called authorization, instead of method pointers: C # uses method references to quickly connect objects and methods. These methods, called authorizations, refer to a process type similar to Delphi. Hejlsberg also introduced the same mechanism into Visual J + + 6.0, but it is not part of the standard Java specification. A method reference is somewhat like a C + + method pointer, but it is superior, secure, and much more useful.
Authorization is a reference type that holds the signature of the method. An application can assign any method that conforms to this signature to an authorization variable. When this authorization variable is invoked, the associated method is invoked. Unlike the Delphi process type, C # authorizes automatic multicast support. An application can assign many methods to an authorization variable, and all methods are invoked when this variable is called.



C # uses Java's simple thread synchronization mechanism. To implement thread synchronization in C #, developers only need to flag critical blocks of code. Java developers use the Synchronized keyword, and C # developers use lock. A hidden mutex wraps a flagged block of code, allowing only one thread to execute the code at any one time. In addition to the keywords, this mechanism is identical in C # and Java. Because threading is one of the most error-prone programming tasks, any feature that simplifies synchronization can help rapid application development.


Explicit overload declaration: Finally, C # supports RAD with an explicit overload declaration. An explicit overload declaration supports rapid application development by protecting the method namespace of the class and indicating unexpected naming conflicts.
The developer of the C # export class must explicitly tag the method overload with the keyword override, as it did in Delphi. If the derived class contains an unmarked method with the same name as a virtual method in the base class, the compiler cannot explicitly distinguish the author's intent.

On the other hand, naming conflicts can be unavoidable, especially when base classes and export classes are implemented by different programmers, who may work for different companies. In this case, the compiler emits a warning and treats the method of the exported class as a new declaration, rather than as an overload.

On the other hand, if a programmer intentionally makes a new method in an exported class with the same name as a virtual method in a base class, he or she can use the New keyword to prevent the compiler from issuing a warning.

Other features of C #
Considering all the language features that have just been discussed, strong support for RAD appears to be one of Microsoft's most important goals for C #. However, C # must also focus on other important development requirements. These requirements include cross-platform deployments, access to the resources inherent in the platform, and support for COM and. Net platforms. Let's analyze the C # language features that are designed to support these requirements.

Cross-platform deployment: C # solves the problem of cross-platform deployments in the same way that Java solves this problem. The C # compiler generates a bytecode stream that is interpreted by the. Net Runtime. A run-time component works much like a Java virtual machine, and an application can be deployed to any device that has the. Net runtime installed.


Application access to platform-inherent resources: Unlike Java virtual machines, the. Net runtime allows programs to access the resources inherent to the platform. For example, a C # program can take advantage of the Windows API to run as a fully functional application on Windows 2000. By using a subset of Windows CE APIs, the same program can also be run on a PDA. Of course, not all the services that the application expects are available on all devices. Therefore, it is the responsibility of the developer to test the software on all target platforms, and developers can write special case code if necessary, which will enable the system to still work when the required services are missing.


Support COM and. NET: In order to support COM and. NET platforms, C # contains a unique language attribute called attributes. A property is actually a C # class that provides meta information by modifying the source code. property enables C # to support specific technologies, such as COM and. Net, without interfering with the language specification itself.
For example, C # provides an attribute class that converts a C # interface to a COM interface. Other attribute classes convert a C # class to a COM class. Performing these transformations does not require any IDL or class factories. Some language watchers claim that all C # classes are COM objects. This is not true-but with the appropriate properties, any C # class can easily be converted to a COM object.

Another property library that is provided with the compiler wraps C # classes and functions as WEB services. WEB services are managed software modules that can be invoked on the Internet via an interactive protocol, such as SOAP. SOAP Wraps method calls with their arguments and return values in an XML packet. Web services can be written in many languages and deployed to many hardware and software platforms. Also, different types of Web services can collaborate to make up the entire Web application. By using the correct attributes, it is easy for a programmer to convert any C # class or function into a Web service.

C # features that are not available
Consistent with the experience of Anders Hejlsberg, many of the features that C # uses to support Internet applications are selected from Delphi and Java. Microsoft asserts that C # was transformed from C and C + +. So let's analyze some C + + features not available in C #.

Scope and non-associative operators: C # does not use the C + + scope operator (::); it relies on similar point operators (.) in Delphi and Java. In addition, because it is based on the Java and Delphi-style value/reference type system described previously, in most cases C # does not use C + + non-associative accessors (->), but again implements the dot operator. Although overloaded dot operators may confuse C + + programmers who are just beginning to learn C #, this is quite familiar to Java and Delphi developers.


Reference declaration syntax: Because classes, interfaces, and authorization types are references by default, C # does not have a reference declaration syntax for C + +. Instead, the new language uses syntax similar to the Delphi declaration that passes arguments by reference:
Unmarked parameters are input parameters
Ref keyword specifies an input/output parameter (similar to Delphi's Var)
Out keyword specifies an output parameter
Params keyword Specifies a variable-length argument list (similar to the variant Open-array parameter of Delphi)



Templates: Like Java and Delphi, C # has no templates. As a result, C # does not have a mechanism for declaring collections of type security. Each class is ultimately derived from the common base class object. A generic collection class must be an object collection, and it needs to convert its members to an unsafe subsurface type to the desired type.
Despite these language features of C + +, C # is still a powerful programming language designed to support Internet applications around features like Java and Delphi. Because of the machine-level focus of C + + and the lack of RAD support, it is not the basis for an Internet application development language. If the C + + developer needs to write applications and services for the. Net platform, it will be highly recommended to learn the language after the C # release-remember that its actual difference from C + + is much greater than that of their names.

In this transition, it is best to learn Java or Delphi. Not only do these two languages give you a better understanding of C #, but they are also very useful languages in themselves. As software professionals, we should take advantage of the best available tools.

Author Introduction
Michael L. Perry has been engaged in professional Windows development for more than six years and has expert experience in COM +, Java, XML, and other technologies that currently shape the future of programming. He founded the Mallard Software Designs in 1998, where he used mathematical rigor to prove software design-the correctness of the solution before implementation.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.