Overview
What is D language? D is a universal system and application programming language. It is a more advanced language than C , while also maintaining efficient code and direct access to the operating system.
API and hardware capabilities. D is ideal for writing a variety of programs from medium-size to those who are completed by teamwork, millions of lines. D is easy to learn, providing a lot of convenience for programming, and applies a variety of ambient compiler optimization techniques.
D is not a scripting language, nor is it an interpreted language. It does not require virtual machines, religions, or philosophy above everything. It is the actual language used by the actual programmer, which helps the programmer quickly and reliable code that is easy to maintain, easy to understand.
D is the accumulation of experience in achieving multiple language compilers for decades, which is the accumulation of the trial of large engineering. D Get inspiration from those languages (mainly C ) and will use the practicality in the experience and the real world to tame it.
Why is D? Indeed, why? Who needs another programming language?
Since the C language has been invented by the inventive, the software industry has passed a long way. Many new concepts have been added to C , but it maintains backward compatibility with C, including all the weaknesses compatible with the original design. There are a lot of tries to fix these weaknesses, but compatibility is the biggest trouble. At the same time, both C and C are constantly introducing new features. These new features must be careful to join the existing structure to avoid heavy code. The final result is very complicated - the C standard is nearly 500 pages, and the C standard has about 750! C achieves both difficult and cost, resulting in a variety of implementations, so it is difficult to write C code that is fully portable.
C programmers tend to programmatically using the islands in the language, that is, they tend to avoid some of the characteristics in the language and avoid other features. Although the code is usually portable between the compiler, it is not so easy to transplant between programmers. One of C is that it supports many different programming styles - but from the long run, repeated and conflict-related styles will hinder development.
C implements a number of groups and string splices that can change the size rather than the language core. These functions do not implement these functions in the core of language have caused several less ideal results.
Can I release C capacity, redesign and re-cast a simple, orthogonal and practical language? Is this language that can be easily implemented and make the compiler have the ability to effectively generate highly optimized code?
Modern compiler technology has made great progress, and some language features that have been used as original compilation technologies have been ignored (one such example is the 'register' keyword in C language, one more subtle The example is the macro pre-processing program in C). We can rely on the optimization techniques of the modern compiler rather than using language characteristics (as in the original compiler) to get acceptable code quality.
Main goal of D
By joining the characteristics that have been proven to improve productivity, adjust language characteristics to avoid common but consumable bugs, at least 10% of software development costs. It is the code that is easy to transplant between the machine between the machine, transplant between the operating system. Supports a variety of programming paradigms, that is, at least support for command, structured, object-oriented, and modes of programming paradigms. For those who are familiar with C or C , the learning curve is short. Provide necessary low-level access capabilities. To make D's compiler fundamentally easily (relative to C ). It is incompatible with the C language application binary interface of this machine. The syntax must be unrelated to the context. Provide convenient support for the application of internationalized applications. Support contractual programming and unit test methodology. It is possible to build a lightweight, independent program.
The characteristics of the C / C reserved look D look like C and C . This is easy to learn and transplant the code to D. Turning from C / C should be natural. Programmers don't have to learn from the beginning.
Using D does not mean that the programmer will be strictly restricted to a certain runtime VM (virtual machine) as Java or SmallTalk. D No virtual machine, the compiler directly generates a connected target file. D is directly connected to the operating system as c. Usually those that you are familiar with, such as Make also applies to the development of D.
D will have a large extent to keep C / C 's viewing sense. It will use the same algebraic syntax, most of the same expressions and statements, and the overall structure. D procedures can be used in both C-style functions and data paradigms, or the C style object-oriented paradigm, or mixing thereof. The development model of the compilation / link / debug will be inherited, but the DCC is built into a bytecode and does not have any problems. Abnormal handling is more and more experience shows that abnormal processing is a more advanced error handling model than C Traditional "Error Code / Global Errno Variable" model. The runtime type recognition C partially implements this function, and D is further. Full support for runtime type identification will make the garbage collection operation, which makes the debugger's function more than the support of automatic persistence, and more. D maintains compatibility with C call practices. This enables the D program to directly access the API of the operating system. Programmaker's knowledge and experience of existing APIs and programming examples can continue to use Dragonfly Use only to pay very little effort. The operator overload D supports overloading of the operator so that the type system consisting of the basic type can be extended by the user-defined type. The template template is a means of implementing the model programming. Other means include using macros or uses a cracked data type. Using macro has been outdated. Candle type is very straightforward, but it is inefficient and lacks type check. The problem with the C template is that they are too complicated, the syntax of the same language is not harmonious, and there are various types of conversion and overloading rules, and so on. D provides a simple way to use templates. RAII (resource gain, initialization) RAII technology is one of the important methods of writing reliable software. Down and Dirty Programming D will keep down-and-dirty programming without using an external module written in other languages. When performing system programming, sometimes it is necessary to convert a pointer into another pointer or use assembly language. D 's goals are not to avoid Down and Dirty programming, but reduce their needs when performing normal programming.
Abandoned characteristics
Source level compatibility of C. Reserved Source-level compatible extensions (C and Objective-C) have been extended to C. Further work in this area is subject to a large number of legacy code, which is difficult to improve these code. Concise C link compatibility. C runtime object model is too complicated - if it is better to support it, it is basically required that the D compiler becomes a complete C compiler. C preprocessing. Macro processing is a simple way to extend the language, which can add some languages that are not supported (not visible for symbol debuggers). Conditional compilation, using a #include layered text, macro, symbolic connection, etc., in essence, in nature, two kinds of fuses that are difficult to distinguish between two languages, not a language. Worse, it is (perhaps the best), the C preprocessor is a very original macro language. It's time to stop, see what the pre-processing is used for doing, and directs these features directly into the language. Multiple inheritance. It is a complex feature that has a controversial value. It is difficult to implement in an efficient manner, and various bugs are prone to compilers. Almost all MI functions can be achieved by using a single inherited interface and aggregation. And those who only support only MI can not make up for the side effects it brings. Name space. When linking the independently developed code, the conflict of the name may occur, the namespace is an attempt to solve this problem. The concept of modules is simpler and better work. Mark the namespace. This is a bad feature of C, the structure of the structure is located in a symbol table in different symbols. C attempts to combine the namespace and normal namespace, but also maintain backward compatibility of legacy C code. The result of causing is not printable. Beforewards. The C compiler only knows something in semantics, before the words are located before the current state. C has a little extension, and members in the class can rely on class members that have been declared after it. D further, a reasonable conclusion, the forward statement does not exist at all. The function can be defined in a natural order, which is defined in order to avoid the forward declaration as to avoid forward declarations. Contains files. One of the slow-proof causes of compilers is to compile each compile unit, you need to resolve the number of huge headers. The work of the included file should be done in the way imported into the symbol table. Create an object instance on the stack. In D, all classes are accessed by reference. This does not need to copy constructor, assignment operators, complex perture semantics, and interactions in the stack deployment in the same abnormal processing. Memory resources are relieved by the garbage collection program, and other resources are released by using D's RAII feature. Three-character code and double-bytecode. Unicode is the future. Pre-treatment procedure. Modern languages should not require text processing, they should only need symbol processing. Non-virtual member functions. In C , it is determined whether a function should be a virtual function. Rewriting a function in the subclass and forgetting to update it in the parent class to virtual functions is a common (and very difficult to discover) encoding errors. Set all the members function to virtual functions, and by the compiler to determine if the function is rewritten, and thus will be more reliable to convert the renovated function to the non-virtual function. The bit field of any length. Bit field is a complicated, efficient and rare feature. Support for 16-bit computers. D Never consider mixing the remote / near pointer and all other 16-bit code for claiming. D Language Design assumptions Target machine has at least 32-bit flat memory space. D will be able to be ported to a 64-bit architecture without difficulty. Due to the interdependence of compilation. In C , a symbolic table and a variety of preprocessing program commands can be successfully parsed for a source file. This makes it impossible to prepress the C source code, and the process of writing code analysis programs and syntax guides is difficult to implement correctly. The complexity of the compiler. This is more likely to have multiple correct implementations by reducing the complexity of implementation.
The difference between '.' And '->'. This difference is actually very unnecessary. '. The' operator can function as a pointer to the pointer to the reference. D is suitable?
Using the LINT or similar code analysis tools to reduce BUG programmers in order to compile. Turn the warning level of the compiler to the highest person and those who tell the compiler as an error. It has to rely on programming style specifications to avoid common C bug programming department managers. It is determined that the function of the C object-oriented programming is determined because C is too complicated and cannot be reached. Indulge in C powerful expressions but is discovered by explicit memory management and find pointer bug tortured. Requires a built-in test and verification mechanism project. Develop a team of millions of row. It is considered that language should provide sufficient feature to avoid programmers of explicit processing pointers. Write a programmer of numerical computing programs. D has a number of features that directly support numerical calculations, such as directly providing multiple types and NAN and infinity of determining behavior. (These are all added to the latest C99 standard, but no C is added to C .) The lexical analytics and parsers are completely independent of each other, and independently of the semantic analysis program. This means easy to write simple tools to handle D source code without writing a complete compiler. This also means that the source code can deliver a program that requires it in a marker.
D is not suitable?
One point, no one will write up millions of rows of C or C programs once, because D is not directly compatible with C / C source code, and D is not suitable for legacy procedures. (However, D provides a good support for legacy C APIs.) Very small program - script or interpretative language is more suitable for this situation such as Python, DMDScript, or Perl. As the first door programming language - Basic or Java is more suitable for beginners. For intermediate to advanced programmers, D is their excellent second language. Language pureists. D is a practical language, and each characteristics of it are serving this destination. D does not want to be a "perfect" language. For example, D has the structure and semantics that can basically avoid using pointers in daily tasks. But D is still supporting the pointer, because sometimes we need to break this rule. Similarly, D retains type conversion because sometimes we need to rewrite the type system.
D 's main feature This section lists some of the characteristics of more interesting D.
Object-Oriented Programming
Object-oriented nature of class D comes from classes. Single inheritance plus interface when the inheritance model is employed. The Object class is the topmost end with the inheritance system, so all classes have realized a common set of functions. The class is instantiated by reference, so it is not necessary to use complex code for cleaning operation after abnormal.
The operator overload class can support new types by overloading the existing operator extension type system. For example, create a BIGNUMBER Class, then overload , *, and / operators, such a large number of categories can use the normal algebraic operation syntax.
productive forces
The module source file is one or one. D no longer "contain" text with declared files, but "import" the module. Don't worry about importing a module multiple times, don't use the header file
# iFNDef / # ENDIF or
#pragma once package.
Declare that VS definition C functions and classes typically need to declare twice - declaration is located in the .h header file, defined in the .c source file. This process is easy to go wrong and is less tedious. Obviously, it should only be required to write once, and the compiler extracts the declaration information and imports it into the symbol table. This is what D is done.
Example:
Class ABC
{
INT func () {return 7;}
Static int z = 7;
}
INT Q;
No longer need to define member functions, static members, and external statements, and don't need to annoying syntax like this: int abc :: func () {Return 7;}
INT ABC :: z = 7;
Extern Int Q;
Note: Of course, in C , trivial functions such as
{RETURN 7;} can also be written directly at the statement, but the complex function is not possible (uframer: Although it is still possible from grammar, it will violate the principle of C interface and implementation.). In addition, if there is a forward reference, it must be guaranteed that a prototype of the referenced is declared. The following code is illegal in C :
Class foo
{
INT foo (bar * c) {return c-> bar;}
}
Class Bar
{
PUBLIC:
Int bar () {return 3;}
}
But the equivalent D code can work properly:
Class foo
{
Int foo (bar c) {return c.bar;}
}
Class Bar
{
Int bar () {return 3;}
}
The D function is online depending on the setting of the optimizer.
Sleal continuation ...