Thinking in Delphi: Language Change

xiaoxiao2021-03-06  89

Thinking in Delphi: Language Change

Delphi Language Birth

In November 2003, Borland officially released the latest version of Delphi: Delphi 8 for Microsoft .NET Framework. If its name is revealed, Delphi 8 no longer supports development under Win32 platform, but is completely based on Microsoft .NET Framework. There is no doubt that this has brought revolutionary changes to Delphi, and let a computer programming language to the most interested place, it is more interested in Delphi 8 to the language itself. As we all know, Delphi brings OO's ideology into traditional Pascal to create a famous Object Pascal language. Since Delphi 1, Object Pascal has been constantly improving. However, in the process of upgrading from Delphi 7 to Delphi 8, it is not only a fundamental change in the programming model, but the language itself has also been largely expanded and improved. The result is that it is almost a new language. In this article, the language used in Delphi 8 is referred to as Delphi Language, which is different from the previous Object Pascal. Starting from Delphi 7, Borland has called Object Pascal as Delphi Language. However, the language in Delphi 7 has not changed fundamental changes compared to previous versions, which is actually in Delphi 8. Therefore, in this article, the language used in Delphi 8 is referred to as Delphi Language, and the language used in previous versions of Delphi is called Object Pascal. Delphi Language adds support for the following characteristics: Namespace, Nested type, Class Static Method and Class Property, enhanced, sealing of records Sealed Class and Final Method, Multicast Events Mechanism, Operator Overload, Boxing / Unboxing Mechanism, and so on. The comparison between different programming languages ​​is a very easy thing to bring controversy. However, in many cases, this comparison seems to be inevitable. In particular, when the programming language is innovative, the horizontal comparison between the language is often more clearly seen in this innovative essence. Therefore, when Delphi Language is in the world, it has become a temptation with other mainstream programming languages. In the following, the author will perform this comparison. The selection criteria for the language compared to Delphi Language are like this:

Must be a universal language instead of a dedicated language. Must be a strong type, compiled or semi-compiled language instead of explaining the scripting language executed. It must be a language that fully supports object-oriented programming (OOP) (this will be excluded from the language of C, although C is still one of the mainstream industrial language standards now).

This kind of choice may not be suitable, however, this comparison only shows the conclusions obtained at a particular angle, rather than trying to make advantage of these languages. Moreover, it is believed that many readers will also compare this, so that the application range and implementation are completely different, it is largely meaningful. According to this standard, C , Java, C # becomes a ministers, representing the programming languages ​​under the three main platforms of Java, .NET and native code, respectively. Visual Basic .NET is too similar to C #, the author believes that there is no need to increase it. The predecessor of Delphi Language is also added as a reference. Language characteristics

As someone pointed out, the relatively susceptibility between the language is susceptible to subjective, so the author should limit the scope of the comparison to the level of the empirical language characteristics, and how much controversy is basically no existence for these issues. Table 1 lists the comparisons of these languages, Y represence is, n indicates no.

Table 1 Language characteristic comparison table

Note 1: Java is converted between the basic types and objects through the wrapped class, while .NET provides support in the syntax level, and this feature is built in the virtual machine's instruction set. Therefore, only Java partially supports boxing / unboxing. However, there is a message saying that Java will provide a Boxing / UNBoxing mechanism to support similar .NET in future releases. C and Object Pascal do not support boxing / unboxing. Note 2: Sun has announced that generic programming will be supported in JDK 1.5. Microsoft also announced will support generic programming in the next version of C #. About this discussion is very rich. On the Borland Conference in November 2003, Delphi's development team also announced a similar plan. Note 3: Object Pacsal can support retrieval of the properties and methods of uncertain objects, which is also one of the foundation of the Delphi component mechanism by built-in RTTI. But Object Pacsal does not support dynamic generation classes, so it can only be said to support the reflection.

As you may think, this table is far less complete, even in these features listed, there are many situations that are not only "Yes" or "No" can be summarized. At this point, you can see from a few lengthy annotations from the table. In fact, there are some main differences that are not listed in this table. Since they are so complex, it is not possible to simply use "YES" or "NO" to be placed in a table, but must be discussed specifically.

Operating platform

From the surface, there is no inevitable connection between the programming language and the platform on which it is running, but this is not the case. Below is the correspondence between these languages ​​and run platforms:

Table 2

Dr. Bjarne Stroustrup in C said a very well-known: "Java is not cross-platform, Java is a platform." Whether the conclusion of the previous sentence is appropriate, the latter is unpleasant. Therefore, the JVM is listed here as a platform. According to the same logic, the running platform of Delphi Language and C # is .NET CLR. From the above table, we can find such a phenomenon that Java and C # These two purely object-oriented languages ​​are virtual machines. That is to say, these languages ​​running on virtual machines do not support global variables and global methods. The Object Pascal and C These two-style programming languages ​​are running on the native platform. After thinking about this phenomenon, it may be possible to draw the following conclusions: all mainstream operating systems, including Windows, Linux, and UNIX, the underlying is developed by C or assembly language, and the APIs provided are both C styles. Therefore, the programming language running on the native platform must support the global variables and global methods of C style, while the virtual machine can bypass this limitation, providing pure object-oriented programming models. An interesting trend is that Microsoft is gradually approaching purely object-oriented operating system by transferring the operating system from Win32 .NET. An important exception to this conclusion is Delphi Language. It is like Java and C #, running on the virtual machine, but it still supports global variables and global methods, in other words, still supports process-oriented programming styles. This feature of Delphi Language should be considered for backward compatibility. Programmers, they want to transfer to the .NET platform with small cost as much as possible. However, the appearance of this phenomenon illustrates a problem, that is, .NET's unity of programming languages ​​is not as serious as people guess. After the .NET's CLS release, people have guess all programming languages ​​under the .Net platform. This view may be correct in 4 languages ​​supported by Microsoft (Visual Basic.net, C #, Visual J #, Managed C ), but it is not necessarily correct for other languages. In theory, any language can support .NET as long as the minimum rule set specified in CLS is met, but CLS does not limit the extension of these languages, as long as their compiler can generate a normative .NET code. Delphi Language is an example in which it retains the ability to use process-oriented programming on a purely object-oriented platform. Another example is Eiffel #, which achieves multiple inheritances on the .NET platform through a strong compiler. Another impact of running platforms for programming languages ​​is a Garbage Collection mechanism. Both virtual machines such as JVM and .NET CLR have a memory automatic recycling mechanism, so it has an impact on the three languages ​​of Java, C # and Delphi Language, especially in terms of object destruction. The C and Object Pascal running on the native platform do not have this mechanism, so the programmer must implement memory recycling. Yes, through certain third-party libraries, C and Object Pascal can also achieve automatic recycling, but this is not the characteristics of the language itself. Container

And container deal is the most frequently encountered work in the daily programming of developers, excellent container support, how to estimate it for a programming language, and it is not too much. In addition to the simple container of C and Pascal, no other support is provided in addition to the simplest container of array. The programmer must implement the most basic data structure such as a linked list (List). In Object Pascal, this situation has been improved. Object Pascal provides some classes as a container, implementing basic data structures, such as TLIST is the implementation of the list, TQueue is the implementation of the queue, TSTACK is the implementation of the stack, TBucketList is the implementation of the Hash Table. These classes will have no type of pointer instead of an object as an element of the container, so the programmer must be responsible for the type conversion and processing thereby, but the other more beneficial consequence is to load basic types and objects to load the container at the same time. There is no need for boxing / unboxing conversion. Starting from Delphi 6, adding containers with objects, such as TobjectList, TobjectQueue, TobjectStack, and TobjectBucketList. In actual programming, these containers are very practical, but they are still just a series of flat, inconvenient extensions, does not mean a universal solution based on object-oriented ideas. In C , the support of the container has been unprecedented. On the basis of Template and Operator Overload technology, C has developed a set of Standard Template Library (STL). STL provides a large number of container classes, which can be used as an element, or a pointer can be used as an element. At the same time, on the basis of function object technology, STL also provides a wide range of generic algorithms that are independent of the container type to perform various operations in the container. STL is so powerful and complex, so that many specialized works have discussed it. However, because of this, STL has put forward higher requirements for developers while facilitating development work. Programmers have to spend a lot of time for familiarity and using STL, in fact, most programmers encountered in work, may only account for a small part of the features provided by STL. In Java, efficiency and complexity have reached a balance. The container class in Java is completely object as an element, which is quite consistent in the way of processing, but because the container class only manipulates the Object object, the programmer must still handle the upcast (UPCAST). In addition, the basic type must be processed by the container class by programming into a wrapped object. In addition to these problems, Java provides a set of large-scale, utility-wide containers. From Java 1.2, the previous version of the container class has been greatly improved, and finally formed this look now. Java's container size, complexity, and dacom, just make programmers don't need to learn and master when spending STL, but it is enough to cope with most common needs, do not need programmers Re-implement your own container as in the C language. Practice has proved that Java's container class is very successful. Figure 1 Java container class

C # and Java also provide your own container class. At present, the size of the C # container class cannot be compared with Java, but its style is significantly different from Java. These containers are actually provided in the .NET's FCL. Since Delphi Language and C # use the same set of FCLs, its container class is basically the same as C #. Language evolution

Let's go back to Table 1 to see what the differences listed in this form will explain. From the time order, from C , go to Object Pascal, to Java, to C # and Delphi Language, you can see the evolution of programming ideas and style (but does not represent outstanding extent and practicality). C is the earliest in these languages, and it also provides the best backward compatibility: almost compatible with C language in the era of process programming era. From a market strategy, this is a very visionary move, and C has successfully appeared in subsequent in C language, but it also leads to many serious problems. For this, the inventors of C are not told. C supports complete object-oriented programming, supports Namespace, supports Nested Type, which makes it a great support for large-scale programs (this is also one of the design goals of C ). However, C also retains global variables / global functions, Structure, etc., which sacrifices the object-oriented characteristics while obtaining compatibility (of course, C 's purpose is not a pure object-oriented, but multi-style programming). In addition, C is completely unable to compare with later languages ​​on RTTI. However, C also provides complex templates and operator overload mechanisms to fully support generic programming, which is unique in these languages. In general, C is a huge, complex, profound language that maximizes backward compatibility from the transition to object-oriented programming, and pays a heavy price. . C has been explored in many front-edge fields, which are drawn by other languages, but also makes C learning thresholds too high. Object Pascal is the language of Anders Hejlsberg to expand the traditional PASCAL, which is the background of the object-oriented object-oriented programming ideas and the rise of Windows operating systems. For these two trends, Object Pascal has made a lot of optimization to adapt to them.

Object Pascal supports complete object-oriented programming, while competitors such as Visual Basic support only object-based programming. Object Pascal implements event mechanisms based on delegate, fully encapsulated Windows event processing, which makes it a great support for the development of Windows GUI programs. Object Pascal has greatly enhanced the power of RTTI and implements its own open Component mechanism on the basis of the RTTI and PME (Property, Method, Event), making Delphi a powerful component development tool.

However, the disadvantage of Object Pascal is also quite obvious, and these disadvantages are exposed one by one during long-term use. Object Pascal retains global variables / global functions, RECORD and other syntax. As C , these features provide backward compatibility, retaining process-oriented style, perhaps the benefit of efficiency. However, they also destroy the object-oriented characteristics, it is easy to cause confusion on the programming style (in theory, this should not take the programming language, but this is indeed a common situation). And C is different, Object Pascal is not a start to design a large-scale program development. Therefore, it has never supported characteristics such as namespaces and nested types, and these features are quite important for large-scale development. Object Pascal's event mechanism is too close to Windows, and when Object Pascal tries to the development of the Windows GUI program, the developers are more or less encountered in these problems when they enter other fields.

Java is a purely object-oriented example. "Everything is Object" is a slogan raised by Java and tried to implement the slogan. Unlike C and Object Pascal, Java does not maintain C style in grammar, but it does not have a historical burden of backward compatibility. Java also provides support for advanced features such as Interface in grammar. Based on all this, Java has reached an unparalleled clarity, as well as a more strong "OOP" atmosphere. Like C , Java is designed as a language that is responsible for large-scale program development, so it supports support for named space and nested types. In addition, Java supports the reflection mechanism based on RTTI technology, which has transcend Object Pascal at this point. Therefore, Java has been very successful in componentization (JavaBean is a result), which in turn has led to success of Java in distributed computing technology. In the past few years, as the rise of the network, Java has received unprecedented success. However, Java does not have no room. The emergence of .NET / C # has proved this. Compared to Java, the biggest improvement in C # may be in terms of efficiency. Like Java, C # is a purely object-oriented programming language, "everything is object." For some of the excellent language features in Java, such as single inheritance structure, interface and reflection, etc., C # also collects all. However, C # is at least different from Java at least in the following points:

C # greatly increases the importance of value types (Value Types). The value type is related to the reference type (Reference Types). In the case of processing large objects, reference type ratio types are more efficient, for small, frequent objects creation, and use value types are more efficient than reference types. In Java, all variables are reference types in addition to basic types. The value type in the C # contains basic types and struct, which are derived from System.ValeType, which can be handled as objects. The difference between Class is that Struct is a value type, created in the stack, and it is implicitly closed (Sealed), so it is more efficient than Class, which can be used as a lightweight class. C # provides some and OOP no direct relationship, but very useful syntax feature in practical applications, such as enumeration (Enum), Property, Property, Preprocessor, and multicast events ( MUTILCAST EVENTS support. In addition, C # also introduces some C support and Java is not supported, such as operator overload. In Java, all classes can be inherited. C # provides the function of the Sealed Class. Closed classes cannot be inherited. Closed classes can make the software architecture more rigorous and more efficient in operation. C # provides support for Unsafe Code. In an insecure code, C # provides a lower layer capability, which can use the C style pointer to operate directly. Its price is lost in many virtual machines, including memory automatic recycling, type security, array crosstalk check. It can clearly feel that both C # and Java are similar in many ways, but C # is more useful to practicability than Java. Whether it is the value of value type, the support of the attribute, the delegation, and the pre-processor, or the support of unsafe code is not directly related to OOP, and even destroying the "pureness" of OOP (such as pre-processor), But it is very useful in actual coding. In contrast, Java appears to be more pure, or more ideal. There may be different opinions on these two, but there is no doubt that after paying some pay prices, C # does exceed Java in efficiency and simplicity. Delphi Language is a more late language than C #, and it is also the language of our comparison language and C # most similar. Due to the provisions of CLS, the characteristics of the above C # can almost applicable to Delphi Language. However, different places with C #, Delphi Language must take into account compatibility issues with the original Object Pascal. Compared with Java and C #, the characteristics of Delphi Language can be summarized as follows:

Delphi Language has retained the original .PAS file format, which is format consisting of Interface and Implementation, which means that the category declarations and definitions are separated. This style can be traced back to C and C . In Java and C #, the statements and definitions of the class are no longer separated. Delphi Language retains global variables and global functions. .NET is a purely object-oriented programming model, C # is also a purely object-oriented language, but Delphi Language still retains global variables and global functions and support, which still maintains process-oriented style. Delphi Language supports Metaclass, which is a variant of class reference in the Object Pascal language. Class references are the unique features of Object Pascal. Object Pascal saves the original information of the class by class, and implements features such as polymorphism and RTTI. The .NET CLS does not correspond to the class reference, so Delphi Language introduces the concept of metaclass, which is implicitly added to each class through the compiler, saved the original information in this nested class. . When a class reference is required, the information is obtained from the nested class. Object Pascal, or the rigorous and strong style of Pascal, also reflected in Delphi Language. In C #, Boxing / Unboxing can be executed directly between different types, but in Delphi Language, it is necessary to complete through a more rigorous approach, ie explicit shape. Summarize these features, we can get a rough impression. Delphi Language has expanded due to the specifications of .NET CLS, Delphi Language supports many advanced OO features, so that it has reached the same level as Java and C # at the language level. The foregoing has been said, compared to Java, C # is more practical, at this point, Delphi Language is inseparable from C #. There are two reasons that cause this, one is because Delphi Language is not like C #, it is a language that completely reinvented, it must take care of the downward compatibility; the other is because Delphi Language, or Object Pascal, from At the beginning, it is a language for practical applications, and its goal has always been convenient and effectively meets user needs, rather than conforming to a specific theory.

Conclusion C direct forward-drive is a C language. C is a very flexible language, close to hardware layer, and is therefore referred to as "portable assembly language", also known as "intermediate language" (with assembly The low-level language, as well as the advanced language such as Basic, Pascal). C provides an abstraction of compilation such that mutual transplantation between C language between different platforms. At the same time, its oriented process is characterized by modular programming, thereby facilitating large-scale software development work. C introduces the ideology of object-oriented programming and generic programming into C language, which are from SmallTalk and ADA. The addition of these features makes C become higher levels than C language. This abstraction makes C have higher degree of graft, and is also more suitable for developing large-scale software. At the same time, since C needs to be compatible with C, it has left the bad characteristics of many C. The appearance of C can be considered as C to a higher level of abstraction, less thorough attempts. After C , Object Pascal acts as the product of the similar attempt to PASCAL. Object Pascal improves the success and failure of C , improves OO mechanism, abandoning or simplifying some of them too complicated or uncomfortable, and established its own IDE and component mechanism on this basis. . Compared to C , Object Pascal did not try further abstraction, but as a lightweight, highly high language, it has achieved great success in the application area. Java's birth is slightly early, but in contrast to Object Pascal, Java is a product that is more thoroughly abstract. Java makes it thoroughly independent of any platform through the virtual machine, through the grammar and the API, through the integrity of OO thinking, through the memory automatic recycling mechanism will be handed over to the virtual machine itself by the programmer. Java thoroughly changed the programming model. Since Java is so radical, it has not received universal acceptance in the past few years, then since the same reasons have been unprecedented, it may be that it does not expect it. However, history has not ended this. The emergence of C # indicates the correction of some extensions of this effort. C # and Java are very close to many aspects, but C # re-enacts practicality rather than theory in the first place. The value of value types, support for the characteristics of enumeration, commission, attribute, operator overload, pre-processor, etc., make C # full of more smell of C or Object Pascal. This is a step from the abstract level of Java. Delphi Language features a very similar to C #, if there is a difference, it is Delphi Language more attention to practicality, retaining many of the Object Pascal compatible features, so at a lower abstraction level. If C / C and Java do two extremes, then C # is located in these two extremes, while Delphi Language is in the middle of C # and C / C . As shown below: Figure 2

We may be able to make a conclusion that the evolution of computer programming languages ​​in recent years is a process from specific to abstraction, then from abstraction to specific regression. The programming language itself is a product that people try to abstract computer hardware. As the size is getting bigger and bigger, the programming language is increasingly complex, and the abstract level is getting higher and higher. Object-oriented programming theory and generic programming theory are the achievements of this effort, which can help programming languages ​​to achieve higher abstract levels. However, from the perspective of philosophy, human rationality has its limits. Trying to use a unified way to completely explained the whole world, although it is a temptation, but in the end, it is not possible to avoid failure. The higher the abstraction, the more strict standards, the farther from the hardware, the more efficient sacrifices, but will not only stay away from hardware, but also have deviated from the natural thinking method of human beings, deviations from abstract original goals. After Java reached a certain amount of abstraction, the emergence of C # and Delphi Language was the reaction to this ideal tendency. Http://editblog.9cbs.net/programmer/archive/2004/07/14/416.aspx

转载请注明原文地址:https://www.9cbs.com/read-122889.html

New Post(0)