Questions tagged [d]

D is a multi-paradigm systems programming language developed by Walter Bright and, since 2006, Andrei Alexandrescu. Now, D is an open source collaboration.

Overview

D is a systems programming language developed by Walter Bright and, since 2006, Andrei Alexandrescu. Its focus is on combining the power and high performance of C and C++ with the programmer productivity of modern languages like Ruby and Python. Special attention is given to the needs of concurrency, reliability, documentation, quality assurance, management and portability.

The D language is statically typed and compiles directly to machine code. It supports many programming styles: imperative, object oriented and functional, and offers tools for disciplined template-based metaprogramming. It's a member of the C syntax family.

The current version of D (technically D2), a non-backwards compatible successor, is feature complete and has become the official version under support.

Hello world in D

import std.stdio;

void main()
{
   writeln("Hello, world!");
}

Design Goals of D

  1. Make it easier to write code that is portable from compiler to compiler, machine to machine, and operating system to operating system.
  2. Eliminate undefined and implementation defined behaviors as much as practical.
  3. Provide syntactic and semantic constructs that eliminate or at least reduce common mistakes.
  4. Reduce or even eliminate the need for third party static code checkers.
  5. Support memory safe programming.
  6. Support multi-paradigm programming, i.e. at a minimum support imperative, structured, object oriented, generic and even functional programming paradigms.
  7. Make doing things the right way easier than the wrong way.
  8. Have a short learning curve for programmers comfortable with programming in C, C++, Java or C#.
  9. Provide low level bare metal access as required.
  10. Provide a means for the advanced programmer to escape checking as necessary.
  11. Be compatible with the local C application binary interface.
  12. Have a context-free grammar, i.e. successful parsing must not require semantic analysis.
  13. Easily support writing internationalized applications.
  14. Incorporate Contract Programming and Unit Testing methodology.
  15. Be able to build lightweight, standalone programs.
  16. Reduce the costs of creating documentation.

External Resources

Tag usage

When posting questions about D programming, please make sure to include target system and compiler information. This includes the compiler name (eg. dmd, ldc, gdc), version and settings used to compile.

  • Use as a generic tag to refer to the language as a whole, or version 2 specifically.
  • Use to refer to the abandoned version 1 specifically.
2639 questions
2
votes
2 answers

Using dlang in a scripting sense

So I was just taking a look at the example posted on the dlang website here: http://dlang.org/rdmd.html and was looking to do something like the second version where you define #!/usr/bin/env rdmd as the first line of your file. I copied and pasted…
csteifel
  • 2,854
  • 6
  • 35
  • 61
2
votes
1 answer

InvalidMemoryOperationError@ on call of class destructor

The plan is to log message using template when a class destructor is called, but it seems to not be possible. Any suggestions or explanations will be appreciated. import std.stdio; import std.datetime; class Test { this() { struct…
MX4399
  • 1,519
  • 1
  • 15
  • 27
2
votes
0 answers

Mago gives D0006: Error: Type resolve failed when debugging with VisualD

I'm trying to debug this very simple piece of code. import std.stdio; class Test { int i = 5; } int main(string[] argv) { Test test = new Test; return 0; } However, Mago gives me error D0006: Error: Type resolve failed when I'm…
Scintillo
  • 1,634
  • 1
  • 15
  • 29
2
votes
1 answer

memcmp in DMD v.s GDC AND std.parallelism: parallel

I'm implementing a struct with a pointer to some manually managed memory. It all works great with DMD, but when I test it with GDC, it fails on the opEquals operator overload. I've narrowed it down to memcmp. In opEquals I compare the pointed to…
Ryan
  • 417
  • 2
  • 12
2
votes
2 answers

How to get server response code on D?

I need to check server response code in D. For example check if server return 404, 200 or some another code. I looked at std.net.curl, but I do not understand how to use it. I am not sure but possible I need to use option request ex: import…
Dmitry Bubnenkov
  • 9,415
  • 19
  • 85
  • 145
2
votes
1 answer

Copying array while excluding element(s)

Is there a standard way to copy an array excluding elements equal to an object? My current naive solution: T[] without(T)(T[] array, T what){ T[] a; foreach(element; array) if(element != what) a ~= element; return…
weltensturm
  • 2,164
  • 16
  • 17
2
votes
2 answers

Maybe types in D

I'm trying to define a value type which either holds a size_t or a null (which is what I mean by a 'maybe type'). What I want to be able to do is something like this (where the relevant type is Maybe!size_t: Maybe!size_t something_which_could_fail…
Koz Ross
  • 3,040
  • 2
  • 24
  • 44
2
votes
0 answers

vibe.d application code porting trouble

Abstract Vibe.d has undergone a lot of breaking changes. The same applied to the compiler. I'm trying to get running a piece of code written back in 2012 with an earlier release of the dmd compiler and vibe. My porting effort is in vain and I am…
menjaraz
  • 7,551
  • 4
  • 41
  • 81
2
votes
2 answers

D Compiler for Arduino?

I am just getting into D, and I'm trying to figure out if I can use D for programming an Arduino. I know D normally compiles to native binaries, but I haven't had any luck trying to find a D compiler for the AVR instruction set. Does anyone know of…
Lily Mara
  • 3,859
  • 4
  • 29
  • 48
2
votes
2 answers

Initializing an array with an arbitrary number of elements in D

I have stumbled upon an issue when working with arrays in D. I need to initialize an array with an arbitrary number of elements of a pre-defined value. I know it can be done like double[10] arr = 5;, for example, this will make an array with 10…
Aendur
  • 53
  • 5
2
votes
1 answer

std.json - A bit confused with TRUE, FALSE and NULL values

I was looking over the std.json library as part of program I am working on, and I'm a bit confused about how to get data out of JSONValues whose types are inferred as TRUE, FALSE or NULL. For example, if I parse the following JSON: { "foo" :…
Koz Ross
  • 3,040
  • 2
  • 24
  • 44
2
votes
1 answer

Nullable inout Constructor Creates Mutable Object

The following code gives me a strange error when trying to compile: import std.conv: to; import std.typecons; import std.traits; void main() { alias BuiltinScalars = TypeTuple!(ubyte, byte, ushort, short, uint, int, ulong, long, …
Meta
  • 1,091
  • 6
  • 14
2
votes
1 answer

CDB command for setting a breakpoint based on a line number

Is there a set of CDB commands for setting a breakpoint based on a line number? It seems that there is no "direct" one. Actually it seems that CDB knowledge is falling into a black hole and it's getting harder and harder to find resources on the…
Abstract type
  • 1,901
  • 2
  • 15
  • 26
2
votes
2 answers

How to define a package's version in a DUB project

I know how to specify version requirements for imported packages in D/DUB project using the list of dependencies in the dub.json file. But: how do I define the version of a package in it's on dub.json file in the first place?
Ber
  • 40,356
  • 16
  • 72
  • 88
2
votes
1 answer

Access violation while using Xlib's XCreateSimpleWindow

I'm trying to use Xlib directly using D and bindings I found on Github (https://github.com/madadam/X11.d). The problem is that I get an access violation in several functions (e.g. XCreateSimpleWindow). I created a minimal example: module…
user3684240
  • 1,420
  • 2
  • 12
  • 18
1 2 3
99
100