Difference between revisions of "Why program in D"

From D Wiki
Jump to: navigation, search
(articles section)
 
(15 intermediate revisions by 8 users not shown)
Line 1: Line 1:
<blockquote>Much of D's improvements appear to be small, but the aggregate is large
+
<blockquote>
enough that once you write a project in D, you'll find it pretty hard to
+
[Many] of D's improvements appear to be small, but the aggregate is large enough that once you write a project<br/>
go back to another language. ''- Walter Bright'' </blockquote>
+
in D, you'll find it pretty hard to go back to another language. <br/>
 +
-- Walter Bright <br/> <br/>
 +
</blockquote>
  
The detailed [http://digitalmars.com/d/2.0/overview.html overview] of the language should give you the big picture.
+
<blockquote>
 +
Often, programming teams will resort to a hybrid approach, where they will mix Python and C++, trying to get <br/>
 +
the productivity of Python and the performance of C++. The frequency of this approach indicates that there <br/>
 +
is a large unmet need in the programming language department.<br/>
 +
 
 +
D intends to fill that need. It combines the ability to do low-level manipulation of the machine with the <br/>
 +
latest technologies in building reliable, maintainable, portable, high-level code. D has moved well ahead of <br/>
 +
any other language in its abilities to support and integrate multiple paradigms like imperative, OOP, and <br/>
 +
generic programming.
 +
 
 +
-- Walter Bright  <br/>  <br/>
 +
</blockquote>
 +
 
 +
<blockquote>
 +
Should one choose C over D for maximum performance? <br/>
 +
 
 +
My answer is an emphatic no, and I bring as evidence the fact that warp is significantly faster than the <br/>
 +
preprocessor in my own older Digital Mars C/C++ compiler tool chain, which was already the fastest on the <br/>
 +
market, and on which I've spared no effort optimizing and tuning over months and years. Modern compiler <br/>
 +
technology working in concert with D language fundamentals (white-box templates, simple object models) takes <br/>
 +
high-level compositions of templated code and optimizes it down to code that is virtually indistinguishable <br/>
 +
from what a C programmer would write for maximum efficiency. <br/>
 +
 
 +
The neato thing about D is that by separating the code into ranges and algorithms, it becomes easy to keep <br/>
 +
trying different range implementations and different algorithms. I tried all sorts of things. Like breeding <br/>
 +
racehorses, I kept the profile winners and culled the losers, step by step, through the code. That would have <br/>
 +
been a lot more difficult to do in other languages. <br/>
 +
 
 +
[https://code.facebook.com/posts/476987592402291/under-the-hood-warp-a-fast-c-and-c-preprocessor/ -- Facebook's warp C/C++ preprocessor written by Walter Bright]  <br/>  <br/>
 +
</blockquote>
 +
 
 +
The detailed [http://dlang.org/overview.html overview] of the language should give you the big picture.
  
 
Now if you are looking for reasons to start using D you are probably also looking for reasons not to use it. This was pointed out by Andrei Alexandrescu in [http://www.ddj.com/hpc-high-performance-computing/217801225 The Case for D], "Trying to find quick reasons to avoid [learning a new language] is a survival instinct." And like any language there are reasons not to use D, but you might find that they don't apply to you or that the benefits are greater.
 
Now if you are looking for reasons to start using D you are probably also looking for reasons not to use it. This was pointed out by Andrei Alexandrescu in [http://www.ddj.com/hpc-high-performance-computing/217801225 The Case for D], "Trying to find quick reasons to avoid [learning a new language] is a survival instinct." And like any language there are reasons not to use D, but you might find that they don't apply to you or that the benefits are greater.
Line 9: Line 42:
 
* [[MoreLinks#DBuzz | D Buzz]]
 
* [[MoreLinks#DBuzz | D Buzz]]
 
* [[PerfectD | Imperfect C++ and More Perfect D]]
 
* [[PerfectD | Imperfect C++ and More Perfect D]]
* [[FAQ]]
+
* [http://dlang.org/faq.html FAQ]
  
 
<p></p>
 
<p></p>
  
== Video conferences & presentations ==
+
== Videos - language ==
 
W. Bright: [http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2012/The-D-Programming-Language The D Programming Language] (2012)
 
W. Bright: [http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2012/The-D-Programming-Language The D Programming Language] (2012)
  
Line 23: Line 56:
  
 
W. Bright: [http://vimeo.com/4333802 Metaprogramming in D] (2009)
 
W. Bright: [http://vimeo.com/4333802 Metaprogramming in D] (2009)
 +
 +
 +
== Videos - D users ==
 +
 +
[http://dconf.org/2016/talks/zvibel.html Weka.io: Using D for implementing a large scale primary storage system] (2016)
 +
 +
[http://dconf.org/2016/talks/watson.html Quantum Break: AAA Gaming with Some D Code] (2016)
 +
 +
[http://dconf.org/2014/talks/clugston.html Sociomantic: Real-Time Big Data in D] (2014)
 +
 +
[http://dconf.org/2015/talks/smith.html Large Hedge Fund: Using D in production in finance] (2014)
 +
 +
[http://dconf.org/2014/talks/crapuchettes.html EMSI: economic modelling at scale using D] (2014)
 +
 +
[http://dconf.org/2014/talks/simpkins.html Facebook: Experience Report - Using D at Facebook and Beyond](2014)
 +
  
 
Here is a full list of [[Videos | videos]] relating to D.
 
Here is a full list of [[Videos | videos]] relating to D.
 +
Here is a list of [http://dlang.org/orgs-using-d.html organisations using D]
  
 
== Articles ==
 
== Articles ==
Line 33: Line 83:
 
* B. Mileswski [http://dlang.org/safed.html Safe D]
 
* B. Mileswski [http://dlang.org/safed.html Safe D]
  
Besides, W. Bright regularly writes enlightening [http://www.drdobbs.com/author/6839 columns in Dr Dobb's Journal]. Many are directly related to D (access is free, but it may require registering if you read more than a couple articles/day).
+
Until that journal's untimely demise, Walter Bright regularly wrote enlightening [http://www.drdobbs.com/author/6839 columns in Dr Dobb's]. Many were directly related to D (access is free, but it may require registering if you read more than a couple articles/day).
  
 
* [http://www.drdobbs.com/blogs/cpp/232700394 Uniform function call syntax] (2012)
 
* [http://www.drdobbs.com/blogs/cpp/232700394 Uniform function call syntax] (2012)
Line 50: Line 100:
  
 
You can find more articles in the [[Articles | articles section]].
 
You can find more articles in the [[Articles | articles section]].
 +
 +
See also the [https://dlang.org/blog/ official D blog] and [http://arsdnet.net/this-week-in-d/ This Week in D], the summary of what is going on in the D community.
 +
  
 
== Application Developers ==
 
== Application Developers ==
  
Each language has a preferred application domain. D's sweet spot is high performance desktop and server side applications. It does a very good job of bringing low-level performance] in the order of C++ with the safety and expressivity of languages like Java or Python.
+
Each language has a preferred application domain. D has a high degree of versatility as a language - it does have a sweet spot in high performance desktop and server side applications, but it can nonetheless be used where a scripting language would be the traditional choice: it provides the performance of low-level languages (of the order of C++) with the safety and ease of expression reminiscent of languages like Java and Python.
In fact, nearly everywhere Java is suitable, D could replace it, bringing in more expressive power, better performance and better memory management. Although its current libraries are nowhere near extensive as the Java libraries, most fundamental bricks are already here. You may want to have a look at [http://dlang.org/phobos/index.html Phobos] and [https://github.com/D-Programming-Deimos Deimos] libraries, as well as third-party libraries to make your own opinion on that matter. A very nice port of Java's SWT library has been created under the name [DsourceProject:dwt DWT].
+
 
 +
In fact, nearly everywhere Java is suitable, D could replace it, bringing in more expressive power, better performance and better memory management. Although its [https://code.dlang.org/ current libraries] are nowhere near as extensive as the Java libraries, most fundamental bricks are already here, and D has native interfacing to both C and C++, with library solutions for other languages such as Python,R and Lua. You may want to have a look at [http://dlang.org/phobos/index.html Phobos] and [https://github.com/D-Programming-Deimos Deimos] libraries, as well as third-party libraries to make your own opinion on that matter. A very nice port of Java's SWT library has been created under the name [https://github.com/d-widget-toolkit/dwt DWT] (with older but more complete documentation available at the [http://www.dsource.org/projects/dwt legacy dsource site]).  There are also [http://gtkd.org/ bindings for GTK], and [https://github.com/buggins/dlangui a cross-platform idiomatic D GUI].
 +
 
  
 
== Embedded Developers ==
 
== Embedded Developers ==
  
Being targetted at 32 bit and 64 bit machines, D is not designed for embedded development on small devices. However, with the advent of Android and iOS smartphones which embed powerful CPUs and large amounts of RAM, D may be suitable for such development. The GCC and LLVM compiler backends being able to target these devices, the community is making progress.
+
Being targeted at 32 bit and 64 bit machines, D is not designed for embedded development on small devices. However, with the advent of Android and iOS smartphones which embed powerful CPUs and large amounts of RAM, D may be suitable for such development. The GCC and LLVM compiler backends being able to target these devices, the community is making progress.
  
 
Find out more at StackOverflow:
 
Find out more at StackOverflow:
Line 66: Line 121:
 
== Numerical programmers ==
 
== Numerical programmers ==
  
D provides high precision floating point, NaN, and complex/imaginary numbers. There are also a number of [ScientificLibraries math libraries] already in the works.
+
D provides high precision floating point, NaN, and complex/imaginary numbers. There are also a number of mathematical and scientific libraries in development, e.g. SciD.  Notably the [https://github.com/libmir/mir Mir] and [https://github.com/libmir/mir-glas Mir-GLAS] projects provide an implementation of numerical libraries that offer performance comparable to Intel MKL, and better than Eigen and OpenBLAS without the use of assembler and implemented in a way that makes porting to new platforms very simple.
 +
 
 +
 
 +
== Script Fan ==
 +
 
 +
Since D provides type inference, high-level constructs, and fast compile-time it is a great language for writing scripts. The first line of the file is ignored if it begins with #! ('shebang') and combining this with [https://dlang.org/rdmd.html rdmd] which handles dependency resolution, D becomes a leader in native-code scripting languages. 
 +
 
 +
<syntaxhighlight lang="D">
 +
    #!/usr/bin/env rdmd
 +
 
 +
    void main() {
 +
        import std.stdio : writeln;
 +
        writeln("Hello, World!");
 +
    }
 +
</syntaxhighlight>
  
== Script Monkey ==
+
Scripts with library dependencies can also be written using a shebang with the [https://code.dlang.org/getting_started dub package manager].  The example below uses the [http://vibed.org/tutorials async fiber-based framework vibe.d]
  
Since D provides type inference, high-level constructs, and fast compile-time it is a great language for writing scripts. The first line of the file is ignored if it begins with #! and combining this with [DSpec2x:rdmd.html rdmd] which handles dependency resolution, D becomes a leader in machine-code scripting language.
+
<syntaxhighlight lang="D">
 +
    #!/usr/bin/env rdmd
 +
    /+ dub.sdl:
 +
        name "hello"
 +
        version "~master"
 +
        dependency "vibe-d" version="~master"
 +
    +/
 +
    import vibe.core.log;
 +
    import vibe.mail.smtp;
 +
 
 +
    void main()
 +
    {
 +
        auto settings = new SMTPClientSettings("smtp.example.com", 25);
 +
        settings.connectionType = SMTPConnectionType.startTLS;
 +
        settings.authType = SMTPAuthType.plain;
 +
        settings.username = "username";
 +
        settings.password = "secret";
 +
 
 +
        auto mail = new Mail;
 +
        mail.headers["From"] = "<user@isp.com>";
 +
        mail.headers["To"] = "<recipient@domain.com>";
 +
        mail.headers["Subject"] = "Testmail";
 +
        mail.bodyText = "Hello, World!";
 +
 +
        logInfo("Sending mail...");
 +
        sendMail(settings, mail);
 +
        logInfo("done.");
 +
    }
 +
</syntaxhighlight>
  
 
== Language Lover ==
 
== Language Lover ==
  
Walter works to make D a practical language while providing the benefits found in languages that strictly stick to a single paradigm. If you enjoy languages D is interesting in the way it combines many paradigms in a C-like syntax.
+
Walter, Andrei and the D community work to make D a practical language that combines native code efficiency and control with the modeling power, safety, and productivity found in high-level languages and those that stick strictly to a single paradigm. If you enjoy languages D is interesting in the way it combines many paradigms in a C-like syntax, and yet D is also a language [http://dlang.org/orgs-using-d.html used in production at scale] in industry and academe.
  
 
== Related ==
 
== Related ==
* [[ComingFrom | Learning D as a second language]]
+
* [[Coming_From | Learning D as a second language]]
* [[LanguageSpecification | Language Specification]]
+
* [http://dlang.org/spec.html Language Specification]
 
* [[D__Tutorial/StartingWithD | Setting up an environment to compile programs]]
 
* [[D__Tutorial/StartingWithD | Setting up an environment to compile programs]]
* [[DevelopmentWithD | Development with D]]
+
* [[Development_With_D | Development with D]]
* [[FAQ]]
+
* [http://dlang.org/faq.html FAQ]
* [[CurrentDUse | Current uses of D]]
+
* [[Current D Use | Current uses of D]]
 +
 
 +
 
 +
[[Category:Learn]]

Latest revision as of 03:36, 27 November 2018

[Many] of D's improvements appear to be small, but the aggregate is large enough that once you write a project
in D, you'll find it pretty hard to go back to another language.
-- Walter Bright

Often, programming teams will resort to a hybrid approach, where they will mix Python and C++, trying to get
the productivity of Python and the performance of C++. The frequency of this approach indicates that there
is a large unmet need in the programming language department.

D intends to fill that need. It combines the ability to do low-level manipulation of the machine with the
latest technologies in building reliable, maintainable, portable, high-level code. D has moved well ahead of
any other language in its abilities to support and integrate multiple paradigms like imperative, OOP, and
generic programming.

-- Walter Bright

Should one choose C over D for maximum performance?

My answer is an emphatic no, and I bring as evidence the fact that warp is significantly faster than the
preprocessor in my own older Digital Mars C/C++ compiler tool chain, which was already the fastest on the
market, and on which I've spared no effort optimizing and tuning over months and years. Modern compiler
technology working in concert with D language fundamentals (white-box templates, simple object models) takes
high-level compositions of templated code and optimizes it down to code that is virtually indistinguishable
from what a C programmer would write for maximum efficiency.

The neato thing about D is that by separating the code into ranges and algorithms, it becomes easy to keep
trying different range implementations and different algorithms. I tried all sorts of things. Like breeding
racehorses, I kept the profile winners and culled the losers, step by step, through the code. That would have
been a lot more difficult to do in other languages.

-- Facebook's warp C/C++ preprocessor written by Walter Bright

The detailed overview of the language should give you the big picture.

Now if you are looking for reasons to start using D you are probably also looking for reasons not to use it. This was pointed out by Andrei Alexandrescu in The Case for D, "Trying to find quick reasons to avoid [learning a new language] is a survival instinct." And like any language there are reasons not to use D, but you might find that they don't apply to you or that the benefits are greater.

Videos - language

W. Bright: The D Programming Language (2012)

A. Alexandrescu: Three Unlikely Successful Features of D (2012)

A. Alexandrescu: Generic Programming Galore Using D (2012)

A. Alexandrescu: Three Cool Things About D - The Case for the D Programing Language (2010)

W. Bright: Metaprogramming in D (2009)


Videos - D users

Weka.io: Using D for implementing a large scale primary storage system (2016)

Quantum Break: AAA Gaming with Some D Code (2016)

Sociomantic: Real-Time Big Data in D (2014)

Large Hedge Fund: Using D in production in finance (2014)

EMSI: economic modelling at scale using D (2014)

Facebook: Experience Report - Using D at Facebook and Beyond(2014)


Here is a full list of videos relating to D. Here is a list of organisations using D

Articles

You will find in the main website more than a dozen articles discussing several design decisions for the language and its library. Don't forget to have a look there. A few examples

Until that journal's untimely demise, Walter Bright regularly wrote enlightening columns in Dr Dobb's. Many were directly related to D (access is free, but it may require registering if you read more than a couple articles/day).

A. Alexandrescu wrote several equally important articles :


You can find more articles in the articles section.

See also the official D blog and This Week in D, the summary of what is going on in the D community.


Application Developers

Each language has a preferred application domain. D has a high degree of versatility as a language - it does have a sweet spot in high performance desktop and server side applications, but it can nonetheless be used where a scripting language would be the traditional choice: it provides the performance of low-level languages (of the order of C++) with the safety and ease of expression reminiscent of languages like Java and Python.

In fact, nearly everywhere Java is suitable, D could replace it, bringing in more expressive power, better performance and better memory management. Although its current libraries are nowhere near as extensive as the Java libraries, most fundamental bricks are already here, and D has native interfacing to both C and C++, with library solutions for other languages such as Python,R and Lua. You may want to have a look at Phobos and Deimos libraries, as well as third-party libraries to make your own opinion on that matter. A very nice port of Java's SWT library has been created under the name DWT (with older but more complete documentation available at the legacy dsource site). There are also bindings for GTK, and a cross-platform idiomatic D GUI.


Embedded Developers

Being targeted at 32 bit and 64 bit machines, D is not designed for embedded development on small devices. However, with the advent of Android and iOS smartphones which embed powerful CPUs and large amounts of RAM, D may be suitable for such development. The GCC and LLVM compiler backends being able to target these devices, the community is making progress.

Find out more at StackOverflow:

Numerical programmers

D provides high precision floating point, NaN, and complex/imaginary numbers. There are also a number of mathematical and scientific libraries in development, e.g. SciD. Notably the Mir and Mir-GLAS projects provide an implementation of numerical libraries that offer performance comparable to Intel MKL, and better than Eigen and OpenBLAS without the use of assembler and implemented in a way that makes porting to new platforms very simple.


Script Fan

Since D provides type inference, high-level constructs, and fast compile-time it is a great language for writing scripts. The first line of the file is ignored if it begins with #! ('shebang') and combining this with rdmd which handles dependency resolution, D becomes a leader in native-code scripting languages.

    #!/usr/bin/env rdmd

    void main() {
        import std.stdio : writeln;
        writeln("Hello, World!");
    }

Scripts with library dependencies can also be written using a shebang with the dub package manager. The example below uses the async fiber-based framework vibe.d

    #!/usr/bin/env rdmd
    /+ dub.sdl:
        name "hello"
        version "~master"
        dependency "vibe-d" version="~master"
    +/
    import vibe.core.log;
    import vibe.mail.smtp;

    void main()
    {
        auto settings = new SMTPClientSettings("smtp.example.com", 25);
        settings.connectionType = SMTPConnectionType.startTLS;
        settings.authType = SMTPAuthType.plain;
        settings.username = "username";
        settings.password = "secret";

        auto mail = new Mail;
        mail.headers["From"] = "<user@isp.com>";
        mail.headers["To"] = "<recipient@domain.com>";
        mail.headers["Subject"] = "Testmail";
        mail.bodyText = "Hello, World!";
	
        logInfo("Sending mail...");
        sendMail(settings, mail);
        logInfo("done.");
    }

Language Lover

Walter, Andrei and the D community work to make D a practical language that combines native code efficiency and control with the modeling power, safety, and productivity found in high-level languages and those that stick strictly to a single paradigm. If you enjoy languages D is interesting in the way it combines many paradigms in a C-like syntax, and yet D is also a language used in production at scale in industry and academe.

Related