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
0 answers

Interaction between Widgets in gtkd

I am experimenting with D and gtkd. Now, I have this button, and when I click it, I want to start a function in an other widget. How can I do this? Here is some example Code, that is working, but not yet doing, what I want(when pressing…
jan_w
  • 113
  • 1
  • 6
2
votes
1 answer

D, setting class property, no identifier for declarator

I'm just getting started with D and this is completely strange. Here's my code: class User { int id; string name; } User b = new User(); b.name = "Edwin"; And here's my error: root@d-testing:~/Sail/source# dmd nonsense.d nonsense.d(8):…
RandomInsano
  • 1,204
  • 2
  • 16
  • 36
2
votes
1 answer

Mixin Function Names

Is there a way to mixin function names (or for the matter any kind of member names) other than mixin strings? I'm currently doing it like this: mixin template PacketValue(T, string name, PacketMode mode, size_t offset) { import std.string :…
Bauss
  • 2,767
  • 24
  • 28
2
votes
2 answers

How to convert array of strings to string in D?

I have got array of strings like: string [] foo = ["zxc", "asd", "qwe"]; I need to create string from them. Like: "zxc", "asd", "qwe" (yes every elements need be quoted and separate with comma from another, but it should be string, but not array of…
Suliman
  • 1,469
  • 3
  • 13
  • 19
2
votes
1 answer

Faulty D Dependency Logic in SCons

I've tracked down a bug in the dependency logic for D sources in SCons. The self.cre regexp import\s+(?:\[a-zA-Z0-9_.\]+)\s*(?:,\s*(?:\[a-zA-Z0-9_.\]+)\s*)*; in SCons.Scanner.D doesn't cover patterns such as... import IMPORT_PATH :…
Nordlöw
  • 11,838
  • 10
  • 52
  • 99
2
votes
3 answers

Dlang generics for classes

first time poster. I've been using Java for a few years now, and have decided to learn D. In Java, you can declare a class with a generic type, and create a new object from that class. Like: public class foo { public foo() { ... } } and then…
Straivers
  • 349
  • 1
  • 9
2
votes
1 answer

D: Converting DateTime to Date: cannot cast from DateTime to Date

I need to convert DateTime type to Date. here is my code: DateTime dt = DateTime(2015, 1, 1, 14, 10, 13); Date z = cast(Date)dt; Error: cannot cast from DateTime to Date Whats wrong?
Suliman
  • 1,469
  • 3
  • 13
  • 19
2
votes
1 answer

How to detect from console or GUI app was run?

Is it's possible to detect inside app from where it was run? From cmd/bash or from GUI? Assume that we are working in graphical mode, not in pure console.
Suliman
  • 1,469
  • 3
  • 13
  • 19
2
votes
1 answer

D Programming - How to get the piped content from stdin

I'd like to get the piped content in stdin of a D program only IF it is there. Considering the following string output; char[] buf; while (stdin.readln(buf)) { output ~= buf; } return output; This works great if you pipe content e.g echo…
keyle
  • 2,762
  • 3
  • 24
  • 27
2
votes
1 answer

Mimicking C++'s std::unordered_map index behavior in D

In C++, the index operator for maps will either return a reference to the existing value if the key can be found, or a reference to a new, default-initialized value if one with the given key cannot be found. In D, an exception is thrown instead when…
Matt Kline
  • 10,149
  • 7
  • 50
  • 87
2
votes
1 answer

Is it safe to cast between B* and D* if D contains an object of type B as its first member?

Consider the following: struct B { int x; } struct D { B b; int y; } void main() { auto b = cast(B*) new D(); writeln(b.x == b.x); auto d = cast(D*) b; writeln(b.x == d.b.x); } Is this program guaranteed to write "true" twice? I…
user1804599
2
votes
2 answers

Iterating through files in a folder in D

In D programming, how can I iterate through all files in a folder? Is there a D counterpart to python's glob.iglob?
user1392329
2
votes
1 answer

D lang record separator is being lost after string cast

I am opening a .gz file and reading it chunk by chunk for uncompressing it. The data in the uncompressed file is like : aRSbRScRSd, There are record separators(ASCII code 30) between each record (records in my dummy example a,b,c). File file…
Kadir Erdem Demir
  • 3,531
  • 3
  • 28
  • 39
2
votes
2 answers

Mechanics behind adding two arrays in D language

I am a bit curious mechanics behind code below: int[3] a1 = [ 1 , 2 , 3 ]; int[3] a2 = [ 1 , 2 , 3 ]; int[3] result = a1[] + a2[]; foreach (i; result) writeln(i); Result is 2,4,6 . In C++ we had to overload '+' operator for it to take two…
Kadir Erdem Demir
  • 3,531
  • 3
  • 28
  • 39
2
votes
1 answer

Exact copy of http gzipped response into a string

I need help. I'm trying to get content of website where Content-encoding is gzip, with dmd v2.066.1 on Windows. This is my web address for test: "http://diaboli.pl/test2.html". My HTTP request is: GET /test2.html HTTP/1.1 Host: diaboli.pl Accept:…
1 2 3
99
100