4D v13.4Overview |
||
|
4D v13.4
Overview
Overview
You can compile your application, i.e., translate all of your methods into machine language. Compiling a database lets you check the consistency of the code and accelerate its execution, as well as making it possible to protect the code in its entirety. Compilation is an indispensable step between the development of databases using 4D and their deployment as stand-alone applications. The compilation process is entirely automatic; however, compilation requires greater rigor when writing 4D code. The Compiler section of the 4D Language Reference manual provides advice and specific information concerning programming with a view to compilation. Furthermore, keep in mind that the compiler will indicate any programming errors and situate them in their context. The computer is a device where commands are written using only “0”s and “1”s. This binary language is called machine language. The heart of the machine, the microprocessor, understands only this language. A program written in any high-level computer language (C, C++, SQL, Java, BASIC, 4D, and so on) is first translated into machine language, so as to be understandable to the computer’s microprocessor. There are two ways to do this:
When a series of statements is executed using an interpreter, the process can be broken down as follows:
This cycle is executed for each of the statements in the program. The program that handles the execution of this kind of cycle is called the interpreter. For a database in the process of development, 4D methods are interpreted. A compiled program is translated in its entirety prior to execution. This process results in a new file that contains a set of statements in machine language. This set is saved for repeated use—the translation is performed only once and the compiled version of the program is available for repeated execution. This phase is completely independent from any use of the program. The program that handles the translation is called the compiler. The compiler in 4D compiles the database methods, project methods, triggers, form methods and object methods in your database. If you do not have any of these elements in an application, the compiler will have nothing to compile. When you have successfully completed compilation, the use of the compiled database is identical to that of the original one. The first benefit of compilation is, of course, speed of execution. There are two further benefits directly linked to compilation:
The increased speed is due to two characteristics of compiled code: direct code translation, once and for all, and direct access to variable and method addresses.
The compiler also operates as a syntax checker for your databases. It systematically checks your code and notes possible ambiguities, whereas 4D only does this when the method is executed. Suppose that one of your methods contains a series of tests as well as a sequence of statements to be executed. It is unlikely that you would fully test for all cases if the number of tests was very large. Therefore, a syntax error in an untested case might not show up until an end user encounters the case. This sort of problem is avoided when you use a compiled database. When you compile a database, the compiler scans the entire database and analyzes each statement. The compiler detects any abnormality and generates an error message or warning. Once you have compiled your database, you can use the application builder to erase the interpreted code. In this case, access to the Design environment (except for records) is blocked. For more information about the application builder, refer to the Finalizing and deploying final applications chapter. In a compiled database, the commands related to development are disabled. When a compiled component is installed into a host database, the shared project methods are accessible in the Explorer and can be called in methods of the host database but their contents do not appear in the preview area nor in the debugger. The other project methods of the component never appear. For more information about components, refer to the Developing and installing 4D components chapter. The benefits are:
A compiler is integrated into 4D. Database compilation is carried out using the following dialog box: It is also possible to launch compilation directly using the current settings via the Start Compilation command found in the Design menu and in the menu associated with the “Compiler” button of the tool bar. Compilation is carried out in keeping with generic compilation options, set on the Compiler page of the Database Settings. Once the database is compiled, it is still possible to switch from interpreted mode to compiled mode, and vice versa, at any time using the Restart Interpreted and Restart Compiled commands of the Run menu, without having to quit the 4D application — except when the interpreted code has been erased (see the previous section). The Open database dialog box also allows the choice of interpreted or compiled mode on startup of the database (see Open dialog box options). If you modify the structure of your database in interpreted mode, you must recompile it in order to have them taken into account in compiled mode. When you switch from one mode to the other, 4D closes the current mode and opens the new one. This amounts to exiting then reopening the application. Consequently, each time you change from one mode to another, 4D executes the two following database methods (if specified) in this order: On Exit database method -> On Startup database method |
PROPERTIES
Product: 4D |