An Introduction to D and Visual D

D is a systems programming language from Digital Mars that focuses on “combining the power and high performance of C and C++ with the programmer productivity of modern languages like Ruby and Python.” While still being a statically typed language that compiles directly to native code, the syntax looks very much like Java or C# but it has some interesting advances.

Once such advance is explicit support for lazy arguments. When a parameter is tagged with the keyword “lazy” it indicates that the associated argument will be evaluated 0 or more times. This differs from languages such as Haskell which lazily evaluate arguments 0 or 1 times, but never more.

To assist in program correctness, especially in the realm of concurrency and multithreading, D supports both “immutable” and “const” as first-class concepts. Unlike C++, the immutable and const modifiers in D are transitive. If a variable is tagged with immutable, neither it nor anything you can access via it can be modified. The const keyword works the same way, though a given object may still be modified via a non-const reference.

D also combines many of the popular features from other languages. For example it has for-each loops, switches on strings, array slicing, closures, try-catch-finally blocks, and the separation between value types and reference types. At the same time it allows for direct memory access, 80-bit floats, struct member alignment control, and inline assembly.

Usually switching to native code comes with a high price in terms of safety. While C and C++ are the most well-known, most native languages are susceptible to coding errors such as buffer overflows. D prevents these by a combination of compile time and runtime array boundary checking. Likewise the contents of non-zero length arrays are auto-initialized to their default values.

In terms of memory management D is very much like .NET. By default reference types are stored in a garbage-collected heap and value types are stored either on the stack or inside other objects. D can also stack-allocate reference types so long as a pointer to them doesn’t escape. And like .NET you can also take pointers to unmanaged memory. Keeping these separate is important, as many of the operations that you can perform on an unmanaged pointer simply aren’t safe on a managed one.

Is your profile up-to-date? Please take a moment to review and update.

Email Address

Note: If updating/changing your email, a validation request will be sent

Company name:

Keep current company name

Update Company name to:

Company role:

Keep current company role

Update company role to:

Company size:

Keep current company Size

Update company size to:

Country/Zone:

Keep current country/zone

Update country/zone to:

State/Province/Region:

Keep current state/province/region

Update state/province/region to:

Subscribe to our newsletter?

Subscribe to our industry email notices?

You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.

We notice you're using an ad blocker

We understand why you use ad blockers. However to keep InfoQ free we need your support. InfoQ will not provide your data to third parties without individual opt-in consent. We only work with advertisers relevant to our readers. Please consider whitelisting us.