When comparing D vs Go, the Slant community recommends Go for most people. In the question“What is the best programming language to learn first?” Go is ranked 2nd while D is ranked 28th. The most important reason people chose Go is:
The language is designed in a manner that seems logical. Syntax is simplified to reduce burden on the programmer and compiler developers.
Specs
Ranked in these QuestionsQuestion Ranking
Pros
Pro Has an improved C subset
With few exceptions, D will either compile C code to work exactly as when compiled as C, or it won't compile - it won't quietly change the semantics of C code and give unexpected results. This means that D contains an improved C, as it fails compilation where type safety is missing in C.
This allows learning the same machine operations available in C and other low-level languages.
Pro Easy to read and understand code
Pro Doesn't force you to deal with memory management
When you're just starting out, dealing with manual memory management and its bugs is a huge pain! D is garbage collected by default, which removes a huge class of things that could go wrong. And later on, if you decide you don't want or need the GC, you can turn it off.
Pro Very fast compilation
D is usually up to 10 times faster than C++. Having a language that compiles this fast means that you are free to write highly optimized code because of the relatively low cost of experimentation.
Pro Unit testing built-in
D provides unittest blocks to insert code that verifies functions preform their expected behavior and document edge cases. Since these are enabled with a compiler switch, there is no need to teach new programmers how to install new libraries and import modules, instead training on test driven design can start from the very first function.
Pro Provides a powerful data structure on top of C's arrays called slices
D provides a structure that builds on C's arrays called slices. A slice is a segment of an array that tracks the pointer and the length of the segment.
Slices are extremely powerful because they combine the protection of knowing the length of the data with the garbage collector that manages the memory backing that data, thus avoiding most memory corruption issues.
Pro It's a state-of-art evolution of C
Pro Static with type inference
For a new user adding types can feel tedious, and takes focus off the meaning of the code, but they are also important for checking logic. D provides static types, and a good system to infer types, so types are checked when calling functions, but do not need to be specified everywhere, making it feel more dynamic.
Pro Provable purity and immutability
The compiler can check that functions don't have side effects, extremely important for functional programming in concurrent scenarios, and can check immutability.
Therefore, the compiler will prove that your programs are functionally pure and respect immutable data, if you want it to.
Pro Compile-time Function Execution
Pro Built-in Unicode support
Pro Industrial quality
Pro Asynchronous I/O that doesn’t get in your way
Because all types can be treated as objects, all files can call functions in the same manner -- even stdin
and stdout
. stdout.writeln();
stdin.readln();
file.writeln();
file.readln();
Pro Easy to integrate with C and C++
D practically has the same memory structure as C and C++; all D does it build a structure around that. The entire C standard library is accessible at no cost (syntactic or speed) and it's being worked on allowing the same for the C++ standard library.
Pro Designed for concurrency and parallelism
Supports first-class functionality for both concurrency and parallelism, offered as part of the standard library.
Pro Supports calling functions from types in an object-oriented manner.
if (exists(file)) {}
may be written as if (file.exists) {}.
writeln(file);
may be written as file.writeln();
isDivisibleBy(10, 2);
may be written as 10.isDivisibleBy(2);
writeln(isEven(add(5, 5)));
may be written as 5.add(5).isEven().writeln();
Pro Simplified C-like syntax that is as easy to read and write as Python
The language is designed in a manner that seems logical. Syntax is simplified to reduce burden on the programmer and compiler developers.
Pro Great team working behind it
Go has a solid team of engineers working on it (some of the best networking engineers in the world are working on Go). Up until now, the great engineering of the language has compensated for its lack of power.
Pro Easy to install and configure; simple to compile software
Go software can be immediately installed, regardless of your operating system, package manager, or processor architecture with the go get command. Software is compiled statically by default so there is no need to worry about software dependencies on the client system. Makefiles and headers are no longer necessary, as the package system automatically resolves dependencies, downloads source code and compiles via a single command: go build
.
Pro Programmers don't have to argue over what 10% subet of the language to implement in their software project
The language promotes programming in a specific idiomatic style, which helps keep every programmer on the same page.
Pro Supports 'modules' in the form of packages
Every Go source file contains a package line that indicates which package a file belongs to. If the name of the package is 'main', it indicates that this is a program that will be compiled into a binary. Otherwise, it will recognize that it is a package.
Pro Demonstrates a unique, simple concept to object-oriented programming
All types are essentially objects, be they type aliases or structs. The compiler automatically associates types to their methods at compile time. Those methods are automatically associated to all interfaces that match. This allows you to gain the benefits of multiple inheritance without glue code. As a result of the design, classes are rendered obsolete and the resulting style is easy to comprehend.
Pro Great language for building networking services
Go was started as a systems language but now it has fully committed in the niche of networking services. This has been a brilliant move by Go because it allows them to capitalize on the immense talent of the Go engineering team (who are in the most part network engineers).
In a world dominated by Java EE and slow scripting language, Go was a breath of fresh air and it continues to be one of the most powerful languages if you want to build networking services.
Pro Exceptionally simple and scalable multithreaded and concurrent programming
Goroutines are "lightweight threads" that runs on OS threads. They provide a simple way for concurrent operations — prepending a function with go
will execute it concurrently. It utilizes channels for communication between goroutines which aids to prevent races and makes synchronizing execution effortless across goroutines. The maximum number of OS threads goroutines can run on may be defined at compile time with the GOMAXPROCS
variable.
Pro The go compiler compiles binaries instantly — as fast as a scripting language interpreter
Compiled binaries are fast — about as fast in C in most cases. Compiles on every OS without effort — truly cross-platform compiler. As a result of the fast compilation speed, you can use the gorun program to use go source code as if it was a scripting language.
Pro Performance is on the order of C and Java
Go is blazing fast, but easier to write than Python, JS, Ruby, or many other dynamic languages.
Pro Jobs available
You can find a Job knowing Go. Which is more than can be said with many other languages.
Pro API documentation is rich in content; easy to memorize
Only features deemed critical are added to the language to prevent cruft from working its way into the language. The language is small enough to fit inside one's head without having to repeatedly open documentation. Documentation is hosted on an official webpage in a manner that is simple to read and understand.
Pro Supports functional programming techniques such as function literals
This naturally also supports first class and high order functions, so you may pass functions as variables to other functions.
Pro Multiple variables may be assigned on a single line
This conveniently eliminates the need to create temporary variables.
Fibonacci example: x, y = y, x+y
Pro Built-in unit testing
The idiomatic approach to writing a Go software project is to perform test-driven development with unit testing. Every source code file should have an associated *_test.go
file which tests functions in the code.
Pro Provides tools for automatically formatting code for your entire software project
This helps keep every programmer on the same page in a project and eliminates arguments over formatting styles.
Pro Automatically generates API documentation for installed packages
Godoc is provided to automatically generate API documentation for Go projects. Godoc also hosts its own self-contained web server that will list documentation for all installed packages in your Go path.
Pro Supports splitting source code into multiple files
As long as every source code file in a directory has the same package name, the compiler will automatically concatenate all of the files together during the compilation process.
Pro Syntax for exported code from a package is simplified to be less verbose than other languages
Any variable, type and function whose name begins with a capital letter will be exported by a project, while all other code remains private. There is no longer a need to signify that a piece of code is 'private' or 'public' manually.
Cons
Con Poor adoption even after many years of existence
There's a widely accepted perception of D as a language that has been poorly adopted. Since adoption is driven by perception this becomes a fact. So managers and engineers start becoming nervous in adopting a language that has such a perception among the community and that has been so unsuccessful for so long.
Con Failed at becoming alternative to C or C++
Almost as confused and complicated as C++, but without the popularity and widespread corporate usage. Also failed at becoming a good cross-platform GUI application development language like Object Pascal. Many missed past opportunities, and now newer languages are better alternatives.
Con Lack of vision
D is community-driven and lacks the support of any large corporation. While this increases the amount of talent and engineering abilities of the people working on D, it also brings a severe lack of charisma, leadership and vision.
Con Garbage Collection
Memory is not managed directly.
Con All the downsides of garbage collection without any of its benefits
When D decided to implement garbage collection it instantly alienated a large community of developers (C and C++ programmers). For them, the official policy has been: "Don't want garbage collection? Use D with RAII or manual management style!".
While true, it's also absolutely pointless because there's little to none support for alternate memory management styles in the standard library, which means that a new user will have to start with a language that is stripped down of the core infrastructure.
On the other hand, for those people who want to use garbage collection, the implementation of it is lackluster.
Con Golang controlled by Google
Solves Google problems, which might not be your or the majority of user's problems. Was created for the benefit and purposes of Google, so is less flexible in language direction and options.
Con Hard to abstract even the simplest notions
Go is famously regarded as very simple. However, this simplicity becomes problematic in time. Programmers who use Go find themselves over and over again writing the same thing from a very low point of view. Domains not already served by libraries that are easy to glue are very difficult to get into.
Con Forces K&R style and won't allow Allman style
Golang developers were extremely short-sighted and biased by forcing the K&R style, which should never have happened. Basically kicking Allman style users out of their language.
Con Doesn't have true enums
Golang does weirdness with const versus having real enums, like other languages. This reflects the stubbornness and shortsightedness of the core developers, similar to the issue with generics, where it was denied that it was needed until it became too obvious that it should have been added years ago.
Con Does not have sum types
Makes it harder to have functions of different parameters types in a non OOP language. Thus messy generics and interfaces, and more confusion, where sum types could have solved a number of issues.
Con It appears Google uses position to snuff out or suppress other languages
Newer languages that could threaten Golang (or other Google controlled languages) appear to have suppressed search results on Google and YouTube. Dangerous situation where large company can manipulate user choice and market share. The freedom to freely choose and user rights need to be protected.
Con Designed to make the programmer expendable
Go was designed for large team projects where many contributors may be incompetent. That Go can still get things done under these conditions is a testament to its utility in this niche. Go's infamously weak abstraction power is thus a feature, not a bug, meant to prevent your teammates from doing too much damage. This also means any team member can be easily replaced by another code monkey at minimum cost. Good for the company, bad for you. The more talented programmers, on the other hand, will be very frustrated by having one hand tied behind their back.
Con Easy to shadow variable
Due to single character only difference, declare and assign statement can easily shadow variable from outer scope unconsciously. Example:
err := nil
if xxx {
err := somefunctionthatreturnsanerr
}
return err // always return nil
Con No forms designer
Those who are used to Visual Studio can feel the lack of a forms designer for rapid development.
Con Bizarre syntactic choices like a unique date format.
Con Changing visibility requires renaming all over the code
Con Lacks support for immutable data
Only way to prevent something from being mutated is to make copies of it, and to be very careful to not mutate it.
Con Performance slowdown because of indirect calls and garbage collection
Practically no meaningful Go application can be written without indirect function calls and garbage collection, these are central to Go's core infrastructure. But these are major impediments to achieving good performance.
Con Implementation of interfaces are difficult to figure out
Finding out what interfaces are implemented by a struct requires a magic crystal ball. They are easy to write, but difficult to read and trawl through.