Why D?
- May I Propose D for memory safe programing?
Show off D
Semantics
- Copy and Move Semantics in the D Programming Language, talk by Ali Çehreli at DConf 2013. Describes the differences between
const
,immutable
;struct
,class
etc.,
Garbage Collection
- See the D garbage page on how to set GC options on a D program and also collect GC summary on program termination. Very handy!
- Don’t Fear the Reaper – The D Blog [March 2017 on D blog].
- Concurrent garbage collection for D — Dconf 2013 talk by Leandro Lucarella. DGC (appears to be for D1/tango only)… need to find out if it’s been ported to the D2 runtime.
- See Lucarella’s garbage collection posts circa 2009.
- Maxime Chevalier-Boisvert on D’s garbage collection problem and Circumventing the D garbage collector; Oct 2014. Her Higgjs JIT compiler for JS written in D. D’s New GC and Object Allocation Pools
- Matt Kline’s work on D’s owning types (Unique and RefCounted)
- Martin Nowak’s “Garbage Collection in D” talk; Mar 2015.
- Audio plugin written in D
- Forum discussion on garbage collection, Dec 2015.
- Xomb (pronounced zombie), an exokernel operating system written in D without use of GC.
- The real problem with GC in D - Infognition tech blog
- DmitryOlshansky/gchunt is a tool to identify and keep in check GC usage of D projects. My question about dub flags
- Implementing Alternative Garbage Collector - D Programming Language Discussion Forum
- “D generates lot less garbage”
Example code showing GCStats:
import std.stdio;
extern (C)
{
void gc_stats(GCStats* stats) nothrow;
}
struct GCStats
{
size_t poolsize; // total size of pool
size_t usedsize; // bytes allocated
size_t freeblocks; // number of blocks marked FREE
size_t freelistsize; // total of memory on free lists
size_t pageblocks; // number of blocks marked PAGE
}
void main()
{
GCStats stats;
gc_stats(&stats);
writeln(stats);
auto p = new byte[200];
gc_stats(&stats);
writeln(stats);
p = new byte[1000];
gc_stats(&stats);
writeln(stats);
p = new byte[10000];
gc_stats(&stats);
writeln(stats);
}
To turn on garbage collection profiling
$ max_column_sum_by_key_v1 --DRT-gcopt=profile:1 ngrams.tsv 1 2
max_key: 2006 sum: 22569013
Number of collections: 132
Grand total GC time: 246 milliseconds
GC summary: 35 MB, 132 GC 246 ms
-
What’s the go with the GC these days? ; Jan 2019 D forum discussion. recent PRs to add a more precise GC.
-
Profiling D’s Garbage Collection with Bpftrace — The Art of Machinery; Apr 2019.
Summary of GC discussion
See June 2016 discussion on the Garbage collector
- Precise GC is in the works. (todo: summarise progress)
- “Only a few language features forces you to use the GC.” (which ones?)
- “For most uses you are not forced to use the GC in any form especially with the help of std.experimental.allocator.” (How?)
- Current GC is based on a forked version of Boehm GC. So, not easy to upgrade to current version without deep understanding of how D does Thread Local Storage etc.,
- “we can disable the GC so it won’t go ahead and scan upon allocation (only time it does)” (how?)
Memory allocations are /always/ expensive. Higher level languages like Java have the benefit of using pools and optimizing for this usage pattern, D does and will never have this. Keep in mind an allocation = usage of malloc + write to returned pointer. — rikki c.
The point is, D doesn’t have to have a GC. Not using it is way easier than in most other languages because all the tools to help you profile it and avoid it are provided by the compiler. Go without a good GC is a dead language. D without a good GC is just not as good as it could be. And btw we’re generally faster than Go ;-) The point is: while a better GC is a work in progress we’ll never have a GC that can fit all needs, but it’s not as critical as it is in Go or in C# because we provide other ways to manage memory when limitations arise. — cym13
“Has anyone thought about taking GC from .NET and reusing it in D?”
One significant point has been already mentioned: cost of write barriers. I’d like to mention another factor: .NET GC is a copying one, it moves data around. One good feature of current D is it never moves data, so you can very easily call C and C++ code and pass pointers to your buffers and stuff and C/C++ code just takes these pointers and works with them as usual. No pinning, no marshaling, zero overhead. If you take a moving GC like .NET’s, you immediately make all C/C++ interaction much harder, now you need to worry about pinning stuff or copying “managed” data to “unmanaged” memory and back. This is all costly both in terms of CPU cycles and of programmer cycles. You’ll need “FFI”, what most other GC-ed languages have to have, and D doesn’t. —thedeemon
Precise Garbage Collector
It is essentially in a similar state that it was when Rainer presented it at DConf2013. The version in the pull request is not different from the one Rainer presented at all. It’s actually the same one, just updated with what has been changed in druntime recently and my attempts at making the marking phase faster.
Meta programming3
- User:Quickfur/Compile-time vs. compile-time - D Wiki
- Metaprogramming in D - From a beginner’s perspective
- Type safe OpenGL - Converting strings into types in D — using templates and mixins.
Debugging
Building
- To build projects using
ldc2
instead ofdmd2
withdub
, use the--compiler
switch, thus:dub build --compiler=ldc2
- To build the release version of the software, use the
-b
switch, thus:dub build -b release
Cross Compiling
Serialization
- Orange library for serialization.
Concurrency
- Forum question What are the real advantages that D offers in multithreading?
- See Ali’s book from “Parallelism” to “Fibers”.
- Getting more fiber in your diet
- Concurrency in the D Programming Language | 13.1 Concurrentgate from Andrei’s D book.
Range based programming
- poita.org has couple of articles on range based programming.
Profiling / performance
- andrewtrotman / D Profile Viewer — Bitbucket — The D language profiler that comes with DMD produces traces that are not designed for humans to read. This program reads a trace file (trace.log) and turns it into an interactive HTML file designed for human navigation and understanding.
- PGO: Optimizing D’s virtual calls
D run time
- Running D without its runtime (experience in building audio plugins in D without using the D run time.)
Testing
- Behaviour-driven development with D and cucumber by Atila Neves at Dconf 2015
C/C++ binding
-
Creating D bindings for a C library on D forum. “State of the art” as of Nov 2015.
-
Interfacing D with C and Fortran uses
-betterC
technique.
Lexing and parsing
- hsc - Halo 3 scripting lexer, parser, compiler in D
- Implementing a programming language in D: Lexical Analysis
Another option is to use a lexer/state machine generator. Ragel supports D and Rust (as of the not-quite-released v7) as target languages. HN
Memory safety
- Memory Safety in by Jakob Øvrum.
Documenting D code
- harbored-mod A documentation generator for D with support for both DDoc and Markdown in documentation comments.
Higher level programming
Resources
Introduction
- Diving into Dlanguage — Andrei Alexandrescu explains the basics of D programming Language.
- Pragmatic D Tutorial by
qznc
. - DPaste — paste code, run it online, see the output.
- The Dlang tour, forum announcement — “The basic idea behind this tour is to introduce features of the language with short explanations and example code that is compiled and run online.”. See also playpen, a sandbox used by Rust to create their playpen.
- glot.io — an open source pastebin with runnable snippets and API.
- explore.dgnu.org compiler disassembler.
- An active D reddit
- Three cool things about D - PDF presentation.
- ApplyYourDLang Channel on Youtube
- Quick start with D!
- D tutorials by Minas Mina
Intermediary
Articles
- Evaluating D for games
- Functional programming in D
- A comparison between C++ and D
- D as a scripting language - Infognition tech blog
Tutorials
- Beginner level — Tutorials - D-Land (in German)
Presentations
- Dive into D: Slides by Dmitry Olshansky; Mar 2016.
Editor
-
IntelliJ plugin for D language — look at the screenshots. It is a fairly complete IDE with syntax highlighting, auto completion, compile checking, code linting (via Dscanner), navigate to classes etc.,
-
DDT — the Eclipse based D IDE works as advertised. Use the 3.7(Indigo) version. [In Oct 2012, DDT did not work with the latest version of Eclipse: Juno].
Blogs
- The art of machinery by Seimon Arneaud.
- Planet D
- nomad.so/tag/d
- To:goto To; — D, go, nim, rust ; language benchmarks.
- Bitbashing.io
- braingam.es
- w0rpzone
- rharriso — D, intellij, lldb.
- infocognition blog
- leonardo
- Programming blog of Johan Engelen
- Blog - Bradley Chatha, see “Simple JSON Serialiser” etc.,
Talks
- Andrei Alexandrescu Three Cool Things about D - YouTube; Dec 2015.
- Functional Programming with D ― Andreas Zwinkau
- DConf 2013 Day 1 Talk 5: Using D Alongside a Game Engine by Manu Evans - YouTube
Read code
- dmin.io — URL shortener in D. Uses vibe.d.
- See also ccbikai/Sink: ⚡ A Simple / Speedy / Secure URL Shortener with Analytics, 100% run on Cloudflare., written in JS.
- DUB registry — list of D library packages; dub can be installed on Mac OS X using
brew
. - facebook/warp — A fast preprocessor for C and C++
- https://github.com/karpovr/veda uses vibe.d
- terminix -A tiling terminal emulator for Linux using GTK+ 3. GTK + D.
Discussions
- Andrei Alexandrescu’s AMA on reddit post his decision to work on D full time. [Aug 2015]
- Why didn’t D language become mainstream comparing to Golang?
- D Roadmap etc.,; specifically DIPs, Review Queue.
- RejectedSoftware Forums for vibe.d, dub etc discussion forum.
Contributing to D development
Software written in D
Developing and distributing D software
- Carlos Soriano Sánchez / GtkDApp · GitLab. This is a template for a Linux app, using Flatpak, GTK+, Meson, and D.
Misc
- Dlang comic strips
- Codeeval supports D.
- Rust v D
- SDLang — “simple declarative langauge” used by dub project for configuration.
User experience
- D for HFT by SD
- wilzbach comments on An introduction to non-uniform random sampling using D. Experience report of using D for six months. Forum link
- The Expressive C++17 Coding Challenge in D
- Advent of D – The Scribbler of the Rueful Countenance — see day 18 for concurrency, 8 for mixins, 7 for ctRegex.
- Why D is a good choice for writing a language
Libraries
For some reason, many D programmers have this “collection of D libraries”, which is interesting in the sense that more than one developer has found it just easy to write their own library to do X…
- adamruppe/arsd
- CyberShadow/ae
- kxml — recommended in D cookbook for XML parsing large files.
- treecount SDL2 etc.,
- runtimer Application runtime configuration for applications built in the D programming language.
- dstruct — has
WeakReference(T), Some(T), Option(T), HashMap(K,V), HashSet(T), Matrix(T), Matrix(T, rowCount, columnCount), BasicGraph(T, edgeDirection)
. - Tango-D2
- mbierlee/poodinis: A dependency injection framework for D with support for autowiring. and aedi
- Literate — A modern literate programming system written in D
- Abscissa/scriptlike: Utility library to help you write script-like programs in D
- sociomantic-tsunami/ocean: General purpose, platform-dependant, high-performance library for D extends Tango-D2, which is a D2 port of the Tango project.
- Derelict — D bindings to popular C libraries.
- tamediadigital/asdf: fast and simple JSON for Dlang
- tamediadigital/je: json extract: a tool to extract data from json
- Ocean is a general purpose library, compatible with both D1 and D2, with a focus on supporting the development of high-performance, real-time applications. developed by Sociomantic. runs only on linux. What’s inside —
core, io, math, net, stdc, task, text, time, util
.
In addition to those of CWEB:
- Markdown based — very easy to read and write Literate source.
- Generates readable and commented code in the target language (the generated code is usable by others)
- Reports syntax errors back from the compiler to the right line in the literate source
- Supports any language including syntax highlighting and pretty printing in HTML
- Compatible with Vim (literate.vim)
- Highly customizable (you can add your own HTML or CSS)
- Runs fast — wc.lit compiled for me in 7ms for both code and HTML output
- Supports TeX equations with
$
notation.
Inspired from CWEB:
- Automatically generates hyperlinks between code sections
- Formatted output similar to CWEB
Interop
The power of reflection | Átila on Code
import autowrap;
mixin(
wrapDlang!(
LibraryName("mylib"),
Modules(
Module("mymodule"),
Module("myothermodule"),
)
)
);
The code above, when compiled, will generate a Python extension (shared library) that exposes every D function marked as “export” in the modules “mymodule” and “myothermodule” as Python functions. It’ll even convert their names from camelCase to snake_case. Any D exceptions thrown will become Python exceptions. D structs and classes become Python classses. If the original D functions take a D string, you’ll be able to pass Python strings to them in user code. Modulo bugs, this… works! The code shown above is the only code that needs to be written. Setting up the build system takes more work!