| Wikipedia has related information atD programming language. |
This page needs to bede-wikified. Books should use wikilinks rather sparsely, and only to reference technical or esoteric terms that are critical to understanding the content. Most if not all wikilinks should simply be removed. Please remove {{dewikify}} after the page is dewikified. |
The goal for this book is to create a complete, free, open-content, well-organized online book for the D programming language.
D is a programming language being designed as a successor to C++. Until this page gets better written and more informative, the D home can be foundhere.
This book aims at beginners learning D language. It will cover all the language basics and some design aspects. In addition it will introduce topics like multi-threading, GUI programming and standard library to get you started with real-world applications.
To quoteWalter Bright, the author of the D Programming Language:
D is a general purpose systems and applications programming language. It is a higher level language thanC++, but retains the ability to write high performance code and interface directly with theoperating systemAPI's and withhardware. D is well suited to writing medium to large scale million line programs with teams of developers. D is easy to learn, provides many capabilities to aid the programmer, and is well suited toaggressive compiler optimization technology.
D is not ascripting language, nor aninterpreted language. It doesn't come with a VM, a religion, or an overriding philosophy. It's a practical language for practical programmers who need to get the job done quickly, reliably, and leave behind maintainable, easy to understand code.
D is the culmination of decades of experience implementing compilers for many diverse languages, and attempting to construct large projects using those languages. D draws inspiration from those other languages (most especially C++) and tempers it with experience and real world practicality.
D is astatically-typed,multi-paradigm language supportingimperative programming,object-oriented programming, andtemplate metaprogramming. It also supportsgenerics anddesign by contract.
This section is a stub. You can help Wikibooks byexpanding it. |
D has many features not seen in C++, implementingdesign by contract,unit testing, truemodules,automatic memory management (garbage collection), first classarrays,associative arrays,dynamic arrays,array slicing,nested functions,inner classes,closures (anonymous functions), and has a reengineeredtemplate syntax. D retains C++'s ability to dolow-level coding, and adds to it with support for an integratedinline assembler. C++multiple inheritance is replaced bysingle inheritance withinterfaces andmixins. D's declaration, statement and expressionsyntax closely matches that of C++.
Theinline assembler typifies the differentiation between D and application languages like Java and C#. An inline assembler allows a programmer to enter machine-specificassembly code alongside standard D code—a technique often used by systems programmers to access the low-level features of theprocessor needed to run programs that interface directly with the underlyinghardware, such asoperating systems anddevice drivers.
Built into the language is adocumentation generator calledDdoc.
Memory is usually managed withgarbage collection, but specific objects can be finalized immediately when they go out of scope. Explicit memory management is possible using theoverloaded operators new and delete, as well as simply callingC'smalloc 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'sABI (Application Binary Interface) is supported as well as all of C's fundamental and derived types, enabling direct accessto existing C code and libraries. C's standardlibrary is part of standard D.
In D 1.0, C++'s ABI is not supported, although it can access C++ code that is written to the C ABI, and can access C++COM (Component Object Model) code. D 2 already supports some interaction with the C++ ABI.
Current D implementationscompile directly intonative code for efficient execution.
The Digital Mars D compiler can be obtained from the digital mars website.http://www.digitalmars.com/d/download.html You will need the two files dmd.zip and dmc.zip. According to the manual both files should be extracted into a root directory or one without spaces or other special characters. The location of link.exe should then be added to the path. D programs can now be compiled by calling 'dmd'.
Create a batch file "dmd_vars.bat" and move it to a directory that is included in the path:
@echo offecho Setting up a dmd environment...setPATH=c:\dm\bin;c:\dmd\binrem ;%SystemRoot%\System32setLIB=c:\dmd\lib;c:\dm\libecho PATH set to%PATH%
Then:
Note: This works well, even if you have other compilers/tools installed (which might also have link.exe/make.exe etc.)
With Tango Library the classic hello world program is:
importtango.io.Console;voidmain(){Cout("Hello, World").newline;}
With the Phobos library the classic hello world program is:
importstd.stdio;voidmain(){writefln("Hello, World");}
Compiling hello world:
dmdhello.d-ofhello
gdchello.d-ohello
This is an incomplete list of all D features. It is specifically created to show and teach the D programming language with lots of examples.