Oh, the list of people came over

zhaozj2021-02-08  233

Often find a file, but found that the discussion of VC and Delphi is very intense. I saw some articles written, I feel that some opinions are correct, some are very biased or even mistaken (maybe I don't know? I am sorry I said this :-). I am inadvertently arguing with anyone, and I am willing to see this as a technical discussion. It should be a fair, no prejudice attitude (this does not mean that it is necessary to score autumn, everything should be truthful). I have used all versions other than TP1 Turbo Pascal, all versions of Turbo C / Borland C , all versions of Delphi and C Builder; and MSC 5.0 / 6.0, MSC / C 7.0 and Visual C 4.2 / 5.0. I don't dare to say how high levels, at least have a little experience. Let's talk about my opinion.

Compiler

It should be said that Borland's compiler is best. Because Borland has the best compiler development group worldwide (although Anders Hejlsberg leaves). From a technical point of view, Borland leads the competitors for at least 2 to 3 years. In general, Borland's compiler can always generate smaller code and usually (not in any case) faster code.

Zi Yunying, Zengdeng said that VC compiled in the article, which is actually the result of dynamic connection. M $ puts VC runtime (MSVCRT * .DLL, MSVCP * .dll, mfc * .dll, how much is you adding together) When you install Windows, it is placed in the System / System32 directory. Two questions that say "negotiate interface" is fear that it is an understanding of some English articles. M $ is not willing to run files on other companies in Windows, there is no technical reason.

In fact, Delphi / C Builder is smaller than C , regardless of dynamic connection or static connection. For example, MDI examples: Selected new ... | Projects | MDI Application in Delphi / C Builder, in VC , using MDI App Wizard; generated program function is very similar.

The following is the comparison result:

(Delphi open optimization, C Builder use maximum speed optimization, VC 5 optimization using the minimum code)

Delphi 3 Delphi 5 C Builder 5 VC 5

Dynamic Link 21K 35K 44K 70K

Static Link 253K 398K 467K 490K

Any program that uses the application class library (regardless of MFC, OWL, VCL, and new CLX frameworks) is much larger than that is not used. This is because the current intelligent connection technology can only be used for global variables / processes without the object structure. Even if you only use an attribute or method of a class (or indirect reference), this class, and all classes it references are all connected to EXE. All compilers have not solved this problem. (PS: Actually generating the minimum code (really compiled) high-level language compiler is Turbo Pascal, do not believe you write the program

Comparison:

PROGRAM TEST;

Begin

Writeln ('Hello, World.');

End.

The resulting EXE is less than 1.5K. The same C procedure:

#include

Main ()

{

Printf ("Hello, World./N");

}

The code generated by the most sophisticated C / C compiler is also 6K.

)

So what is the quality of the code generated by several compilers? For example, for example, the For loop statement often used in programming:

(1) Object Pascal:

PROCEDURE FOO;

VAR

I, J: Integer;

Begin

For i: = 0 to 15 DO J: = J I;

END;

(2) C

Void foo (void)

{

INT I, J;

For (i = 0; i <16; i ) j = j i;

}

Delphi 3 generated code (open optimization): byte clock cycle

00424AA9 33C0 XOR EAX, EAX 1

00424AAB 40 Inc EAX 1

00424AAC 83F810 CMP EAX, 0x10 1

00424AF 75FA JNZ -0x06 0 (in parallel)

-----------------

8 3

C Builder 5 generated code (maximum speed optimization):

00401535 33c0 xor EAX, EAX 1

00401537 40 Inc EAX 1

00401538 83F810 CMP EAX, 0x10 1

0040153B 7CFA JL-0X06 0 (in parallel)

-----------------

8 3

Visual C 5 generated code (maximum speed optimization):

27: for (i = 0; i <16; i )

00401205 MOV ECX, DOWRD PTR [J] 1

00401208 xor Eax, EAX 0 (can be parallel)

28: {

29: j = j i;

0040120A Add ECX, EAX 1

0040120C Inc EAX 1

0040120D CMP EAX, 10H 1

00401210 jl foo (0x0040120a) 0ah 0 (in parallel)

00401212 MOV DWORD PTR [J], ECX 0/1 (depending on the branch predictive feelings of the previous instruction

?

30:};

-----------------

16 4.2 (Assuming that branch prediction accuracy is 80%)

The minimum code optimization of VC 5 also has 11 bytes:

27: for (i = 0; i <16; i )

00401205 XOR EAX, EAX 1

28: {

29: j = j i;

00401207 Add DWORD PTR [J], EAX 1

0040120A Inc EAX 1

0040120B CMP EAX, 10H 1

0040121E jl foo (0x00401207) 7 0 (in parallel)

30:};

-----------------

11 4

Note:

(1) The result of Delphi / C Builder is to use Turbo Debugger directly disassembled, and the result of VC 5 is obtained from the source-level debugging of the integrated environment.

(2) The number of clock cycles is taken as an example. In fact, the code speed generated by the CPU (such as 386/486 and NX586, etc.) VC 5 is still slower for the CPU without parallel execution units.

(3) Branch prediction accuracy derived from Intel's "Pentium Optimization Reference". However, it is closely related to the specific scheme. In general, the closer transfer command in the program is, the lower the branch prediction accuracy.

It can be seen that this program of Delphi / C Builder has an advantage of 1 to 1.2 clock cycles. This is mainly because C Builder's compiler is more intelligent, and it is not compiled with useless waste statements. (Interestingly, for this program, the maximum speed optimization of VC 5 is not as fast as the code optimized code run.)

Don't think that 1 ~ 1.2 clock cycles are not what, the entire program is coming out of this cycle of one clock. And for these instructions, it is very expensive to 25% to 28.6%, which is a very considerable number.

I didn't use VC 6 test (I no longer use VC from VC 5 because C Builder 5 can be fully compatible with VC - this compatibility from C Builder 3, but it is not perfect), I don't know if there is improved. If someone is interested, please test it.

If you are interested, you can go to Jake's Code Efficiency Challenge (http://www.xnet.com/~johnjac)

Take a look. The code is running performance challenge. At present, Delphi / C Builder maintains 5 leaders in 6 tests.

(PS: Delphi 2 defeated VC 4.2 in performance test of PC Week in 1996)

2. Language features

First of all, I don't want to evaluate the so-called "Pascal is a toy language" this ignorance. Some of the Basic people use bad people can't evaluate the advantages and disadvantages of other languages. As for "Only with high school students" is more smile: Peter Norton did not go to college, ID Software's John Carmack did not go to college, you don't care? ! Please don't laugh at high school students, most of the programmers may never reach these "high school students". What is the genius needs for creative work? Do you think genius is equivalent to what degree? :-)

(1) Pretreatment, macro, and .h file

Object Pascal does not support pre-processing, in fact, it is not necessary. The compiler that cannot be directly compiled in the source code requires support for the pre-processor (for translation / specification source (also included) to facilitate compilation). The preparation of the pretreatment is because the Ken Thompson and Dennis Ritchie have a large compromise that the C compiler is difficult to implement on the PDP-11 of the 256K memory. Modern C / C products have included the preprocessor in the compiler. (PS: C is also due to this historical reasons because of this historical reasons), it should be said to be garbage characteristics, just because compatibility considerations are reserved. ANSI / ISO C / C specification is clearly suggested: "Do not use macro and .h, you should use the constant definitions and functions in the program." Because Macro and .h are not the language characteristics of C / C (this is true!), There is no clear unified syntax definition. It will also cause the compilation speed to decrease, and due to the deployment of Macro in each place (not called), a large number of Macro will make the generated code bloated.

(2) Collection, subcord type

C does not support these Object Pascal native types (compilers can directly recognize). However, you can use class to simulate, after all, the C object structure is the most complex flexible (except ADA). However, performance has lost.

(3) Enumeration type

Object Pascal does not support each enumerated element to specify a value.

For example, C / C can be defined: Enum aweek {sun = 1, mon, tue ...};

Only Object Pascal can only be defined: aweek = (Sun, MON, TUE ...);

(4) array

C / C does not support the array of subscripts specified in Object Pascal, and the subscript can only start from 0.

(5) structure

Object Pascal does not support bitfield in Struct (called Record in Pascal). Bitfield can store structural members (do not require whole bytes) to reduce the storage space of the structure. However, the access efficiency will be reduced.

(6) String

String processing is one of the strengths of Object Pascal. Flexible and efficient string processing can be supported. Strictly speaking, C / C cannot support native string types. CHAR * and CHAR [] is more similar to the user-defined type because the compiler does not support the memory automatic allocation and recycling of the string, requiring users to call Malloc () and Free (). Object Pascal also supports a C / C style string (called PCHAR). However, the String type is more powerful. From the perspective of implementation, the String type of Object Pascal uses a prefix represents the length of the string (the Short String and 4-byte prefixed long string, two String are automatically compatible, and long String is also compatible with PCHAR), C / C CHAR * and CHAR [] use the suffix chr (0) to indicate the end of the string. Different representations have great impact on string processing performance: for large, complex string operations, using Object Pascal several times more than C / C faster programs (many PASCAL compilers written by PASCAL, such as Free Pascal, Pascal Pro, etc., although the technical level is general, but the compilation speed is also fast, and to some extent, it also benefits from the string processing efficiency of Pascal). For example, take a string length function length (), the implementation of Object Pascal only needs one MOV instruction, and the implementation of C / C needs to perform repeating string scan until the end is found.

Object Pascal's String type also has an advantage in supporting Unicode characters. To know that the C / C string has brought a lot of trouble to the modern operating system to support Unicode characters, such as the "ABC 'Unicode" is: 41 00 42 00 43 00, which makes the C / C program at all, this String. Although modifying the compiler can easily solve this problem, the optical modification compiler is not enough, but also modify the operating system, otherwise the previous large number of C / C programs cannot be used on the new operating system (this is a disaster --- You even have Notepad, what should I do? :-). Windows provides two sets of solutions using any API involving string processing. More than Textout, there is a textouta for processing ASCII characters and Textoutw for processing Unicode characters. And UNIX / Linux uses another way: all APIs involving string processing use UTF8 compression encoding (a coding method similar to RTF: Any ASCII character is stored directly, multi-byte characters are used / transform) Although (reluctant) ensures that compatibility is not small.

(String / Ansistring in PS: C is the simulation of class, so performance ...)

(7) Multiple inheritance

There is no doubt that Object Pascal does not support multiple inheritance; and it can also see that Borland has increased this feature (in fact, it is easy to lift). Object Pascal implements multiple inheritances through the interface (Interface). Interface can not only introduce objects implemented with Object Pascal, but also introduce COM / DCOM / CORBA objects implemented in other languages. Do you really need multiple inherits? I think most programmers have never used multiple inheritances like me (even such a strong and flexible architecture of VCLs is not used in multiple inheritances. (PS: Java and Delphi do not support multiple inheritance, but also using Interface to achieve multiple inheritance. In fact, this is not surprising: JDK 1.2 and Java 2 are mainly developed by Borland, Sun only name. Don't believe you, see the Java class library Not and VCL.: -) (8) Object Template

Object Pascal does not support object templates. Because the object template is just a macro language (the macro itself is not the language characteristics of C / C ).

(9) Overload

The Object Pascal supports the overload of the function / process and does not support operator overload. C all support. (PS: I personally prefer Object Pascal to increase support for operator overload)

(10) Bit and logical operations

Object Pascal and C / C have no difference in this regard. C / C &, |, ~, ^, >>, <<, &&, ||, is equivalent to Object Pascal And, OR, NOT, XO, SHR, SHL (AND, OR, NOT, XOR Used for bit operations to be used for logic operations). However, C / C does not support logic XOR (a xor b = a and not b or not a and b, or can be implemented).

(11) style

In fact, this is an important reason I prefer to use Delphi (because of the reason, I also often use C and assembly). Just like some articles said: "Object Pascal and C are the same heavyweight language", it is really difficult to divide, and the difference is mainly in style. C emphasizes flexible, and Object Pascal is more implicit and beautiful. The author of the "programming language: design and implementation" also praised Pascal "a very beautiful language." Some people think that Pascal is "clumsy". In fact, it should be "Avenue to Jane". I think that it is also a good job with the C writer, and don't sell skills. Only programmers with low levels like selling skills (the level is too low, it can't be found, too high and I don't want to sell it). Just like the chess of Li Changyi, "Plain", but Ma Xiaochun once again "ghost" can only be willing to worship.

It is actually C vs Object Pascal. But it also applies to VC VS Delphi. (PS: VC does not implement the features of all ANSI / ISO C 95 specifications (currently the latest standards) (So some people are called C ). And C Builder is fully compatible with ANSI / ISO C 95 specification and supports AT & T (C The birthplace) and all C extended features of UNIX V. Some people call "M $ adhere to industrial standards, Borland will modify", this is not right. Delphi is also fully compatible with ANSI / ISO Pascal 1983/92 specification, and Apple Object Pascal It should be aware of the apple Object Pascal for use with Code Warrior Professional.)

3. Function and other

(1) Obtainability

There is no doubt that Delphi has a huge advantage, this doesn't have to say more. (PS: The truly great greatness of Delphi is not because it is easy to use, the technical level is reduced. You need complexity, you need flexibility, you need to be flexible; you don't have visualize the same written program (visualization is just Object Pascal object) On the other side of the structure, write programs without VCL)

(2) Scope of application

VC can make any hardware allowed work. Delphi can also. ("No !!!", I know that you will say this, you will mention VXD. :-) Delphi can't write VXD (in actually if you use Delphi to generate Obj, use the LINK link to the LINK, it is possible) Reasons for (you have seen non-M $ can generate vxd? Watcom? Symantec? Gnu? ...), but not technical reasons. VXD's Le (Linear Executable) file format first appears in Windows 3.0, the format is simple (simple than NE and PE format), basically a memory image file. But M $ don't know what to do is not allowed to generate this (patent) format of other companies. Delphi is a SYS and a new WDM (Windows Driver Model) driver that can be written for Windows NT, which uses a normal DLL format. (PS: From the legal perspective, you write a program yourself, you don't have MS Word files without M $) (PS: Play "Miracle Age" (Age of Wonders, http://www.epicages.com )? It is written in Delphi 3. The picture and speed are better than the "Empire Age" of M $. But I don't like to play the strategy game, I like the Duke3D and Quake series, and Tomb Raider series.: - )

(3) Integrated development environment

Delphi's IDE is more concise / easy to use.

(4) Database support

In this regard, except Delphi's brother C Builder / JBuilder is probably only Power Builder (barely) compared to Delphi. However, the performance and scope of use of PB are too far (not how to call POOR Builder? :-). (PS: My Impression is that most network-based / large databases of C / S and multi-layer structures are developed by PHI / JBUILDER)

(5) Network function

Delphi also has a certain advantage. Especially in the development of Internet.

(6) Component support

In addition to Object Pascal-based VCL / CLX, Delphi also supports COM / DCOM-based components (such as ActiveX), and CORBA support. VC only supports components based on COM / DCOM.

(7) Application framework / design idea VCL is at least one generation than MFC, which is not much. The amount of MFC is almost imposed on OWL (a less successful) model, and it is not as good as OWL from design ideas. As a basic class library (regardless of visual or not), you should focus on your eyes, strike a simple and effective, maintain certain elasticity and abstraction (abstract means from function, such as Tcanvas in the VCL is in Windows. A very good abstraction of DC (Device Context) is less than a little bit of the design of the MFC. Not, it's not an face, move the API (unfortunately, M $ programmer has been doing this work for many years). Take a look at some of the MFCs, it is horrible: in addition to the parameters such as HWND and DC (already saved as a private data as a class), the method is simply the Windows API. What is the meaning of this? Will the Windows API are you? For example, using the thread class in the MFC is not as possible to call the CreateThread / Exitthread / ResumeThread / SetthreadPriority, which is more convenient and fast. (PS: Have Delphix (http://www.yks.ne.jp/~ Hori/)? DirectX is so complicated with the Object Pascal package so good again proves the power of the VCL architecture)

(8) debugging

The two are different. VC source-level debugging more user friendly, while Delphi / C Builder is better to support multi-threaded program.

(PS: It is more than a separate debugging tool, Borland's Turbo Debugger is much better than the codeview of M $)

(9) Run environment / system requirements

It should be said to be almost. The startup speed of VC is indeed faster than Delphi (which is mainly relative to Delphi 4 , the startup of Delphi 3 is still very fast). This is largely due to a fact: VC is mainly a traditional development environment based on a text editor. Code Warrior Professional is not a faster startup? As for the "A database program to bring 3 ~ 5MB BDE Run File", this may be due to the use of "all BDE installation" (default) instead of "in the installation production tool (INSTALLSHEILD, WISE) installation". If you only use the desktop databases such as Access, DBASE, FoxPro, Paradox, just a few hundred k run files. The database program developed with M $ tool also takes a lot of ODBC, DAO, JET, ADO, MSDE, and other run files. In Delphi 5, if you use AdoExpress, Interbase Express to access the database, you may not take BDE.

(PS: No matter what to say, Borland has to work hard in the start of Delphi / C Builder!)

(10) Product quality / stability

There is article "VC quality, high stability". Is it really? Is the service pack of Visual Studio not going to 4? What is a service pack? Is it mainly bug fix patch? ! Borland's tool is not perfect, and the "memory vulnerability" does exist in the VCL of Delphi 3, which will result in programs developed with D3 sometimes (not always) and cannot release allocated memory. VC has a lot of problems: IE is written with VC , start more, start the Internet, open the customs, finally closed, see how much your system resources are left? Always lead to "General Protection Error". Ultra edit is written with VC , and the same problem. In fact, it is good to say that the program quality is good, and the operation is stable and unstable, mainly on the level of developers / responsibility. For example, Tomb Raider Series and Quake Series games are developed with VC , but the picture quality and running speed obviously the Quake series is more better. As Bank of NASA (NASA), Russia (RSA), Bank of America (Bank of America, more than $ 500 billion in big bank), else, such as American Airlines, AT & T, BMW, Compaq, BBC Television, British Telecom, etc. Large agencies / companies are developing complex, corporate levels (ridiculous, "some people actually call" VC Development Enterprise-level Desktop Applications ", I don't know if enterprise application and desktop applications are relatively) applications There is a product introduction to Delphi and C Builder developed in http://community.borland.com (Borland Community Site)), if someone else wants to say "..." stability and reliable are the hard truth, I have to endure love " He is afraid I have had the homemade development tool (take the outer operating system). :-) (PS: About Delphi and some graphics drive conflicts, is due to some graphics cards (such as S3 Virge GX) old version drivers do not correctly handle the image of ImageList in Windows public control, in this In the case of all the programs that use multiple images in ImageList (PS: As for "I have a sad anomalus who has seen a lot of excellent sharing software to have Delphi characteristics, I suggest that this person can figure out The "Error Exception" message you see is that these software itself error, or is running an exception handling message (such as "" Did not find a specified file "or" index beyond range ") and say that there is a perfect exception handling in Delphi. So many programmers do not write error handles, and let go of the compiler to deal with. I think this is not a good habit, at least the pop-up message dialog may not match the language / style used by your program. Let people misunderstood? : -) (11) Help / Document

The help and documentation of VC is indeed a lot of Delphi / C Builder. However, this should not include MSDN because MSDN is a separate product, which is not prepared for VC , and includes considerable Windows technical information. As a programmer, no matter what development tool, you can (also) has a set of DN. Windows Data Structure / APIS is a slight inconvenience that uses a C style, but most conversion has been included in Delphi; in addition, if a programmer conversion. H file is simple work If you can't do it, he (she) may not do what is like development. A volunteer organization (www.delphi-jedi.org/) has also done a lot of work in this regard, with almost all useful C / C libraries on their site. Object pascal translation.

(PS: Delphi / C Builder Why can't you buy a MSDN? After all, we are still using M $ operating system, you will not even connect Windows technical information) (PS: Look at M $ MSDN from MSDN) The technical data is mainly stored in compiled html (.chm), but M $ puts all .CHM in Disc # 1, and puts index files (.chi) separately in DISC # 2. This will not See these files directly from the CD. Either install, or copy the corresponding .chm and .chi. I don't have any technical reason (who knows please tell me) Don't put half .CHM and .chi On a disc, and the other half is placed in the second disk. This at least reflects the dark psychology of some people in M ​​$)

(12) International Support

VC has included RTL resources for more than a variety of languages, and you need your resource localization in Delphi. Although Franch, German is also included in the ENGLISH resource. : - <(13) Application VC Driven Development (after all, M $ Windows) and some desktop applications (such as games) are used more. Delphi more applied in terms of database / multi-layer structure, multimedia and Internet development. (PS: VC is used in game development. I look at the price factor, the game uses a private interface, usually does not involve the database and the Internet (even if the Internet Play is just a simple TCP connection, and this feature is included in DirectPlay ), Expensive Delphi and C Builder displays the advantage. Just $ 79 VC standard version, DirectX SDK (available for free), OpenGL document (also free), then add a set of MSDNs.

For example, quake, all handwritten C code, even C features are rarely used. Borland also realized this problem, so released a free C compiler)

(14) price

M $ development tools are really inexpensive (relatively), but whether it is worthwhile, you can only see what you are using. (p

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

New Post(0)