Learn to Code via Tutorials on Repl.it!

← Back to all posts
DLang template/tutorial
h
CodeLongAndPros (963)

Written by @CodeLongAndPros && @StudentFires

Hello Repl.it community! You all know we only have a small set of languages available, right?

Did you know that there's plety of language requests that go unseen and ignored, or are just phased out by the passage of time.
Have you ever heard of:

  • BCPL
  • Ada
  • Oberon

One of the many languages that went unseen was Dlang, or simply D. So, what is D? You might've never heard of it. D is a modern language that can be considered to be a "better C." It has many features of C++ and C that it has improved upon.
As an added bonus, it compiles incredibly fast! Comparable to that of C itself, with all of power of C++!

Make a new D repl.
Let's view a simple example of a "hello, world" program written in D:

import std.stdio: writeln;

int main(string[] args) {
	writeln("Hello world");

	return 0;
}

The very first line is an import statement.

import std.stdio: writeln;

This specific import imports the writeln (writeline) function from std.stdio. This allows it to write to the terminal, as D lacks any built-in capability to do so.
So, C has it's #include preprocessor statment, so what's so much better about it?

  • Cleaner syntax
  • Submodules
  • Selective imports

Next, we have the generic main function that C and C++ have. This maps to _start, like in C(++):

int main(string[] args) {
	writeln("Hello world");

	return 0;
}

The main function simply takes an array of strings.

Here, instead of printf or std::cout, we use the consise writeln, newline included.

Think about that for a second: C's printf requires you to manually write out the types of arguments passed, and the format it's in. D's writeln function determines the types used for you, meaning not only is it type-safe, it's much easier to use!

This function can take mutliple arguments, like Python's print.

If you want printfesque formatting, import printfln.

We made a simple Repl allowing you to use D in Repl today! It's attached to this post, fork it and start writing!

Want to learn about the langauge yourself?
For more information, go check out the DLang tour.

Commentshotnewtop
HahaYes (1052)

NOOO THE TUTORIAL SECTION IS FALLING

CodeLongAndPros (963)

@StudentFires He's like BillG. Look at my bio.

StudentFires (341)

@CodeLongAndPros I'd already seen your bio. And read the post.

CodeLongAndPros (963)

@StudentFires Wait are you replying to my content or @HahaYes'?

StudentFires (341)

@CodeLongAndPros The bio thing: you, the "how could you say that": HaHaYes.

CodeLongAndPros (963)

@StudentFires Well, the:

Linus Torvalds jokes about world domination, but Bill Gates means it.

It applies to @HahaYes as BillG and to me as LinusT.

HahaYes (1052)

@CodeLongAndPros here ya go, a updated profile now

CodeLongAndPros (963)

sudo pacman -R @ HahaYes go brrrr

HahaYes (1052)

@CodeLongAndPros intellectual property has the shelf life of a banana

CodeLongAndPros (963)

@HahaYes
$ logout

But your tutorials will not stand!

StudentFires (341)

@CodeLongAndPros I can make a full C++ course in a month, 2 well-written moderate-length tutorials every day, and that's at worst. Wanna help me out? Oh wait, you don't know C++ too well, do you?

StudentFires (341)

@CodeLongAndPros Actually... I can teach C++ as if the person already knows Python, JavaScript, or C, especially since everyone here knows Py and JS. How about it?

Btw, this was my domain from the beginning, I just went dormant.

HahaYes (1052)

@StudentFires sadly your domain kinda got taken by me.
insert image of STONKS here

StudentFires (341)

Umm... where's the attached file? lol, just fork it.