When comparing Scheme vs D, the Slant community recommends Scheme for most people. In the question“What is the best programming language to learn first?” Scheme is ranked 8th while D is ranked 28th. The most important reason people chose Scheme is:
Scheme syntax is extremely regular and easy to pick up. A *formal* specification of the syntax fits onto just a few pages; it can be introduced informally in a paragraph or two. Students are not distracted by remembering how to write if statements or loops or even operator precedence because every syntactic follows the same pattern. Ultimately, everything looks something like this: (func a b c) This includes not only user-defined functions but even control flow: (if cond then-clause else-clause) or even primitive operations like `define` and `set`: (define foo 10) (set! foo 11) This means that nothing really has special syntactic treatment in the language. There are essentially no weird edge-cases to memorize, and different concepts are given a more equal weight in the language. (Unlike Algol-like languages which tend to given undue weight to loops and assignment statements, for example.)
Specs
Ranked in these QuestionsQuestion Ranking
Pros
Pro Simple syntax
Scheme syntax is extremely regular and easy to pick up. A formal specification of the syntax fits onto just a few pages; it can be introduced informally in a paragraph or two. Students are not distracted by remembering how to write if statements or loops or even operator precedence because every syntactic follows the same pattern.
Ultimately, everything looks something like this:
(func a b c)
This includes not only user-defined functions but even control flow:
(if cond then-clause else-clause)
or even primitive operations like define
and set
:
(define foo 10)
(set! foo 11)
This means that nothing really has special syntactic treatment in the language. There are essentially no weird edge-cases to memorize, and different concepts are given a more equal weight in the language. (Unlike Algol-like languages which tend to given undue weight to loops and assignment statements, for example.)
Pro No magic - it's clear how everything works
Scheme has far less built into the language itself, helping students see that things like OOP are not magical: they are just patterns for organizing code. Everything in Scheme is built up from a very small set of primitives which compose in a natural and intuitive fashion.
Having a language that does not accord many things special status helps keep students open minded. This will help students later go between different languages and paradigms from procedural to object-oriented to functional.
Pro Great at teaching fundamental programming ideas
Scheme teaches the important, fundamental ideas immediately without the distraction of unnecessary syntax or language features.
Pro Multi platform
GNU/Linux, OS X, and Windows versions available.
Pro Great, well known textbooks
There is a set of very strong textbooks introducing CS and programming using Scheme. These books are available for free online.
The most famous example--and one of the most famous CS books full stop--is Structure and Interpretation of Computer Programs usually known as SICP. This book introduces fundamental ideas in computer science and covers an incredible amount of material quickly and clearly without requiring any prior knowledge.
However, some people find SICP a bit challenging as a first text. Happily, there are other more introductory texts as well. Simply Scheme is a book designed to be read before SICP, easing beginners into the language as well as CS and programming in general. How to Design Programs is another text used in introductory college courses.
Pro Encourages creativity
Pro Robust metaprogramming
The quotation functionality of Lisp allow for extremely powerful, yet syntactically straightforward metaprogramming via macros. This is more powerful than the C preprocessor while being less involved than something like Template Haskell or F# quotations.
Using macros to properly decompose a problem domain teaches new developers good habits, improving composibility and reliability when tackling large programs. Scheme metaprogramming also serves as a gentle introduction to domain specific languages.
Pro Multiparadigm
Unlike most languages, Scheme actually accords both functional programming and imperative programming roughly equal status. Many other languages like Python and Java are staunchly imperative while SML and Haskell are primarily functional; Scheme is a nice middle ground.
Additionally, since Scheme syntax is extremely flexible, it can easily be re-purposed for teaching non-deterministic and logic programming. There is no need to learn a new language like Prolog when the same ideas can easily be expressed with Scheme syntax.
This gives students a good perspective on different ways to think about and organize programs, which makes it much easier to move forward to other languages and technologies.
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();
Cons
Con Little job market
There are little to none jobs searching for a Scheme programmer. The ones that exist are more related to Research in Maths or Artificial Intelligence.
Con A language that is purely academic
If someone said "I am starting a project in Scheme" then they are either talking about their homework or they are starting a joke.
Con Fragmented ecosystem
Scheme is an IEEE standard, not an implementation. Unfortunately, the standard is too minimal and practical implementations have diverged--they had to expand on the standard to get anything done, but did so in incompatible ways.
The later de facto standard R6RS tried to correct this, but lost Scheme's minimalist elegance in the process. The newer R7RS standard takes the best of both worlds with an elegant minimalist core and a practical standard library.
Con Very different semantics from mainstream programming languages
LISP-like languages are very different from mainstream languages (such as C/C++/Java/JavaScript/Python/you-name-it) - both in semantics and syntax. This, in turn, severely limits uses of whatever-learned-with-Scheme, for real-world use.
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.