Difference between revisions of "Why program in D"
m (fix typo "nowhere near *as* extensive") |
(refined some of the language; brought videos up to date and added examples of industrial users to add credibility; gave example of scripting) |
||
Line 1: | Line 1: | ||
− | <blockquote> | + | <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. | + | in D, you'll find it pretty hard to go back to another language. <br/> |
+ | -- Walter Bright <br/> <br/> | ||
+ | </blockquote> | ||
+ | |||
+ | <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. | The detailed [http://dlang.org/overview.html overview] of the language should give you the big picture. | ||
Line 13: | Line 46: | ||
<p></p> | <p></p> | ||
− | == | + | == 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] | ||
− | + | 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 | + | 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. 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 [http://www.dsource.org/projects/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 | + | 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 mathematical and scientific libraries in development, e.g. SciD. | + | 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 == | == 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 #! and combining this with [ | + | 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. Scripts with library dependencies can also be written using a shebang with the dub package manager: |
+ | |||
+ | <code>[https://code.dlang.org/getting_started Getting Started with Dub] | ||
+ | <nowiki> | ||
+ | #!/usr/bin/env rdmd | ||
+ | |||
+ | void main() { | ||
+ | import std.stdio : writeln; | ||
+ | writeln("Hello, World!"); | ||
+ | } | ||
+ | </nowiki> | ||
+ | </code> | ||
+ | |||
+ | <code>[http://vibed.org/tutorials Sample application using the async fiber-based framework vibe.d] | ||
+ | <nowiki> | ||
+ | #!/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."); | ||
+ | } | ||
+ | </nowiki> | ||
+ | </code> | ||
== Language Lover == | == Language Lover == | ||
− | Walter | + | 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 == |
Revision as of 05:46, 28 October 2016
[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.
Contents
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
- D. Clugston Real Close to the Machine: Floating Point in D
- S. Schweighoffer D Slices
- B. Mileswski Safe D
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).
- Uniform function call syntax (2012)
- Inheriting purity (2012)
- Type Qualifiers and Wild Cards (2011)
- Member function pointers (2011)
A. Alexandrescu wrote several equally important articles :
- Interview part 1 part 2 part 3 (2010)
- Concurrency in the D Programming Language(2010) (from The D Programming Language book)
- On iteration (2009)
- Case For D (2009)
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:
- Getting Embedded with D (the programming language)
- How would you approach using D in a embedded real-time environment?
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. Scripts with library dependencies can also be written using a shebang with the dub package manager:
#!/usr/bin/env rdmd
void main() {
import std.stdio : writeln;
writeln("Hello, World!");
}
Sample application using 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.