The D Programming Language
As a rule, D uses exceptions for error handling as opposed to error codes. D uses the try-catch-finally model for exceptions, which allows cleanup code to be inserted conveniently in the finally block. For those cases when the finally block is insufficient, scope statements come in quite handy.
Like any object-oriented language, D has the ability to create object classes. One major difference is the lack of a virtual keyword, unlike with C++. This is handled automatically by the compiler. D uses a single-inheritance paradigm, relying on interfaces and mixins, which are discussed later to fill in the gaps. Classes are passed by reference rather than by value, so the programmer doesn't have to worry about treating it like a pointer. Furthermore, there is no -> or :: operator; the . is used in all situations to access members of structs and classes. All classes derive from Object, the root of the inheritance hierarchy:
class MyClass {
int i;
char[] str;
void doSomething() { ... };
}
Classes can have defined properties by having multiple functions with the same name:
class Person {
private char[] PName;
char[] name() {return PName;}
void name(char[] str)
{
// do whatever's necessary to update any
// other places where the name is stored
PName = name;
}
}
Classes can have constructors and destructors, namely this and ~this:
class MyClass {
this() { writefln("Constructor called");}
this(int i) {
writefln("Constructor called with %d", i);
}
~this() { writefln("Goodbye");}
Classes have access to the constructors of their base class:
this(int i) {
super(1, 32, i); // super is the name of the
// base class constructor
}
Classes can be declared inside other classes or functions, and they have access to the variables in that scope. They also can overload operators, such as comparison, to make working with them more obvious, as in C++.
Classes can have invariants, which are contracts that are checked at the end of constructors, before destructors and before public members, but removed when compiling for release:
class Date
{
int day;
int hour;
invariant
{
assert(1 <= day && day <= 31);
assert(0 <= hour && hour < 24);
}
}To check whether two class references are pointing to the same class, use the is operator:
MyClass c1 = new MyClass;
MyClass c2;
if(c1 is c2)
writefln("These point to the same thing.");An interface is a set of functions that any class deriving from it must implement:
interface Animal {
void eat(Food what);
void walk(int direction);
void makeSound();
}
In D, there is no inline keyword—the compiler decides which functions to inline, so the programmer doesn't even have to worry about it. Functions can be overloaded—that is to say, two functions with the same name can take different parameters, but the compiler is smart enough to know which one you're talking about:
void func(int i) // can implicitly take
// longs and shorts too
{...}
void func(char[] str)
{...}
void main()
{
func(23);
func("hello");
}
Function parameters can be either in, out, inout or lazy, with in being the default behavior. Out parameters are simple outputs:
void func(out int i)
{
I += 4;
}
void main()
{
int n = 5;
writefln(n);
func(n);
writefln(n);
}
inout parameters are read/write, but no new copy is created:
void func(inout int i)
{
if(i >= 0)
..
else
..
}
Lazy parameters are computed only when they are needed. For example, let's say you called a function like this:
log("Log: error at "~toString(i)~" file not found.");Notice that every time you call it, the strings are concatenated and passed to the function. The lazy storage class means that the strings are put together only if they are called upon, increasing performance and efficiency. Nested functions in D allow the nesting of functions within other functions:
void main()
{
void func()
{
..
}
}
Nested functions have read/write access to the variables of the enclosing function:
void main()
{
int i;
void func()
{
writefln(i + 1);
}
}
Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
| Dart: a New Web Programming Experience | May 07, 2013 |
- RSS Feeds
- New Products
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Home, My Backup Data Center
- Dart: a New Web Programming Experience
- Developer Poll
- May 2013 Issue of Linux Journal: Raspberry Pi
- Trying to Tame the Tablet
- Google Docs
2 min 19 sec ago - Reply to comment | Linux Journal
4 hours 50 min ago - Reply to comment | Linux Journal
5 hours 37 min ago - Web Hosting IQ
7 hours 11 min ago - Thanks for taking the time to
8 hours 48 min ago - Linux is good
10 hours 45 min ago - Reply to comment | Linux Journal
11 hours 3 min ago - Web Hosting IQ
11 hours 33 min ago - Web Hosting IQ
11 hours 33 min ago - Web Hosting IQ
11 hours 34 min ago
Enter to Win an Adafruit Prototyping Pi Plate Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Prototyping Pi Plate Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- Next winner announced on 5-21-13!
Free Webinar: Linux Backup and Recovery
Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.
In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.




Comments
What a badly designed language
I can't see any better than C/C++ or Python.
the "~" concatenating operator is ugly than any other language,
the gc makes it not a pure compiling language.
It's pure compiling
It's pure compiling language! "~" is used becouse, "+" means addition, not concatenating. You can find rational arguments for this and other problems on D web page.
BTW. "inout" parameters are now renamed to "ref".
As of 1.011
"BTW. 'inout' parameters are now renamed to 'ref'."
As of 1.011
Funny though, its badly designed because it uses ~ and has gc. And I wonder what pure compiling means if gc makes this no longer true?
Why makes gc pure compiling no longer true
Why makes gc pure compiling (whatever that means) no longer true ? GC is done by the runtime and has nothing to do with compiling. D is a "pure compiling" language (as pure as you can get - there is nothing more pure than compiling into platform dependent native code). And why is a language badly designed just because it has the option to use garbage collection (in D you can manage memory by yourself and turn garbage collection completely off, if you want to) ?
Using ~ for concatenating arrays and not + makes sense because your not adding strings like you are adding numbers. But that might be just a matter of taste.
But if these two things are the only criterions for you to decide if a language is good or bad designed, you should better not become a language designer.
Improvements over C++
For a (not complete) list of things which are "improvements" over C++ just take a look at
http://eureka3d.com/blog/2006/the-d-progamming-language-a-pleasant-surpr...
As always this is a matter of taste and personal preference. But C++ had to be designed to be backward compatible to C, so some things could not be as clean designed as they should be and make the language more complicated and error prone.