D- The Programming Language

Views:
 
Category: Education
     
 

Presentation Description

COP4020 Programming Languages Project

Comments

Presentation Transcript

PowerPoint Presentation:

Jared Mushill

Overview:

Overview History What is D? Why Create D? Why Use D? What Was Removed From C++? What Was Added to D? Conclusions

Walter Bright:

Walter Bright D was first created in 2001 by Walter Bright of Digital Mars. Walter Bright was first known for creating the first C++ compiler that compiled directly into object. Previous compilers first went through C. Bright received his BS in mechanical engineering from Caltech in 1979.

Andrei Alexandrescu:

Andrei Alexandrescu Beginning in 2006, Alexandrescu began assisting Walter Bright with the creation of D. Alexandrescu is Romanian born and is primarily a C++ programmer. He received his MS in electronics from the Polytechnic University of Bucharest in July 1994. Later receiving another MS and then PhD in computer science from the University of Washington.

History:

History As previously stated, the creation of D began in 2001, however the first true release of D version 1.0 did not occur until January 2005. It is currently available in both v1 and v2 flavors, though digitalmars.com suggests that v2 should be used for new projects as it has more support. According to the Change Log, the most recent version of D is 2.060, released August 2, 2012.

What is D?:

What is D? D is based off of C++ while also adding features from other well-known languages such as Python, Java, and C#. D is statically typed and then compiled into object files which are then linked into executables. Therefore D is not a scripting language and does not require a virtual machine to run.

Why Create D?:

Why Create D? If C++ already exists, why even bother trying to improve upon it with features from other languages? Addressing this, the goal of D was really to remove the unwanted features from C++ and add desirable features from other well known languages to create a language that was as easy to use as possible. In an interview in which Bright was asked why he created D, he responded, “Over the years, C++ has grown by layering on needed features without disturbing backwards compatibility. Often this results in some very strange rules and surprising corner cases…C++ has reached a certain level of maturity now, its period of rapid evolution is over. So the time is right to see what can be done with a redesign.”

Why D?:

Why D? The Primary purpose of D is to improve on C++ while maintaining its high functionality. D is defined as an object-oriented, garbage collected, systems programming language. The general feel and syntax of D will be very familiar to those who know C++. Therefore D is for programmers that want broad functionality of C++, without the hassle of dealing with memory management, pointer debugging, and other such features.

From C++ to D:

From C++ to D Because D is based off of C++ it maintains most of the syntax from C++ and most of its core features. Bright and Alexandrescu chose to do this in order to reduce the learning curve for C++ programmers wishing to learn D. As can be seen in the next slide, C++ and D look very similar. This makes it very easy to learn D with just a bit of documentation to clear things up.

C++ vs D:

C++ vs D #include < iostream > int main() { std:: cout << "Hello, World."; } import std.c.stdio ; int main(char[][] args ) { printf ("Hello, World!\n"); return 0 ; } OR import std.stdio ; void main() { writeln ("Hello, World!"); }

What was left out?:

What was left out? C source code compatibility C preprocessor and Macros Multiple Inheritance Namespaces Forward Declarations Include files 16 bit support

C Source Code Compatibility:

C Source Code Compatibility One of Bright’s main complaints of C++ was that it was trying to advance while still maintaining backwards compatibility. For this reason, he chose to entirely forego backwards compatibility with both C++ and C. Dlang.org states, “Realistically, nobody is going to convert million line C or C++ programs into D. Since D does not compile unmodified C/C++ source code, D is not for legacy apps.”

Preprocessor commands and Macros:

Preprocessor commands and Macros Bright felt that Macros grew too complicated in the language. He felt that the purpose of Macros could be designed directly into the core of the language itself, instead of having a combination of two languages within one. Those being the Macro and preprocessor language before the program and then the C/C++ program itself.

Multiple Inheritance:

Multiple Inheritance Multiple Inheritance is a feature of C++ that some may not even know it exists. This feature allows a child class to be made from multiple parent or base classes. This can be a very powerful feature, though it is seen by many to be convoluted and difficult to manage. For these reasons, Multiple Inheritance was left out of the language in order and replaced in favor of single inheritance combined with templates.

Namespaces:

Namespaces Bright felt that namespaces were a step in the right direction for connecting together independent code. Though, he chose to forego namespaces for his own system called Modules which will be discussed later on.

Forward Declarations:

Forward Declarations Forward Declarations are the idea that functions must be declared in a namespace, or in this case module, before they can be used. Bright saw that C++ had advanced this by allowing class members to reference those members defined after them. This allowed Bright to forego the whole idea of Forward Declaration entirely with D. A function need not be declared before it is referenced, or at all for that matter. But the idea of function declarations will be discussed further as well.

Include Files:

Include Files Bright was actually very against the idea of include files. He felt that it was a very clumsy way of adding code libraries to other bits of code as it required the compiler to reparse the include files all over again. Instead, he chose to use importing, which is seen in Java and other languages. This instead imports a symbol table, making compiling far more efficient, even if many libraries are imported.

16-bit Support:

16-bit Support This idea almost perfectly centralizes Bright’s main point in creating this language. He felt that it was no longer necessary to depend on backwards compatibility and decided to focus D on the future instead of the past. D supports both 32- and 64-bit systems.

Still C++?:

Still C++? Even with all these changes, one could see how this could just be a less powerful version of C++. But Bright’s purpose was not just to strip C++ of unwanted features, he also wanted to add features that would make C++ more usable, even if it meant stripping some of the flexibility.

Added Features of D:

Added Features of D Modules Function Declaration vs Definition Array Features Garbage Collection

Modules:

Modules Modules are just a more simple way to include source code into a program. Instead of having to #include the source code to the top of the new code one simply imports the module in its entirety. Bright also allowed for the same module being imported multiple times if it is featured in other imported modules, as the compiler just uses one.

Function Declaration vs Definition:

Function Declaration vs Definition I personally find this to be the most elegant addition to D. As stated before D foregoes the requirement for forward declaration, but it is more than that. D foregoes the requirement for declaration at all. A programmer is merely required to define a function at the time of use and the compiler extracts a sort of declaration from it based on the definition. This also allows a function to be referenced before it has appeared even once in the code, which makes for simpler and less error-prone code.

Array Features:

Array Features Another large goal was to simplify the use of arrays in their entirety. The difference between static and dynamic arrays are as simple as: int [3] array; //a size 3 static array of integers Or int [] array; // a dynamic array of integers. These new arrays also store the information for the array, such as its size, in the array itself. These features can be found in C++ using libraries, but Bright thought they were used so often, they should be included in the core language itself.

Garbage Collection:

Garbage Collection Garbage Collection is the general term for automatic memory management. In C++ a programmer is required to de-allocate dynamically allocated memory once it is no longer needed in order to prevent memory leaks or overflows. D draws a feature from Java called garbage collection which allows a programmer to allocate dynamic memory and allow a garbage collector to come along and clear up the memory at its convenience. This feature may be missed by some C++ programmers that use destructors to free up memory at the exact time they need to create very efficient code, but Bright feels that the average programmer will find this a welcome inclusion.

What’s the Verdict?:

What’s the Verdict? The verdict in the programming community is mixed. Many feel that if a programmer wants to use a program like C++, why not just use C++. Others feel that this is a way for programmers that do not need the extreme flexibility and low-level programming features of C++ to use a similar language that is more usable and less finicky. Personally, knowing both C++ and Java I would likely not use it too often. The purpose of D is to simplify features of C++ and extend Java to make it more powerful, but it almost starts to become a “Frankenstein” language as different pieces and parts are removed.

authorStream Live Help