In this post I will show a few things I've discovered quite recently, mostly concentrating on, as the title suggests, the D programming language. I'm also kinda not sure about where to put this, since it's kinda project-related, kinda personal-related and kinda like an article. But I guess the Blog section works the best for now, since I haven't started any projects on this (yet) and I don't think I'm qualified enough to write an article on this (yet). So, to the point...
I guess I should start by giving a few background details. While I have come in contact with programming before while looking into some things my brother has done with Turbo Pascal (yes, ancient now) and PHP, I haven't done any real programming until I came across UnrealScript. And while it's a scripting language, it's really high-level (compare that to HoMM3 WoG scripting implementation called ERM... Yeah). Generally it's been described as being half-C++ half-Java. I've been programming things in it for quite a while now (IIRC the first thing I tried to do was what has now evolved into Project FlashBang, AKA Unreal II/XMP Weapons, and it dates back to 2008 - but I have rewritten it from scratch a few times now, so I think I started in 2007, maybe? I don't remember). I've grown quite attached to UnrealScript, too, since it's really a language that fits my goals. I am not a conceptionalist - I don't program things because it's fun. I program them because I want to reach the result, gain some knowledge about how the PC and programs work and have fun in-between. Thus it's the result, not the way, that really matters to me, but I am always open to suggestions - most optimisations not only make the code less hacky, but it also improves the result as well as debugging.
Not a long time ago I started working on the Arcomage Clone project that was created by STiCK (who is nowhere to be seen now - anyone know where he's gone to?). That project was written in C. C is extremely similar to C++ who is in term similar to UnrealScript, so I decided to give it a try. And, well, I'm quite amazed at the sheer amount of work people who created C seem to have added in order to make sure you couldn't write programs in it. Coming from a convenient environment, C is just obstacles upon obstacles upon obstacles upon concepts that should never concern me in the first place. Seriously, why should I care about where my data is located in the memory? Sure, it might have been logical in 1972 when computers had a max of 4KB memory, but nowadays my program could be anywhere - somewhere within the 2 GBs of RAM, anywhere on the page file, in the cache, even on my flash drive. So learning about pointers that are used throughout the C code is pointless (pardon the pun :) ). Furthermore, C doesn't support a lot of things I took for granted - strings, booleans, dynamic arrays. And it even requires you to put functions in a certain order or create dummy functions, plus rewrite things into header files. Sure, there are ways to overcome or cope with these things - but I'm not programming just so I could overcome the obstacles that have been placed by others! I want to create things! Thus C doesn't leave me such a good impression.
It's still a good idea to know a programming language that could create actual programs - you can't use UnrealScript to parse a text file, for example. So I decided to go looking for alternatives. First, C++ has basically the same limitations of C, only that it supports things like strings and classes. And it's still better than Pascal, whose syntax is alien to my eyes - why all the unnecessary verboseness everywhere and AGOL syntax that makes little sense? I'd rather code in LOLCODE!
I've also taken a brief look into Java, the other end of UnrealScript. But Java is the same thing, just reversed. The syntax is rather alien (public/private everywhere, classes as functions, dummy functions, everything has to be spawned, ahh!) - it still has a lot of conceptualism. Everything is strictly Object-Oriented - while it would be OK for complex things (like the Unreal Engine), it just won't work right for simple programs. If I have one class, what sense does it make to have it object-oriented? But the thing I don't like the most in Java is availability. You don't compile EXEs - you compile .class or .jar files. What's bad in that? Well, you can only run Java code if you have a Java virtual environment (JRE, Java Runtime Environment). Again, for big projects it's just fine, but having to add a JRE requirement in a really simple program? According to the current statistics of this website (thanks, reader!), even 25% of all unique visitors doesn't have Java support. That essentially means that 25% of people who might be interested in running your Java application are not going to do that. And that's a terrible amount of people.
And then there's D. (Yes, it is officially written as a red D, although casually it can be written simply as D.) D is a language based on C++, but built for practical purposes and influenced mostly by Java. Sounds familiar? That's right! It's very similar to UnrealScript. The syntax is a tad bit different, but nothing you couldn't find or figure out yourself, plus most of the things are even more logical than in UnrealScript. Want to cast things? Use cast(type)Variable. Want two arrays of the same size? No problem, the syntax is type[size] array1, array2;. Too lazy to check what type your new variable is? No problem, let the compiler do the work for you by using the type auto. The D language has all that makes UnrealScript great - strings, dynamic arrays, booleans; it even has boolean arrays that are (for no real reason) missing from UnrealScript. And it has garbage collection - so you can get rid of pointers.
Furthermore, it supports a lot of different approaches to get the same result. Came from Java and like its OO approach? Go ahead, you can make everything OO. Came from C/Pascal and like non-OO solutions? Sure thing, you can do that as well. Enjoy using printf()? You can use it directly or use the D equivalent, writef() with the same options. Came from Pascal and are used to writeln()? Same thing, you can use writefln() with Pascal-like syntax. Nobody is forcing you to do anything - you can use what's convenient for you.
And the official D compiler, DMD, is just gold. Remember how you had to create a bunch of .o files and then compile them when you try to get even the smallest program working on GCC, and then be left to clean all those, as well as your terminal screen? That's history, since DMD is very silent and only shows errors. (Although you can make it verbose by calling dmd -v.) To compile, all you have to do is write dmd filename.d and you get the EXE. No makefile hassle any more, no lengthy IDE setup. Accidentally made a typo while writing a function's name? No fear, since DMD will not only point out that there is an error, but even suggest you the right spelling.
The only slight downside I've seen so far is the fact that D, unlike UnrealScript and just like C and C++, is case-sensitive, so Variable, variable and vArIaBlE are all different. But then again, this is quite needed for Linux developers, where file systems are also case-sensitive - that way you already pay attention to character case and are less likely to make mistakes in file I/O commands.
Thus I find D very close to me. It's very similar to UnrealScript in ease of use, power and syntax, which makes me feel at home. So if you are also someone who likes UnrealScript, I highly recommend giving D a shot, especially since it's compatible with many C and C++ libraries that can ease your life for you and extend the capabilities of your program. You won't have a hard time learning it and will have the benefit of having the knowledge of a full programming language.