D programming language |
D is an object-oriented, imperative programming systems programming language designed by Walter Bright of Digital Mars as a successor to C plus plus. He has done this by adding some features and reducing the complexity of C++ syntax. Examples of other proposed successors to C++ include java programming language and C Sharp programming language.
D extends C++ by implementing design by contract, unit testing, true module (programming), garbage collection (computer science) (garbage collection), first class arrays, associative arrays, dynamic arrays, array slicing, Closure (computer science)s (anonymous functions), and has a reengineered Template (programming) syntax. D retains C++ s ability to do Low-level programming language, and adds to it with support for an integrated inline assembler. C++ multiple inheritance is replaced by single inheritance with Interface (computer science) and mixins. D s declaration, statement and expression syntax closely matches that of C++.
The inline assembler typifies the differentiation between D and application languages like Java and C#. An inline assembler allows a programmer to enter machine-specific assembly code alongside standard D code—a technique often used by systems programmers to access the low-level features of the processor needed to run programs that interface directly with the underlying hardware, such as operating systems and device drivers.
Memory is usually managed with garbage collection (computer science), but specific objects can be finalized immediately when they go out of scope. Explicit memory management is possible using the Operator overloading new and delete, as well as simply calling C programming language s malloc and free directly. It is also possible to disable garbage collection for individual objects, or even for the entire program if more control over memory management is desired.
C programming language s Application binary interface is supported as well as all of C s fundamental and derived types, enabling direct access to existing C code and libraries. C s standard library (computer science) is part of standard D.
C++ s ABI is not supported, although D can access C++ code that is written to the C ABI, and can access C++ Component Object Model code.
Built into the language is a documentation generator called Ddoc.
Current D implementations compile directly into native code for efficient execution.
D is still under development, so changes to the language are made regularly. Some of these could break D programs written for older versions of the language and compiler. The official compiler by Walter Bright defines the language itself, and it is currently in the beta testing state.
= D examples =
Keywords are in blue, strings in red, comments in green.
==Example 1==
This example is of a program that prints its command line arguments. The main function is the entry point of a D program, and args is an array of strings representing the command line arguments. A string in D is an array of characters, represented by char[].
import std.stdio; // for writefln() int main(char[][] args) { foreach(int i, char[] a; args) writefln( args[%d] = %s , i, a); return 0; }
The foreach statement can iterate over any collection, in this case it is producing a sequence of keys (i) and values (a) from the array args.
==Example 2==
This illustrates the use of associative arrays to build much more complex data structures.
import std.stdio; // for writefln() int main() { // Declare an associative array with string keys and // arrays of strings as data char[][] [char[]] container; // Add some people to the container and let them carry some items container[ Anya ] ~= scarf ; container[ Dimitri ] ~= tickets ; container[ Anya ] ~= puppy ; // Iterate over all the persons in the container foreach (char[] person, char[][] items; container) display_item_count(person, items); return 0; } void display_item_count(char[] person, char[][] items) { writefln(person, is carrying , items.length, items. ); }
=External links=
*[http://www.digitalmars.com/d/ Digital Mars: D programming language] *[http://www.codemoon.com/dpage.php D WinLib windows library from Codemoon] *Open Directory Project: [http://www.dmoz.org/Computers/Programming/Languages/D/ D programming language] *[http://www.dsource.org DSource, an open source community for the D Programming Language.] *[http://www.dprogramming.com Dprogramming.com, home of the DFL windowing library.] *[http://www.prowiki.org/wiki4d/wiki.cgiFrontPage Wiki4D, the wiki for the d programming language ] *[http://home.earthlink.net/~dvdfrdmn/d/ gdc], D front-end for GCC *[http://www.opend.org OpenD.org] *[http://shootout.alioth.debian.org/great/benchmark.phptest=all&lang=dlang&sort=fullcpu, The Programming Language Shootout]|
|