D (programming language)
Encyclopedia
The D programming language is an object-oriented
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...

, imperative
Imperative programming
In computer science, imperative programming is a programming paradigm that describes computation in terms of statements that change a program state...

, multi-paradigm
Multi-paradigm programming language
Programming languages can be grouped by the number and types of paradigms supported.-Paradigm summaries:A concise reference for the programming paradigms listed in this article....

, system programming language
System programming language
System programming languages are programming languages that are statically typed, allow arbitrarily complex data structures, are compiled, and are meant to operate largely independently of other programs. Prototypical system programming languages are C and Modula-2...

 created by Walter Bright
Walter Bright
Walter Bright is a computer programmer known for being the designer of the D programming language. He was also the main developer of the first C++ compiler that translated directly to object without going via C, Zortech C++ . Before the C++ compiler, he developed the Datalight C compiler, also...

 of Digital Mars
Digital Mars
Digital Mars is a small American software company owned by Walter Bright that makes C and C++ compilers for Windows and DOS. They also distribute the compilers for free on their web site....

. It originated as a re-engineering of C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

, but even though it is mainly influenced by that language, it is not a variant of C++. D has redesigned some C++ features and has been influenced by concepts used in other programming languages, such as Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

, Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

, Ruby
Ruby (programming language)
Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...

, C#, and Eiffel
Eiffel (programming language)
Eiffel is an ISO-standardized, object-oriented programming language designed by Bertrand Meyer and Eiffel Software. The design of the language is closely connected with the Eiffel programming method...

.

D's design goals attempt to combine the performance of compiled languages with the safety and expressive power
Expressive power
In computer science, the expressive power of a language describes the ideas expressible in that language.For example, the Web Ontology Language expression language profile lacks ideas which can be expressed in OWL2 RL . OWL2 EL may therefore be said to have less expressive power than OWL2 RL...

 of modern dynamic languages
Dynamic programming language
Dynamic programming language is a term used broadly in computer science to describe a class of high-level programming languages that execute at runtime many common behaviors that other languages might perform during compilation, if at all...

. Idiomatic D code is commonly as fast as equivalent C++ code, while being shorter and memory-safe
Memory safety
Memory safety is a concern in software development that aims to avoid software bugs that cause security vulnerabilities dealing with random-access memory access, such as buffer overflows and dangling pointers....

. Type inference
Type inference
Type inference refers to the automatic deduction of the type of an expression in a programming language. If some, but not all, type annotations are already present it is referred to as type reconstruction....

, automatic memory management and syntax sugar for common types allow faster development, while bounds checking
Bounds checking
In computer programming, bounds checking is any method of detecting whether a variable is within some bounds before its use. It is particularly relevant to a variable used as an index into an array to ensure its value lies within the bounds of the array...

, Design by contract
Design by contract
Design by contract , also known as programming by contract and design-by-contract programming, is an approach to designing computer software...

 features and a concurrency
Concurrency (computer science)
In computer science, concurrency is a property of systems in which several computations are executing simultaneously, and potentially interacting with each other...

-aware type system help reduce the occurrence of bugs.

Features

D is designed with lessons learned from practical C++ usage rather than from a theoretical perspective. Even though it uses many C/C++ concepts it also discards some, and as such is not compatible with C/C++ source code. It adds to the functionality of C++ by also implementing design by contract
Design by contract
Design by contract , also known as programming by contract and design-by-contract programming, is an approach to designing computer software...

, unit test
Unit test
In computer programming, unit testing is a method by which individual units of source code are tested to determine if they are fit for use.A unit is the smallest testable part of an application. In procedural programming a unit could be an entire module but is more commonly an individual function...

ing, true modules, garbage collection
Garbage collection (computer science)
In computer science, garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program...

, first class
First-class object
In programming language design, a first-class citizen , in the context of a particular programming language, is an entity that can be constructed at run-time, passed as a parameter, returned from a subroutine, or assigned into a variable...

 array
Array data type
In computer science, an array type is a data type that is meant to describe a collection of elements , each selected by one or more indices that can be computed at run time by the program. Such a collection is usually called an array variable, array value, or simply array...

s, associative array
Associative array
In computer science, an associative array is an abstract data type composed of a collection of pairs, such that each possible key appears at most once in the collection....

s, dynamic array
Dynamic array
In computer science, a dynamic array, growable array, resizable array, dynamic table, or array list is a random access, variable-size list data structure that allows elements to be added or removed...

s, array slicing
Array slicing
In computer programming, array slicing is an operation that extracts certain elements from an array and packages them as another array, possibly with different number of indices and different index ranges. Two common examples are extracting a substring from a string of characters In computer...

, nested function
Nested function
In computer programming, a nested function is a function which is lexically encapsulated within another function. It can only be called by the enclosing function or by functions directly or indirectly nested within the same enclosing function. In other words, the scope of the nested function is...

s, inner class
Inner class
In object-oriented programming , an inner class or nested class is a class declared entirely within the body of another class or interface. It is distinguished from a subclass.-Overview:...

es, closure
Closure (computer science)
In computer science, a closure is a function together with a referencing environment for the non-local variables of that function. A closure allows a function to access variables outside its typical scope. Such a function is said to be "closed over" its free variables...

s, anonymous functions, compile time function execution
Compile time function execution
Compile time function execution is the ability of a compiler, that would normally compile a function to machine code and execute it at run-time, to execute the function at compile-time...

, lazy evaluation
Lazy evaluation
In programming language theory, lazy evaluation or call-by-need is an evaluation strategy which delays the evaluation of an expression until the value of this is actually required and which also avoids repeated evaluations...

 and has a reengineered template syntax. D retains C++'s ability to do low-level coding
Low-level programming language
In computer science, a low-level programming language is a programming language that provides little or no abstraction from a computer's instruction set architecture. Generally this refers to either machine code or assembly language...

, and adds to it with support for an integrated inline
Inline assembler
In computer programming, the inline assembler is a feature of some compilers that allows very low level code written in assembly to be embedded in a high level language like C or Ada...

 assembler
Assembly language
An assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture...

. C++ multiple inheritance
Multiple inheritance
Multiple inheritance is a feature of some object-oriented computer programming languages in which a class can inherit behaviors and features from more than one superclass....

 is replaced by Java style single inheritance
Multiple inheritance
Multiple inheritance is a feature of some object-oriented computer programming languages in which a class can inherit behaviors and features from more than one superclass....

 with interfaces
Interface (computer science)
In the field of computer science, an interface is a tool and concept that refers to a point of interaction between components, and is applicable at the level of both hardware and software...

 and mixin
Mixin
In object-oriented programming languages, a mixin is a class that provides a certain functionality to be inherited or just reused by a subclass, while not meant for instantiation , Mixins are synonymous functionally with abstract base classes...

s. D's declaration, statement and expression syntax
Syntax
In linguistics, syntax is the study of the principles and rules for constructing phrases and sentences in natural languages....

 closely matches that of C++.

The inline assembler
Inline assembler
In computer programming, the inline assembler is a feature of some compilers that allows very low level code written in assembly to be embedded in a high level language like C or Ada...

 typifies the differences between D and application languages like Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

 and C#. An inline assembler lets programmers enter machine-specific assembly
Assembly language
An assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture...

 code within standard D code, a method often used by system programmers to access the low-level features of the processor
Central processing unit
The central processing unit is the portion of a computer system that carries out the instructions of a computer program, to perform the basic arithmetical, logical, and input/output operations of the system. The CPU plays a role somewhat analogous to the brain in the computer. The term has been in...

 needed to run programs that interface directly with the underlying hardware
Hardware
Hardware is a general term for equipment such as keys, locks, hinges, latches, handles, wire, chains, plumbing supplies, tools, utensils, cutlery and machine parts. Household hardware is typically sold in hardware stores....

, such as operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...

s and device driver
Device driver
In computing, a device driver or software driver is a computer program allowing higher-level computer programs to interact with a hardware device....

s.

D has built-in support for documentation comments, allowing automatic documentation generation
Documentation generator
A documentation generator is a programming tool that generates documentation intended for programmers or end users , or both, from a set of specially commented source code files, and in some cases, binary files....

.

Programming paradigms

D supports five main programming paradigm
Programming paradigm
A programming paradigm is a fundamental style of computer programming. Paradigms differ in the concepts and abstractions used to represent the elements of a program and the steps that compose a computation A programming paradigm is a fundamental style of computer programming. (Compare with a...

s—imperative
Imperative programming
In computer science, imperative programming is a programming paradigm that describes computation in terms of statements that change a program state...

, object-oriented, metaprogramming
Metaprogramming
Metaprogramming is the writing of computer programs that write or manipulate other programs as their data, or that do part of the work at compile time that would otherwise be done at runtime...

, functional
Functional programming
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state...

 and concurrent (Actor model
Actor model
In computer science, the Actor model is a mathematical model of concurrent computation that treats "actors" as the universal primitives of concurrent digital computation: in response to a message that it receives, an actor can make local decisions, create more actors, send more messages, and...

).

Imperative

Imperative programming in D is almost identical to C. Functions, data, statements, declarations and expressions work just as in C, and the C runtime library can be accessed directly. Some notable differences between D and C in the area of imperative programming include D's foreach
Foreach
For each is a computer language idiom for traversing items in a collection. Foreach is usually used in place of a standard for statement. Unlike other for loop constructs, however, foreach loops usually maintain no explicit counter: they essentially say "do this to everything in this set",...

 loop construct, which allows looping over a collection, and nested function
Nested function
In computer programming, a nested function is a function which is lexically encapsulated within another function. It can only be called by the enclosing function or by functions directly or indirectly nested within the same enclosing function. In other words, the scope of the nested function is...

s, which are functions that are declared inside of another and may access the enclosing function's local variable
Local variable
In computer science, a local variable is a variable that is given local scope. Such a variable is accessible only from the function or block in which it is declared. In programming languages with only two levels of visibility, local variables are contrasted with global variables...

s.

Object-oriented

Object-oriented programming in D is based on a single inheritance hierarchy, with all classes derived from class Object. D does not support multiple inheritance; instead, it uses Java-style interfaces
Interface (Java)
An interface in the Java programming language is an abstract type that is used to specify an interface that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations...

, which are comparable to C++ pure abstract classes, and mixin
Mixin
In object-oriented programming languages, a mixin is a class that provides a certain functionality to be inherited or just reused by a subclass, while not meant for instantiation , Mixins are synonymous functionally with abstract base classes...

s, which allow separating common functionality out of the inheritance hierarchy. D also allows declaring static and final (non-virtual) methods in interfaces.

Metaprogramming

Metaprogramming is supported by a combination of templates, compile time function execution, tuple
Tuple
In mathematics and computer science, a tuple is an ordered list of elements. In set theory, an n-tuple is a sequence of n elements, where n is a positive integer. There is also one 0-tuple, an empty sequence. An n-tuple is defined inductively using the construction of an ordered pair...

s, and string mixins. The following examples demonstrate some of D's compile-time features.

Templates in D can be written in a more function-like style than those in C++. This is a regular function that calculates the factorial
Factorial
In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n...

 of a number:


ulong factorial(ulong n)
{
if(n < 2)
return 1;
else
return n * factorial(n - 1);
}


Here, the use of static if, D's compile-time conditional construct, is demonstrated to construct a template that performs the same calculation using code that is similar to that of the above function:


template Factorial(ulong n)
{
static if(n < 2)
const Factorial = 1;
else
const Factorial = n * Factorial!(n - 1);
}


In the following two examples, the template and function defined above are used to compute factorials. The types of constants need not be specified explicitly as the compiler infers their types
Type inference
Type inference refers to the automatic deduction of the type of an expression in a programming language. If some, but not all, type annotations are already present it is referred to as type reconstruction....

 from the right-hand sides of assignments:


const fact_7 = Factorial!(7);


This is an example of compile time function execution
Compile time function execution
Compile time function execution is the ability of a compiler, that would normally compile a function to machine code and execute it at run-time, to execute the function at compile-time...

. Ordinary functions may be used in constant, compile-time expressions provided they meet certain criteria:


const fact_9 = factorial(9);


The std.metastrings.Format template performs printf
Printf
Printf format string refers to a control parameter used by a class of functions typically associated with some types of programming languages. The format string specifies a method for rendering an arbitrary number of varied data type parameter into a string...

-like data formatting, and the "msg" pragma displays the result at compile time:


import std.metastrings;
pragma(msg, Format!("7! = %s", fact_7));
pragma(msg, Format!("9! = %s", fact_9));


String mixins, combined with compile-time function execution, allow generating D code using string operations at compile time. This can be used to parse domain-specific languages to D code, which will be compiled as part of the program:


import FooToD; // hypothetical module which contains a function that parses Foo source code
// and returns equivalent D code
void main
{
mixin(fooToD(import("example.foo")));
}

Functional


import std.algorithm, std.range, std.stdio;

int main
{
int[] a1 = [0,1,2,3,4,5,6,7,8,9];
int[] a2 = [6,7,8,9];
immutable pivot = 5; // must be immutable to allow access from inside mysum

int mysum(int a, int b) pure // pure function
{
if (b <= pivot) // ref to enclosing-scope
return a + b;
else
return a;
}

auto result = reduce!(mysum)( chain(a1, a2) ); // passing a delegate (closure)
writeln("Result: ", result); // output is "15"

return 0;
}

Concurrent


import std.concurrency, std.stdio, std.typecons;

int main
{
auto tid = spawn(&foo); // spawn a new thread running foo

foreach(i; 0 .. 10)
tid.send(i); // send some integers
tid.send(1.0f); // send a float
tid.send("hello"); // send a string
tid.send(thisTid); // send a struct (Tid)

receive( (int x) { writeln("Main thread received message: ", x); } );

return 0;
}

void foo
{
bool cont = true;

while (cont)
{
receive( // delegates are used to match the message type
(int msg) { writeln("int received: ", msg); },
(Tid sender) { cont = false; sender.send(-1); },
(Variant v) { writeln("huh?"); } // Variant matches any type
);
}
}

Memory management

Memory is usually managed with garbage collection
Garbage collection (computer science)
In computer science, garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program...

, but specific objects can be finalized immediately when they go out of scope. Explicit memory management is possible using the overloaded operators
Operator overloading
In object oriented computer programming, operator overloading—less commonly known as operator ad-hoc polymorphism—is a specific case of polymorphism, where different operators have different implementations depending on their arguments...

 new and delete, and by simply calling C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

's malloc and free
Malloc
C dynamic memory allocation refers to performing dynamic memory allocation in the C via a group of functions in the C standard library, namely malloc, realloc, calloc and free....

 directly. Garbage collection can be controlled: programmers can add and exclude memory ranges from being observed by the collector, can disable and enable the collector and force a generational or a full collection cycle. The manual gives many examples of how to implement different highly optimized memory management schemes for when garbage collection is inadequate in a program.

Interaction with other systems

C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

's application binary interface (ABI)
Application binary interface
In computer software, an application binary interface describes the low-level interface between an application program and the operating system or another application.- Description :...

 is supported as well as all of C's fundamental and derived types, enabling direct access to existing C code and libraries. D bindings
Language binding
In computing, a binding from a programming language to a library or OS service is an API providing that service in the language.Many software libraries are written in systems programming languages such as C or C++...

 are available for many popular C libraries. C's standard library
Library (computer science)
In computer science, a library is a collection of resources used to develop software. These may include pre-written code and subroutines, classes, values or type specifications....

 is part of standard D.

C++'s ABI is not fully supported, although D can access C++ code that is written to the C ABI. The D parser understands an extern (C++) calling convention for limited linking to C++ objects.

On Microsoft Windows, D can access Component Object Model
Component Object Model
Component Object Model is a binary-interface standard for software componentry introduced by Microsoft in 1993. It is used to enable interprocess communication and dynamic object creation in a large range of programming languages...

 (COM) code.

History

D was first released in 2001, and reached version 1.0 in January 2007. The first version of the language (D1) concentrated on the imperative, object oriented and metaprogramming paradigms, similar to C++.

Dissatisfied with Phobos, D1's official runtime and standard library, members of the D community created an alternative runtime and standard library named Tango. The first public Tango announcement coincided within days of D 1.0's release. Tango adopted a different programming style, embracing OOP and high modularity. Being a community-led project, Tango had a lower contribution bar, which allowed it to progress faster than the official standard library. At that time, Tango and Phobos were incompatible due to different runtime support APIs (the garbage collector, threading support, etc). This made it impossible to use both libraries in the same project. The existence of two libraries, both widely in use, has led to significant dispute due to some packages using Phobos and others using Tango.

In June 2007, the first version of D2 was released. The beginning of D2's development signalled the stabilization of D1; the first version of the language has since been in maintenance, only receiving corrections and implementation bugfixes. D2 was to introduce breaking changes to the language, beginning with its first experimental const system
Const-correctness
In computer science, const-correctness is the form of program correctness that deals with the proper declaration of objects as mutable or immutable. The term is mostly used in a C or C++ context, and takes its name from the const keyword in those languages....

. D2 later added numerous other language features, such as closures
Closure (computer science)
In computer science, a closure is a function together with a referencing environment for the non-local variables of that function. A closure allows a function to access variables outside its typical scope. Such a function is said to be "closed over" its free variables...

, purity
Pure function
In computer programming, a function may be described as pure if both these statements about the function hold:# The function always evaluates the same result value given the same argument value...

, and the addition of the functional and concurrent programming paradigms.

The release of Andrei Alexandrescu
Andrei Alexandrescu
Andrei Alexandrescu is a Romanian C++ programmer and author. He is particularly known for his pioneering work on policy-based design implemented via template metaprogramming. These ideas are articulated in his book Modern C++ Design and were first implemented in his programming library, Loki. He...

's book The D Programming Language on June 12, 2010 marked the stabilization of D2, which today is commonly referred to as just "D".

Implementations

Most current D implementations compile
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...

 directly into machine code
Machine code
Machine code or machine language is a system of impartible instructions executed directly by a computer's central processing unit. Each instruction performs a very specific task, typically either an operation on a unit of data Machine code or machine language is a system of impartible instructions...

 for efficient execution.
  • DMD — The Digital Mars D compiler is the official D compiler by Walter Bright. The compiler front-end
    Front-end and back-end
    Front end and back end are generalized terms that refer to the initial and the end stages of a process. The front end is responsible for collecting input in various forms from the user and processing it to conform to a specification the back end can use...

     is licensed under both the Artistic License
    Artistic License
    The Artistic License refers most commonly to the original Artistic License , a software license used for certain free and open source software packages, most notably the standard Perl implementation and most CPAN modules, which are dual-licensed under the Artistic License and the GNU General Public...

     and the GNU GPL; the source code
    Source code
    In computer science, source code is text written using the format and syntax of the programming language that it is being written in. Such a language is specially designed to facilitate the work of computer programmers, who specify the actions to be performed by a computer mostly by writing source...

     for the front-end is distributed with the compiler binaries. The compiler back-end source code is available but not under an open source license.
  • GDC — A front-end for the GCC
    GNU Compiler Collection
    The GNU Compiler Collection is a compiler system produced by the GNU Project supporting various programming languages. GCC is a key component of the GNU toolchain...

     back-end, built using the open DMD compiler source code.
  • LDC — A compiler based on the DMD front-end that uses Low Level Virtual Machine
    Low Level Virtual Machine
    The Low Level Virtual Machine is a compiler infrastructure written in C++ that is designed for compile-time, link-time, run-time, and "idle-time" optimization of programs written in arbitrary programming languages...

     (LLVM) as its compiler back-end. The first release-quality version was published on January 9, 2009. It supports version 2.0.
  • D Compiler for .NET — A back-end for the D programming language 2.0 compiler. It compiles the code to Common Intermediate Language
    Common Intermediate Language
    Common Intermediate Language is the lowest-level human-readable programming language defined by the Common Language Infrastructure specification and is used by the .NET Framework and Mono...

     (CIL) bytecode rather than to machine code. The CIL can then be run via a Common Language Infrastructure
    Common Language Infrastructure
    The Common Language Infrastructure is an open specification developed by Microsoft and standardized by ISO and ECMA that describes the executable code and runtime environment that form the core of the Microsoft .NET Framework and the free and open source implementations Mono and Portable.NET...

     (CLR) virtual machine
    Virtual machine
    A virtual machine is a "completely isolated guest operating system installation within a normal host operating system". Modern virtual machines are implemented with either software emulation or hardware virtualization or both together.-VM Definitions:A virtual machine is a software...

    .

Development tools

Editors and integrated development environment
Integrated development environment
An integrated development environment is a software application that provides comprehensive facilities to computer programmers for software development...

s (IDEs) supporting D include Eclipse
Eclipse (software)
Eclipse is a multi-language software development environment comprising an integrated development environment and an extensible plug-in system...

, Microsoft Visual Studio
Microsoft Visual Studio
Microsoft Visual Studio is an integrated development environment from Microsoft. It is used to develop console and graphical user interface applications along with Windows Forms applications, web sites, web applications, and web services in both native code together with managed code for all...

, SlickEdit
SlickEdit
SlickEdit, previously known as Visual SlickEdit, is a cross-platform commercial source code editor by SlickEdit, Inc. SlickEdit provides syntax highlighting, code navigation and customizable keyboard shortcuts. Versions from 2007 and later also support programmable code...

, Emacs
Emacs
Emacs is a class of text editors, usually characterized by their extensibility. GNU Emacs has over 1,000 commands. It also allows the user to combine these commands into macros to automate work.Development began in the mid-1970s and continues actively...

, vim, SciTE
SciTE
SciTE or SCIntilla based Text Editor is a cross-platform text editor written by Neil Hodgson using the Scintilla editing component. It is licensed under a minimal version of the Historical Permission Notice and Disclaimer...

, Smultron
Smultron
Smultron is a text editor for Mac OS X that is designed for both beginners and advanced users; it was originally published as open source and is now sold through the Mac App Store It is written in Objective-C using the Cocoa API...

, TextMate
TextMate
TextMate is a general-purpose GUI text editor for Mac OS X created by Allan Odgaard. Popular with programmers, some notable features include declarative customizations, tabs for open documents, recordable macros, folding sections and snippets, shell integration, and an extensible bundle...

, Zeus, and Geany
Geany
Geany is a lightweight cross-platform GTK+ text editor based on Scintilla and including basic Integrated Development Environment features. It is designed to have short load times, with limited dependency on separate packages or external libraries. It is available for a wide range of operating...

 among others.
  • Eclipse plug-ins for D include: DDT, and Descent (dead project).
  • Visual Studio integration is provided by VisualD.
  • Vim supports both syntax highlighting and code completion (through patched Ctags
    Ctags
    Ctags is a program that generates an index file of names found in source and header files of various programming languages.Depending on the language,functions,variables,class members,macros and so onmay be indexed....

    ).
  • A bundle is available for TextMate
    TextMate
    TextMate is a general-purpose GUI text editor for Mac OS X created by Allan Odgaard. Popular with programmers, some notable features include declarative customizations, tabs for open documents, recordable macros, folding sections and snippets, shell integration, and an extensible bundle...

    , and the Code::Blocks
    Code::Blocks
    Code::Blocks is a free and open source, cross-platform IDE which supports multiple compilers including GCC and MSVC. It is developed in C++ using wxWidgets as the GUI toolkit. Using a plugin architecture, its capabilities and features are defined by the provided plugins.Currently, Code::Blocks is...

     IDE includes partial support for the language. However, standard IDE features such as code completion or refactoring
    Refactoring
    Code refactoring is "disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior", undertaken in order to improve some of the nonfunctional attributes of the software....

     are not yet available, though they do work partially in Code::Blocks (due to D's similarity to C).
  • A plugin for Xcode
    Xcode
    Xcode is a suite of tools, developed by Apple, for developing software for Mac OS X and iOS. Xcode 4.2, the latest major version, is available on the Mac App Store for free for Mac OS X 10.7 , and on the Apple Developer Connection website for free to registered developers Xcode is a suite of tools,...

     is available, D for Xcode, to enable D-based projects and development.


Open source
Open source
The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...

 D IDEs for Windows exist, some written in D, such as Poseidon, D-IDE, and Entice Designer.

D applications can be debugged using any C/C++ debugger, like GDB
GNU Debugger
The GNU Debugger, usually called just GDB and named gdb as an executable file, is the standard debugger for the GNU software system. It is a portable debugger that runs on many Unix-like systems and works for many programming languages, including Ada, C, C++, Objective-C, Free Pascal, Fortran, Java...

 or WinDbg
WinDbg
WinDbg is a multipurposed debugger for Microsoft Windows, distributed on the web by Microsoft. It can be used to debug user mode applications, drivers, and the operating system itself in kernel mode...

, although support for various D-specific language features is extremely limited. On Windows, D programs can be debugged using Ddbg, or Microsoft debugging tools (WinDBG and Visual Studio), after having converted the debug information using cv2pdb. The commercial ZeroBUGS debugger for Linux has experimental support for the D language. Ddbg can be used with various IDEs or from the command line; ZeroBUGS has its own graphical user interface
Graphical user interface
In computing, a graphical user interface is a type of user interface that allows users to interact with electronic devices with images rather than text commands. GUIs can be used in computers, hand-held devices such as MP3 players, portable media players or gaming devices, household appliances and...

 (GUI).

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[] in D1, or immutable(char)[] in D2.


import std.stdio: writefln;

void main(string[] args)
{
foreach (i, arg; args)
writefln("args[%d] = '%s'", i, arg);
}


The foreach statement can iterate over any collection, in this case it is producing a sequence of indexes (i) and values (arg) from the array args. The index i and the value arg have their types inferred from the type of the array args.

Example 2

The following shows several capabilities of D in a very short program. It iterates the lines of a text file named words.txt that contains a different word on each line, and prints all the words that are anagrams of other words.


import std.stdio: writefln;
import std.stream: BufferedFile;
import std.string: tolower, join;

void main
{
string[][string] signature2words;

foreach (string line; new BufferedFile("words.txt"))
signature2words[line.tolower.sort] ~= line.dup;

foreach (words; signature2words)
if (words.length > 1)
writefln(words.join(" "));
}

  1. The type of signature2words is a built-in associative array that maps string keys to arrays of strings. It is similar to defaultdict(list) in Python
    Python (programming language)
    Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

    .
  2. BufferedFile yields lines lazily, without their newline, for performance the line it yields is just a view on a string, so it has to be copied with dup to have an actual string copy that can be used later (the dup property of arrays returns a duplicate of the array).
  3. The ~= operator appends a new string to the values of the associate array.
  4. tolower and join are string functions that D allows to use with a method syntax, their names are often similar to Python string methods. The tolower converts an ASCII string to lower case and join(" ") joins an array of strings into a single string using a single space as separator.
  5. The sort property sorts the array in place, creating a unique signature for words that are anagrams of each other.
  6. The second foreach iterates on the values of the associative array, it's able to infer the type of words.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK