Monday, January 30, 2017

D - Environment

Try it Option Online

You really do not need to set up your own environment to start learning D programming language. Reason is very simple, we already have set up D Programming environment online, so that you can build and execute all the available examples online at the same time when you are doing your theory work.
This gives you confidence in what you are reading and to check the result with different options. Feel free to modify any example and execute it online.
Try following example using Try it option available at the top right corner of the below sample code box:
import std.stdio;

void main(string[] args)
{
   writeln("Hello World!");
}
For most of the examples given in this tutorial, you will find Try it option, so just make use of it and enjoy your learning.

Local Environment Setup

If you are still willing to set up your environment for D programming language, you need the following two softwares available on your computer, (a) Text Editor,(b)D Compiler.

Text Editor

This will be used to type your program. Examples of few editors include Windows Notepad, OS Edit command, Brief, Epsilon, EMACS, and vim or vi.
Name and version of text editor can vary on different operating systems. For example, Notepad will be used on Windows, and vim or vi can be used on windows as well as Linux or UNIX.
The files you create with your editor are called source files and contain program source code. The source files for D programs are named with the extension ".d".
Before starting your programming, make sure you have one text editor in place and you have enough experience to write a computer program, save it in a file, build it and finally execute it.

The D Compiler

Most current D implementations compile directly into machine code for efficient execution.
We have multiple D compilers available and it includes the following.
  • DMD - The Digital Mars D compiler is the official D compiler by Walter Bright.
  • GDC - A front-end for the GCC back-end, built using the open DMD compiler source code.
  • LDC - A compiler based on the DMD front-end that uses LLVM as its compiler back-end.
The above different compilers can be downloaded from D downloads
We will be using D version 2 and we recommend not to download D1.
Lets have a helloWorld.d program as follows. We will use this as first program we run on platform you choose.
import std.stdio;

void main(string[] args)
{
   writeln("Hello World!");
}

Installation on Windows

Download the windows installer.
Run the downloaded executable to install the D which can be done by following the on screen intructions.
Now we can build and run a d file say helloWorld.d by switching to folder containing the file using cd and then using the following steps
C:\DProgramming> DMD helloWorld.d
C:\DProgramming> helloWorld
We can see the following output.
hello world
C:\DProgramming is the folder, I am using to save my samples. You can change it to the folder that you have saved D programs.

Installation on Ubuntu/Debian

Download the debian installer.
Run the downloaded executable to install the D which can be done by following the on screen intructions.
Now we can build and run a d file say helloWorld.d by switching to folder containing the file using cd and then using the following steps
$ dmd helloWorld.d
$ ./helloWorld
We can see the following output.
$ hello world

Installation on Mac OS X

Download the Mac installer.
Run the downloaded executable to install the D which can be done by following the on screen intructions.
Now we can build and run a d file say helloWorld.d by switching to folder containing the file using cd and then using the following steps
$ dmd helloWorld.d
$ ./helloWorld
We can see the following output.
$ hello world

Installation on Fedora

Download the fedora installer.
Run the downloaded executable to install the D which can be done by following the on screen intructions.
Now we can build and run a d file say helloWorld.d by switching to folder containing the file using cd and then using the following steps
$ dmd helloWorld.d
$ ./helloWorld
We can see the following output.
$ hello world

Installation on OpenSUSE

Download the OpenSUSE installer.
Run the downloaded executable to install the D which can be done by following the on screen intructions.
Now we can build and run a d file say helloWorld.d by switching to folder containing the file using cd and then using the following steps
$ dmd helloWorld.d
$ ./helloWorld
We can see the following output.
$ hello world

D IDE

We have IDE support for D in the form of plugins in most cases. This includes,
  • Visual D plugin is a plugin for Visual Studio 2005-13
  • DDT is a eclipse plugin that provides code completion, debugging with GDB.
  • Mono-D code completion, refactoring with dmd/ldc/gdc support. It has been part of GSoC 2012.
  • Code Blocks is a multi-platform IDE that supports D project creation, highlighting and debugging.

No comments:

Post a Comment