Originally published on 01 October 2019
I've always had an interest in programming for as long as I can remember, starting with manually copying lines of Basic code from the back of computer magazines into various early Apple computers. Since then, I have dabbled in a number of programming languages including:
To be clear, I am not a professional programmer or software engineer, but as hopefully this blog has shown, I like to dip my toes in the technical pool every now and then. Programming is relatively easy to get started in, has an initially shallow learning curve, but can take years to master. For the past several years, I had focused on learning Python (first Python2 and then Python3) as this is most often recommended as a good choice for novice programmers like me. But just because it's good for beginners doesn't mean that it is limited in its feature set or functionality. Python's "batteries included" philosophy means that it's standard library is filled with a wide variety of easily importable modules to get you up and running quickly or to solve complex programs with just a few lines of code. Python also has a large number of valuable packages (similar to Perl's CPAN, R's CRAN or Rust's Crates) that are just a pip install
away. Armed with a number of online tutorials, I set out to learn as much about it as I could.
I've often heard advice that the best way to learn a language is to apply it to a real world problem. Since I didn't really have one, I went in search of one and stumbled across the Project Euler site, which contains, at the time of this writing, over 600 math puzzles for you to solve. The beauty of the site is that while a program should be able to solve the problem in under a minute, it can take you hours or days (or in my case weeks) to come up with an algorithm or solution. Once you do solve the problem, the site unlocks a discussion forum where you can share your solution or approach with others who have similarly solved it. This is another good way to learn about programming and more importantly, algorithms (as many of the initial problems can be solved with just pen and paper!). Over the course of a few years working on Project Euler, I was able to solve 62 problems -- not great, but not horrible as this is just a hobby for me in my limited spare time.
Because I cannot stick with one thing for very long though, I began to hunt for another language to try. While I had only scratched the surface of Python, I wasn't completely enamored with all of the indentation and white space requirements and I started longing for something that would provide me with static typing. Python's dynamic typing is great for small projects or quick prototyping but I often found myself running into issues where static typing would provide more safety. At the time, Go and Rust were two of the relatively popular newcomers which seemed like good contenders to explore. Go is a simple (or perhaps small is a better adjective) yet powerful language from Google geared toward solving enterprise scale problems and comes with strong support of concurrency via goroutines and channels. Go is often portrayed as a worthy successor to C. Rust is another option I briefly experimented with in my quest to find another language to "master". Rust hails from the folks at Mozilla and is billed as providing safer memory guarantees through its ownership, lifetimes and borrowing models (concepts which, like garbage collection, are way over my head). It is often seen as a replacement for C++.
Unfortunately, neither Go nor Rust really stuck with me. There is nothing inherently wrong with either language (both are used extensively by big companies in production) but none of them was really fun for me. I found Rust in particular, to be really difficult to pick up despite the great documentation and very helpful community. The learning curve was just too steep for me. I then began picking up snippets of D amongst various comments on Hacker News. I can't remember precisely which one tipped me over the edge but I eventually found myself looking through the D language home page and tutorials which really perked up my interest.
D, like Rust, can be seen as a replacement of successor of C++. I am not a historian on the origin of programming languages so please don't hold me to these pronouncements. While D has been around for a number of years, it is not relatively popular compared to Go or Rust. But none of that really matters to me as I don't program for a living. Given that I have some background and experience with C and C++, I found D relatively easy to take up. I don't mind the brackets ({
, }
) or the semicolons (;
) and in fact miss them when I occasionally go back to Python. Besides the clean aesthetics though, here are some of the other reasons why I have been spending more time with D:
Centralized knowledge base. The D language web page has pretty much everything you need to learn about and explore the language. From here you can run through the tutorial, read the documentation, browse the vast collection of packages or file a bug. While the language is almost 20 years old, the web site looks clean and modern and doesn't appear to carry the baggage of other languages similar in age. It is the official and canonical site to go to for information on the language so you don't have to go very far to hunt down the information you need.
Standard Library. D comes with a fairly comprehensive standard library, though I don't know how it compares to other languages. For me, outside of std.stdio, the majority of my needs are satisfied by what you can find in std.algorithm, std.array, std.math and std.string. On occasion, I've had to use things like std.datetime, std.bigint or std.regex.
Excellent documentation. The maintainers of D have done a great job in writing clear and concise documentation that is actually a pleasure to navigate and read. Everything from the specification to the standard library reference is really well thought out without a lot of cruft. I really like how many of the documentation pages for package functions contain example code which can be run directly in your browser (more on this below). In addition, you can go directly to the source code in GitHub from the documentation page itself. You can also file bugs and submit pull requests to improve the documentation directly from the page as well. I just wish we didn't have two different URLs for the standard library documentation (https://dlang.org/library/ and https://dlang.org/phobos/).
Easily installable in FreeBSD. I do most of my "development" on a remote VPS running FreeBSD and it was relatively trivial to run the official install script to install the compiler and get going (and while I know you shouldn't blindly run Bash scripts you find on the internet, I did anyway and managed to live to tell about it.)
Valuable resources outside of the web site. I mentioned earlier that D's web site is kind of like a "one stop shop" for everything you need to learn D and start getting productive. There are, however, a couple of other valuable resources that are worth mentioning as they have been very helpful to me in learning the language. The first, and most important for me, has been Ali Çehreli's book "Programming in D". Ali's book is not only a great introduction to D in particular, but it also makes for a great introduction to programming in general. It starts off with very basic concepts such as how to declare variables and work with logical expressions but also goes into advanced topics beyond my comprehension such as contract programming and memory management. Most chapters have practice exercises at the end along with the solutions. I wish I had come across this earlier in my programming journey.
Another book I came across is Michael Parker's "Learning D". Michael's book is a little more direct than Ali's and assumes a bit more programming experience but is still very approachable. What I really like about his book is it provides a good introduction to dub
, D's package manager which is similar to Rust's cargo
. In addition, Michael walks you through the steps to build a real world application almost step-by-step as you progress through the chapters which is a great way to learn the language.
Online "playground" to quickly test out code. One thing I enjoyed about Python was that as an interpreted language, it was really easy to start writing and executing code. Just pop open a terminal, type python3
to start the interpreter, write a command, press <Enter> and off you go. It's no different from executing commands at the shell. This makes prototyping programs or testing code very easy. Fortunately, D's web site also has an online IDE which makes doing something similar almost as trivial. I often will try out small snippets of code in the online compiler without having to fire up an editor and compile code. (Go has a similar playground as well.)
Fantastic community. Many programming languages have communities spread across the internet on various forums, mailing lists or subreddits. While that is also the case for D in some respects, I've found that the vast majority of the community congregates in the official D mailing lists. The Learn mailing list is the one I frequent the most as the members are thoughtful, civil and very responsive. Most importantly, they have shown an unlimited reserve of patience when answering my very beginner level questions.
Most, if not all, of these reasons are also applicable to a large number of other languages but how they come together for D really resonates with me.
In addition to using D to go back and redo some of the Project Euler problems, I've also started to dip my toes into the problem sets offered by exercism and Rosalind. Thanks to the many questions that the community has answered for me over the past few months, I've managed to solve 27 problems on Rosalind already! My plan is to continue working through the problem sets offered up on the online coding sites (I also want to resume Advent of Code) and going through the resources listed above to start exploring some more advance concepts such as classes, structs and unit testing.
D is not a perfect language by any stretch of the imagination but it works well enough for me. In an effort to reboot this moribund blog, I hope to document some of what I learn here, more to help me remember, but hopefully to help others as well. Let's see how far I get before I inevitably get distracted by the next new shiny thing that comes along.