Connect to the above ...
The template D template provides a simple method for providing a norm-based programming and offsetting.
Associated array association arrays are an array of indexes that can be arbitrary types, not as an integer as an index like a normal array. Essentially, the associated array is a hash table. The associated array makes it easy to build fast, efficient, and error-free symbol tables.
The true TypeDefc and C Typedef are actually type
Alias because it does not introduce new types. D real Typedef:
Typedef int handle;
Really created a new type
Handle. D also perform type checking the type introduced by TypeDef, and TypeDef also participates in the decision of the function overload. E.g:
Int foo (INT I);
Int foo (Handle H);
The most basic data type on the Bit type machine is bit, so D direct support
Bit data type. It is most useful when creating a bit array:
Bit [] foo;
The function is as you wish, D provides support for the function, including global functions, overload functions, functions online, member functions, virtual functions, function pointers, and more. In addition, D is also supported:
Nested function functions can be nested in other functions. This has high value for code decomposition, locality, and function closure techniques.
Functional volume anonymous functions can be embedded directly into the expression.
Dynamic shutdown nested functions and class member functions can be called closed bags (also known as delegate), which makes the model easier and guarantee type security.
In, OUT and INOUT parameters These modifiers can not only make functions easier to understand, and can avoid using pointers without affecting code, and this will also improve the compiler to help programmers find the possibility of coding issues.
These modifiers make D to interface directly with more external APIs. There is also no need to use the "Interface Definition Language" (IDL).
There are several disadvantages that can be corrected in array c arrays:
The array itself does not have information about array structures, which must be stored and passed. A classic example is the ARGC and Argv parameters transmitted to the main (int Argc, Char * Argv [] function. (In D, Main is declared as main (char [] [] args).) The array is not a first-class citizen. When an array is passed to the function, he is converted to a pointer, although the prototype is confused, claiming it is an array. When the type conversion occurs, all array type information is lost. The size of the C array cannot be changed. This means that even if the simplest gathering, such as stacks must be constructed with a complex class. The C array has no boundary check because they don't know how many array boundaries are. [] In the array declaration is behind the flag. This makes a statement such as a pointer to an array requires complicated syntax: int (* array) [3];
In D, the array [] is located on the left: int [3] * Array; // Declare a pointer to an array containing 3 int
Long [] func (int x); // Declare an array that returns the LONG data
Obviously this is easier to understand. Duals have four variants: pointers, static arrays, dynamic arrays, and associated arrays.
Strings In C and C , the operation of the string is so frequent, and so awkward, so that it is best to support it by the language itself. Modern languages handle string connection, copying, etc. Operation, D language also provides these support. Strings are processed directly by an improved array.
Resource management
The memory distribution of garbage collection D is completely garbage collection. Experience tells us that many complex features in C are used to process memory release. With garbage collection, the language has become simpler.
There is a view that garbage collection is prepared for those lazy, primary programmers. I still remember those comments on C . After all, there is nothing C to do c can't do, or this is the same for compilation. Waste collection can avoid boring, easy-to-error memory allocation and tracking code required in C and C . This doesn't mean less development time and lower maintenance costs, but also means that the program is run faster!
Of course, you can use garbage collection programs in C , I have used it in my own project. C is not friendly to garbage collection procedures, which also causes inefficiency of garbage collection in C . Many runtime libraries cannot work with the garbage collection program.
Explicit memory allocation Although D is a language that uses garbage collection, you can also rewrite the NEW and DELETE operations for a class to use a customized distributor.
Raiiraii is a modern software development technique for managing resource allocation and release. D supports RAII in a controlled, predictable manner, which is a recovery cycle independent of the garbage collection program.
performance
Lightweight aggregation D supports simple C style structure, which guarantees compatibility with C data structures, but also because of the suspicion of cockroaches with killing chickens.
Inline assembly equipment drivers, high-performance system programs, embedded systems, and some special code requires the use of assembly language to complete tasks. Although D's implementation does not have to implement intraline assembly, it is still defined as part of the language. He can meet most of the needs of assembly language, so you don't need a separate assembler or use DLL.
Many D implementations also achieve internal functions such as support I / O ports similar to C, directly accessing floating point hardware, and other internal functions.
Reliability Modern language should do our best to help programmers to avoid errors. There are many forms provided by language: from easy to use more robust technologies, the compiler indicates the code that is obviously wrong, and checks at runtime.
Contract Contract Programming (invented by B. Meyer) is a revolutionary technique for ensuring the correctness of the program. The D version of the DBC includes a priori condition of a function, a function of the function, a thunder, and an assertion contract.
Unit testing can give a class join unit test so that the test program automatically runs when the program is started. This will verify whether the class is implemented in each construction. The unit test constitutes a part of the source code. The creation unit test has become part of the natural sect of the class development, rather than directly throwing the code to the test team.
Unit tests can be done in other languages, but their results seem to have a feeling of seven spells, and the language you use is likely to be not compatible with this concept. Unit test is a main feature of D. For library functions, unit tests have been proven to be very effective. It can guarantee that the function is working properly and can demonstrate how to use these functions.
Consider a large number of C libraries and application code that can be downloaded online. Where is "a few" with verification test? Don't expect the unit to test? Less than 1%? The usual approach is that if they can be compiled, we assume that it is correct. And we don't know that the warning given in the process of mutation is a real mistake or a funny.
The contractual programming and unit test make D to prepare the best language to write trustworthy, robust system programs. Unit testing or we can rough but quickly estimate the quality of you from unreasonable D code pieces - if there is no unit testing and contractual programming, each person will do this.
The debug characteristics and statements are now commissioned into part of the language syntax. You can decide whether to use these code at compile time, no need to use a macro or preprocessing command. The debug syntax provides a continuous, portable, easy-to-understand identification of the debug code, so that the programmer can generate binary versions with debug code, and can generate binary versions that do not debug code.
Abnormal treatment D uses a more advanced
Try-catch-finally model rather than the original
TRY-CATCH model. There is no need to construct a 傀儡 object only in order to achieve Finally semantics using the destructor.
Synchronization Because multi-threaded programming has become mainstream, D provides the original language to build multi-threaded programs. Synchronization can be actually active on the method or on the object.
Synchronized Int func () {.}
The synchronization method only allows one thread to be performed at a time.
The sync statement will insert a mutex, control object, or global access around the statement block.
Support for robust technology
Use dynamic arrays instead of pointer to use the reference to variables instead of the reference to the object, not the pointer to use garbage collection rather than explicit memory allocation, the built-in synchronization is no longer a macro. Inline functions rather than macros have largely reduced the need to use the pointer, the size of the need is clear, and it is clear that the char type has a symbol that does not have to repeat the reputation in the source file and header file. The code provides explicit parsing support
Compile time check
A stronger type check requires explicit initialization that does not allow unused local variables that do not allow empty (by ';') cyclic body assignment statement does not return to the Boolean type of API
Runtime check
Assert () Expression array boundaries Check undefined CASE statements in the Switch statement, abnormal memory consumption, OUT, and class invariance provide support for contractual programming
compatibility
Operator priority and evaluation rule D retain C's operators and their priorities, rules and type enhancements. This avoids the emergence of subtle unrecognized bugs due to the semantics of C.
Direct access to C apid does not support the type corresponding to the C-type, it also provides the ability to directly access C functions. There is no need to write package functions and parameter converters, and there is no need to copy the membership of the gathering type one by one.
Support all C data types make the interface to C API or existing C library code possible. D Support structure, joint, enumeration, pointer, and all C99 types. D also has the ability to set up structural members alignment, which ensures compatibility with external imported data formats.
The exception handling mechanism for operating system anomaly processing D will utilize an exception handling method provided by the underlying operating system in the application.
Using ready-made tool D to generate standard target file formats, you can use standard assemblers, linkers, debuggers, performance analysis tools, executable program compressed programs, and other analyzers, and code to be written in other languages. Phase link.
Project management
Version Control D provides built-in support for a program that generates multiple versions from the same source code. It replaces the # IF / # ENDIF technology of the C predecessor.
Abandoning the evolution of the code, some old library codes will be updated and better. At the same time, the old version must be used to support the old customer code, and the old version can be marked as
abandoned . It can be judged by an option of the compiler to determine if the version of the discarded version code is legal, so that the programmer responsible for maintenance can easily determine where to determine the feature that has been discarded.
No warning D compile will generate a warning for suspicious code. The code can be accepted by the compiler or cannot be accepted by the compiler. This will not cause which warnings are indeed wrong and those who are not arguing, there is no controversy. The demand for the compiler warning itself is the performance of a bad language design.
Sample program (Sieve.D)
/ * Number of sieves with EncyOSthene (Erato, Greek astronomer, mathematician and geography) * /
Bit [8191] Flags;
int main ()
{INT I, COUNT, PRIME, K, ITER;
Printf ("10 iterations / N");
For (iter = 1; iter <= 10; iter )
{count = 0;
Flags [] = 1;
For (i = 0; i {IF (Flags [i]) {prime = i i 3; k = i prime; While (K { Flags [k] = 0; K = prime; } COUNT = 1; } } } Printf ("/ n% D number", count); Return 0; }