D Programming Language Articles about
D Programming Language
Website Links For
Programming
 

Information About

D Programming Language




D is an Object-oriented , Imperative Systems Programming language designed by Walter Bright of Digital Mars as a successor to C++ . He has done this by adding some features and reducing the complexity of C++ syntax.


FEATURES

D extends C++ by implementing Design By Contract , Unit Testing , true Modules , Automatic Memory Management (garbage collection), first class Array s, Associative Array s, Dynamic Array s, Array Slicing , Nested Function s, Inner Class es, Closure s (anonymous functions), and has a reengineered Template syntax. D retains C++'s ability to do Low-level Coding , and adds to it with support for an integrated Inline Assembler . C++ Multiple Inheritance is replaced by Single Inheritance with Interfaces and Mixin s. 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 System s and Device Driver s.

Built into the language is a Documentation Generator called Ddoc .


Memory management

Memory is usually managed with Garbage Collection , but specific objects can be finalized immediately when they go out of scope. Explicit memory management is possible using the Overloaded Operators new and delete, as well as simply calling C '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.


Interaction with other systems

C 's ABI (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 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++ COM (Component Object Model) code.


IMPLEMENTATION

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.


EXAMPLES

Keywords are in blue, strings in red,
comments in green.


Example 1

This example program 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 {Link without Title} .

import std.stdio; // for writefln()
int main(char {Link without Title} {Link without Title} args)
{
foreach(int i, char {Link without Title} a; args)
writefln("args {Link without Title} = '%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 color=red>"Anya" ~= "scarf";
container color=red>"Dimitri" ~= "tickets";
container color=red>"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