FACTOID # 19: Single guys should check out The Virgin Islands, where the women outnumber the men.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

SEARCH ALL

FACTS & STATISTICS    Advanced view

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > D programming language

D is an object-oriented, imperative system programming language designed by Walter Bright of Digital Mars as a re-engineering of C/C++. He has done this by re-designing many C++ features, and borrowing ideas from other programming languages. Object-oriented programming (OOP) is a computer programming paradigm in which a software system is modeled as a set of objects that interact with each other. ... In computer science, imperative programming, as opposed to declarative programming, is a programming paradigm that describes computation in terms of a program state and statements that change the program state. ... Systems programming (or system programming) is the activity of programming system software. ... Walter Bright is a computer programmer known for the design of the D programming language. ... Digital Mars features C and C++ compilers for Win32, Win16 and DOS. And also D. External links Digital Mars ... C# redirects here. ... C++ (generally pronounced see plus plus) is a general-purpose, high-level programming language. ...

Contents


Features

D was designed with lessons learned from C++. It uses many C++ concepts and adds to the functionality of C++ by also implementing design by contract, unit testing, true modules, automatic memory management (garbage collection), first class arrays, associative arrays, dynamic arrays, array slicing, nested functions, inner classes, closures (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 mixins. D's declaration, statement and expression syntax closely matches that of C++. Design by contract, DBC or Programming by contract is a methodology for designing computer software. ... In computer programming, a unit test is a procedure used to validate that a particular module of source code is working properly. ... This article or section is missing references or citation of sources. ... In computer science, garbage collection (also known as GC) is a form of automatic memory management. ... In computing, a first-class object (also -value, -entity, -citizen), in the context of a particular programming language, is an entity which can be used in programs without restriction (when compared to other kinds of objects in the same language). ... In computer programming, an array, also known as a vector or list (for one-dimensional arrays) or a matrix (for two-dimensional arrays), is one of the simplest data structures. ... An associative array (also dictionary, finite map, map, lookup table, and in query-processing an index or index file) is an abstract data type composed of a collection of keys and a collection of values, where each key is associated with one value. ... A dynamic array, growable array, resizable array, dynamic table, or array list is a data structure, an array which is automatically expanded to accommodate new objects if filled beyond its current size. ... 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 (or dimensions) and different index ranges. ... A nested function is a function which can only be called from its parent function. ... An inner class is a class defined entirely within another class. ... In programming languages, a closure is a function that refers to free variables in its lexical context. ... In computer science, generics is a technique that allows one value to take different datatypes (so-called polymorphism) as long as certain contracts such as subtypes and signature are kept. ... In computer science, a low-level programming language is a language that provides little or no abstraction from a computers microprocessor. ... Inline assembler is a feature of programming languages, that enables very low level code written in assembler to be embedded in a high level language like C. This allows programmers to optimise a very performance-sensitive algorithm by sending individual commands to the computers CPU. This example of inline... Multiple inheritance refers to a feature of object-oriented programming languages in which a class can inherit behaviors and features from more than one superclass. ... Multiple inheritance refers to a feature of object-oriented programming languages in which a class can inherit behaviors and features from more than one superclass. ... An interface defines the communication boundary between separate computer components. ... In object-oriented programming languages, a mixin is an approach to implementing classes that differs from the most widely-used approach coming from the programming language Simula. ... {{ Categories: | | ...


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. Inline assembler is a feature of programming languages, that enables very low level code written in assembler to be embedded in a high level language like C. This allows programmers to optimise a very performance-sensitive algorithm by sending individual commands to the computers CPU. This example of inline... It has been suggested that Assembler be merged into this article or section. ... CPU redirects here. ... Hardware is the general term that is used to describe physical artifacts of a technology. ... An operating system (OS) is a software program that manages the hardware and software resources of a computer. ... Windows XP loading drivers during a Safe Mode bootup A device driver, or a software driver is a specific type of computer software, typically developed to allow interaction with hardware devices. ...


Built into the language is a documentation generator called Ddoc. Documentation generator is a programming tool that generates an API Documentation documentation from a set of specially commented source codes, and in some cases, binary files. ... Ddoc is the embedded documentation generator for the D programming language. ...


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. In computer science, garbage collection (also known as GC) is a form of automatic memory management. ... In computer programming, operator overloading (less commonly known as operator ad-hoc polymorphism) is a specific case of polymorphism in which some or all of operators like +, = or == have different implementations depending on the types of their arguments. ... The C Programming Language, Brian Kernighan and Dennis Ritchie, the original edition that served for many years as an informal specification of the language The C programming language (often, just C) is a general-purpose, procedural, imperative computer programming language developed in the early 1970s by Dennis Ritchie for use... In computing, malloc is a subroutine provided in the C programming languages standard library for performing dynamic memory allocation. ...


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. The C Programming Language, Brian Kernighan and Dennis Ritchie, the original edition that served for many years as an informal specification of the language The C programming language (often, just C) is a general-purpose, procedural, imperative computer programming language developed in the early 1970s by Dennis Ritchie for use... In computer software, an application binary interface (ABI) describes the low-level interface between an application program and the operating system, between an application and its libraries, or between component parts of the application. ... Illustration of an application which may use libvorbisfile. ...


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. Component Object Model (COM) is a Microsoft platform for software componentry introduced by Microsoft in 1993. ...


Implementation

Current D implementations compile directly into native code for efficient execution. A diagram of the operation of a typical multi-language compiler. ... A system of codes directly understandable by a computers CPU is termed this CPUs native or machine language. ...


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. Walter Bright is a computer programmer known for the design of the D programming language. ... Software testing is the process used to help identify the correctness, completeness, security and quality of developed computer software. ...


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[].

 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."); } 

Example 3

This heavily annotated example highlights many of the enhancements over C++, while still retaining some of the better C++ aspects.

 #!/usr/bin/dmd -run /* sh style script syntax is supported! */ /* Hello World in D * To compile: * dmd hello.d * or to optimize: * dmd -O -inline -release hello.d * or to get generated documentation: * dmd hello.d -D */ import std.stdio; // References to commonly used I/O routines. void main(char[][] args) // 'void' for main means return 0 by default. { // 'writefln' (Write-Formatted-Line) is the improved 'printf' writefln("Hello World, " // automatic concatenation of string literals "Reloaded"); // Strings are denoted as a dynamic array of chars 'char[]' // auto type inference and built-in foreach foreach(argc, argv; args) { auto cl = new CmdLin(argc, argv); // OOP is supported, of course! writefln(cl.argnum, cl.suffix, " arg: %s", cl.argv); // user-defined class properties. delete cl; // Garbage Collection or explicit memory management - your choice } // Nested structs, classes and functions struct specs { // all vars automatically initialized to 0 int count, allocated; } specs argspecs(char[][] args) // Optional (built-in) function contracts. in { assert(args.length > 0); // assert built in } out(result) { assert(result.count == CmdLin.total); assert(result.allocated > 0); } body { specs* s = new specs; // no need for '->' s.count = args.length; // The 'length' property is number of elements. s.allocated = typeof(args).sizeof; // built-in properties for native types foreach(arg; args) s.allocated += arg.length * typeof(arg[0]).sizeof; return *s; } // built-in string and common string operations, eg. '~' is concatenate. char[] argcmsg = "argc = %d"; char[] allocmsg = "allocated = %d"; writefln(argcmsg ~ ", " ~ allocmsg, argspecs(args).count,argspecs(args).allocated); } /** * Stores a single command line argument. */ class CmdLin { private { int _argc; char[] _argv; static uint _totalc; } public: /** * Object constructor. * params: * argc = ordinal count of this argument. * argv = text of the parameter */ this(int argc, char[] argv) { _argc = argc + 1; _argv = argv; _totalc++; } ~this() // Object destructor { // Doesn't actually do anything for this example. } int argnum() // A property that returns arg number { return _argc; } char[] argv() // A property that returns arg text { return _argv; } wchar[] suffix() // A property that returns ordinal suffix { wchar[] suffix; // Built in Unicode strings (UTF-8, UTF-16, UTF-32) switch(_argc) { case 1: suffix = "st"; break; case 2: suffix = "nd"; break; case 3: suffix = "rd"; break; default: // 'default' is mandatory with "-w" compile switch. suffix = "th"; } return suffix; } /** * A static property, as in C++ or Java, * applying to the class object rather than instances. * returns: The total number of commandline args added. */ static typeof(_totalc) total() { return _totalc; } // Class invariant, things that must be true after any method is run. invariant { assert(_argc > 0); assert(_totalc >= _argc); } } 

See also

Programming languages are used for controlling the behavior of a machine (often a computer). ... Ddoc is the embedded documentation generator for the D programming language. ...

External links

Wikibooks
Wikibooks has a manual, textbook or guide to this subject:
Programming:D

  Results from FactBites:
 
Programming language - Wikipedia, the free encyclopedia (3717 words)
Programming languages are used to facilitate communication about the task of organizing and manipulating information, and to express algorithms precisely.
The combination of the language definition, the program, and the program's inputs must fully specify the external behavior that occurs when the program is executed.
Programming language syntax is usually defined using a combination of regular expressions (for lexical structure) and Backus-Naur Form (for grammatical structure).
Programming language - definition of Programming language in Encyclopedia (1627 words)
Most languages that are widely used, or have been used for a considerable period of time, have standardization bodies that meet regularly to create and publish formal definitions of the language, and discuss extending or supplementing the already extant definitions.
Functional languages often restrict names to denoting run-time computed values directly, instead of naming memory locations where values may be stored, and in some cases refuse to allow the value denoted by a name to be modified at all.
Programming languages are not error tolerant; however, the burden of recognising and using the special vocabulary is reduced by help messages generated by the programming language implementation.
  More results at FactBites »


 
 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms, 1022, m