In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
What this article shares to you is about the basic knowledge of D language, which the editor thinks is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Introduction
D language is a compiled language with elegant syntax, which has been developed for 20 years since it was released in 1999. It not only has the strong expression of Java, but also has the performance of C++. It was originally a language with a fairly clear future, but at that time, a large number of core developers in the community abandoned it because of the destructive upgrade of 2.x version.
In 2010, with the publication of Andrei Alexandrescu's new book "The D Programming Language", D language became active again, the features of D language 2.0 became stable, and the separation of runtime and standard library solved the problem of standard library dispute in D language 1.0 period.
In 2011, D language development migrated to Github, and with better code management and bug tracking, there was a significant increase in the number of people involved in D language compiler, runtime, and standard library development. The following year, D language 1.0 was not updated, and developers devoted themselves to 2.0 development.
In 2014, the license agreement for the front-end code of the D language compiler was changed to a more relaxed Boost license. In 2017, all the code in the compiler ended up using the Boost license. After solving the compiler source licensing problem, the D language became more open in the open source community and was successfully merged into GCC 9.x.
Until 2015, the D language community was further revitalized, the construction method based on package management began to mature, and a large number of development libraries began to emerge and applied to actual projects. At present, there are more than 1600 registered project libraries.
The rekindled hope of the D language is very robust in planning for a release, and to this day a large version is guaranteed every two months. The average number of developers per version has more than 50 core contributors, and the most recent 2.087.0 has reached 62 core developers.
The war of programming language is extremely fierce, this article hopes that through the introduction, let developers re-understand D language, realize that D language is actually a powerful language, and it can be used in different scenarios, the ecology is also constantly developing and improving.
Part one: the main features of D language
D language is designed on the basis of learning from various lessons encountered by C++, has a similar programming style, and many concepts are similar to C or C++. However, D language also has its own features, such as support for closures, anonymous functions, compile-time function execution, support for garbage collection, and so on. Specifically, D language has the following main features:
Object oriented programming
The D language allows you to define classes and interfaces. Like Java, the inheritance model of D language is single-class inheritance and multi-interface inheritance. All classes have a root class Object. The classes and interfaces of the D language are reference types, while structures are value types, and inheritance is not allowed.
Functional programming
The D language, like C++, allows functions to be defined separately outside of a class or structure. It also provides a variety of immutable data types, anonymous functions and closures, UFCS (unified function call syntax) and other features to better support functional programming.
Generic programming
The D language allows the definition of model types, as well as direct definition of template classes and template functions. Templates allow nested definitions, and template methods even allow recursive calls. Template type overloading can be achieved through template constraints. Template parameters support an indefinite number of types. In addition, template parameter types also support automatic derivation.
Metaprogramming
Pure functions in D language do not have any effect on global variables, so they can be called directly at compile time. With the help of static if, static foreach, mixin and other statements, the code executed at compile time can be written and the code can be generated dynamically to meet the needs of rapid customization of application functions.
Secure memory
Garbage collection-based memory management is supported by default, which makes programming easier, memory more secure, and programs more stable. In addition, you can also choose manual management of key memory resources as needed. With the help of the scope statement, you can well control the memory resource request and release point. There is a core set of type definitions and implementations within D language, which is a subset of D language, also known as SafeD, to protect memory security.
Modular programming
Each source file of D language is defined as a module, and the dependence between source files reflects the dependence between modules. Multiple modules in the same directory can form a package. Module-based code makes the logic of the project clearer and provides support for the rapid construction and compilation of the project.
Other language interaction
ABI of D language is fully compatible with C language, so it also has a good ability to interact with other languages, such as C, C++ and Objective-C. D language even supports direct embedding in assembly language, and some performance-critical code can be directly implemented in assembly language. The BetterC feature of D language is a subset of D language, which can completely remove GC dependence and replace C language programming in a better way of C language. it can do most of the work done by C language. Under the Windows platform, you can use the COM interface to interact with other languages.
Package-based application construction
This does not belong to the characteristics of D language itself, but in the development ecology of D language, it is a very important and convenient way to build D language applications. Dub is an application building tool of D language, which can manage the dependency relationship between application packages and build D language applications quickly.
In addition to the above features, D language also provides many other features, such as built-in associative arrays, unit tests, inline assembly, embedded documents and so on, which make D language a powerful language.
Part two: a brief comparison with other languages
Compared with Java, D language
As we all know, the design of Java for industrial architecture is very good, far beyond C++, Golang and other languages, and only Golang can be compared with Java. In the study, we found that D also has the characteristics of industrialization, and does not need such a complex virtual machine development environment. The performance of D is better than that of Java, and it is very convenient to integrate C and C++ libraries. And Java wants to integrate C, C++ need very troublesome jni pair to pick up. After all, D language is a veritable system-level development language, D language in the object-oriented aspect does not force every file to be an object, but more like C++ has a main () function as a program entry.
Sample code
Import std.stdio; void main () {writeln ("Hello world!");}
Compared with C++, D language
When it comes to performance, C++ has always been the first choice for high performance on the server side, but the performance of D is almost even with C++, but its efficiency can be 3 to 5 times that of C++. Of course, D and C language library integration is equally convenient, because D language is binary and C, C++ compatible, syntax is more like a super upgraded version of C++, D in the operation of hashMap performance is higher than C++, and as long as those who master C++ can use D language without any barriers.
Sample code
Import std.stdio; void main () {foreach (I; 1.. 10) {writeln (I);}}
Compared with PHP, D language
PHP is the language with the highest share of server-side scripting languages. The advantage of PHP is that it is simple and can use all the functions of the language itself without introducing any package, but that is why the performance of PHP has not been significantly improved. Although the emergence of PHP 7.x has improved the performance of PHP by 2.x times, it is only compared with the very slow PHP 5.x, and there is still a lot of difference compared with compiled languages. PHP has very obvious shortcomings, such as does not support multithreading, long connections are not friendly, weak types, cross-language RPC protocol support is unstable, deployment requires PHP runtime environment, etc., while D language has all the functions that C++ can achieve, including embedded assembly, development efficiency compared with PHP is just a strong type concept, while D language standard library also provides to method for you to carry out various types of conversion very easily.
Sample code
Import std.stdio: writeln; import std.conv: to; void main () {int I = 10000; string s = "Is string"; s ~ = i.tostrings; / / PHP uses dots to concatenate two strings, while D language uses wavy lines to concatenate two strings writeln (s); / / output result Is string 10000}
D language can replace C language
Some time ago, there was an article that was quite popular. An i3 core developer said in the article that D is the preferred language to really replace C. He thinks that D binary is completely compatible with C and C++, so he can directly use the binary libraries of these two languages. D can even introduce * .h files directly with the dpp project # include syntax. The author also talked about why the substitutes for C are not Rust and Golang. Interested students can understand the original text "D as a C Replacement" by themselves.
Gcc integrates D language compilation support
This is a very big step forward. With the recently released gcc 9.1 version, DLang's new compiler front end, gdc, has been integrated, and now there are more developers working on D projects throughout the community, and more people are using D to complete the work of CMagnet +.
Part III: the main applications of D language
As a system language supporting GC, D language has been adopted and applied by many companies, including Facebook and eBay. The application of D involves many fields such as games, Web applications, GUI applications, operating systems, compilers, embedded systems, scientific computing and education.
Game development
Remedy has successfully ported a 3A game, Quantum Break, to XBox One and Windows 10 platforms in D language. In addition, there are pure D language 3D game engine Dash and D language game development tool library gfm.
Web framework
Programming language is very important in Web server framework, there is a good framework to energize the whole language, just like Java has a Spring Framework framework, PHP has a laravel framework, Python has a Django, and Ruby has a Rails, so since it is building a server application, DLang also has a representative framework, Hunt Framework.
Database operation
Database operation is an indispensable basic operation in most application projects, and there are two main modes of operation: writing SQL scripts and ORM.
The D language that directly operates the database includes ddbc / (http://code.dlang.org/packages/ddbc)hunt-database, etc.), and the supported databases include MySQL, PostgreSQL, SQLite, etc. Among them, the underlying driver library of the new version of hunt-database has been upgraded from binding C language to directly using D language, which reduces the dependence on third-party libraries.
The D language using ORM mode to open the library includes hibernated / hunt-entity and so on. Among them, hunt-entity draws lessons from the concepts of Java JPA and spring-data-jpa, which has a high degree of industrialization, reasonable operation and easy maintenance.
Microservice related
Hunt-service is a distributed RPC server and client library based on gRPC protocol, which is easy to use and easy to integrate with hunt-framework to build micro-service architecture.
Neton is a distributed service discovery and registration application service based on raft algorithm.
GUI application
In fact, D language was launched relatively early, so the integration of GTK is very complete. It is well known that gtk's official vala language also draws lessons from D's language design, so gtkd can easily build client applications, and official developers have launched a great new tutorial site: gtkDcoding | Simple examples of how to use GtkD to build GUI applications (https://gtkdcoding.com/)).
In addition, the pure D language implementation of the cross-platform GUI library dlangui also has a good performance, there is a DLangIDE is based on it. More GUI libraries can be found here.
System application
In terms of compilers, the DMD front end has been bootstrapped. In terms of operating system, there are PowerNex (https://github.com/xomboverlord/xomb/tree/unborn) and Trinix) and other systems to try. The compiler LDC even allows application development on more system platforms, such as supporting embedded systems based on ARM and MIPS architecture, Android systems and so on.
Scientific calculation
Now it is convenient to use D language for scientific calculation, and mir is one of the outstanding ones. It provides excellent support for multi-dimensional array computing, and its performance surpasses many numerical libraries and reaches the commercial level.
The above are the basic knowledge of D language, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.