When comparing C++ vs Clojure, the Slant community recommends Clojure for most people. In the question“What is the best programming language to learn first?” Clojure is ranked 17th while C++ is ranked 24th. The most important reason people chose Clojure is:
Clojure programmers are highly encouraged to use immutable data in their code. Therefore, most data will be immutable by default. State change is handled by functions (for transformations) and atoms (an abstraction that encapsulates the idea of some entity having an identity).
Ranked in these QuestionsQuestion Ranking
Pro Huge language supports most everything
C++ is a large language with an even larger community and following. It has libraries for every kind of task that is possible to do with C++
Pro Powerful memory management
Allows puting large arrays on the "heap" to avoid "stack overflow".
Pro Teaches fundamental OOP
Teaches you to leverage object oriented programming.
Pro Excellent compiler optimization
Both open source compilers (such as Clang and GCC), and proprietary ones (like Intel's and Microsoft's) are very good at analyzing program flow and program optimization. This is mostly due to the widespread usage of C/C++ applications running everything from mobile/desktop/server Operating Systems, to search engines and webserver software, and the demand for performance.
Pro Teaches problem solving
The great STL is the most powerful Data Structure and Algorithms Library. It would benefit you very much in problem solving, your main main way to love programming. The code is much compact compared to Java and C#. No unnecessary classes are in your way; yet when you need classes they are available unlike C. The code runs very fast.
Pro Teaches low-level programming, but doesn't have as many pitfalls as C
Teaches data types, low-level program flow and the so common C-style syntax while not being as much of a pain as C itself.
Pro STD is often updated
The functionalities keep growing throughout the years. C++11 gave us a soft type of garbage collecting with the smart pointers.
Pro C code can be used in C++ code
Most C code will work as C++.
Pro Best way to understand algorithms
Pro Immutability is the default
Clojure programmers are highly encouraged to use immutable data in their code. Therefore, most data will be immutable by default.
State change is handled by functions (for transformations) and atoms (an abstraction that encapsulates the idea of some entity having an identity).
Pro Minimal syntax
Being a LISP, programs are simple: they're just functions and data. That it doesn't get bogged down with syntax or the loftier FP concepts like monads makes it one of most approachable functional languages for beginners.
Pro Good for writing concurrent programs
Since Clojure is designed for concurrency, it offers things like Software Transaction Memory, functional programming without side-effects and immutable data structures right out of the box. This means that the development team can focus their energies on developing features instead of concurrency details.
Pro Huge ecosystem of libraries to work with
There's a very large ecosystem of high-quality Clojure libraries which developers can use. One example is Incanter. It's a great data analytics library and a very powerful tool for dealing with matrices, datasets and csv files.
Pro Tries to solve problems as simply as possible
Simplicity is one of the pillars on which Clojure is built. Clojure tries to solve many problems in software development as simply as possible. Instead of building complex interfaces, objects or factories, it uses immutability and simple data structures.
Pro Dynamic language
A superb data processing language. While rich type and specification systems are available they are optional.
Pro Cross platform
Clojure compiles to JVM bytecode and runs inside the JVM. This means that applications written in Clojure are cross-platform out of the box.
Pro Rich Hickey
The creator is so awesome, he's a feature. Just look up his talks and see why.
Clojure has an elegant macro system which enables language additions, Domain-specific languages (DSLs), to be created much easier than most other languages (with the exception of Racket, perhaps).
Pro Great tool used in automating, configuring and managing dependencies available
Leiningen is a very useful tool for Clojure developers. It helps wiht automation, configuration and dependency management. It's basically a must for every Clojure project.
Pro Game is available with which you can learn Clojure
Nightmod is a tool used to make "live-moddable" games. It displays the game's code while you are playing and allows you to inject new code using Clojure. This can be a fun and useful experience for people trying to learn Clojure.
Pro No C/Java syntax
Con Huge language gets in the way of learning
C++ is such an atrociously over-complicated language that its learning curve may get in the way of learning fundamentals. Learning C++ well is a ten-year project, and even experts are frequently surprised by the language.
Con Module system is not great
C++ uses the
#include mechanism provided by C. Which unfortunately is a poor way of accessing the API of a library. Some of the reasons why the module system is weak are:
Compile time scalability: The compiler must preprocess every header included in a file, and every header included in those headers. This process must be repeated for every translation unit in the program. As can be imagined, this doesn't scale very well. For each header added you are increasing the compilation time exponentially.
Fragile: modules included are treated as textual imports by the compiler. This causes all sorts of problems since they are subject to any macro definitions in the time of the inclusion. If any of these macro definitions collide with a name in the library it can break the library API .
Con Undefined behavior
Subtle errors can render the entire program "undefined" by the complicated C++ standard. The standard imposes no requirements in such cases. Thus C++ compiler writers are free to ignore the existence of such cases and Bad Things are prone to happen instead. Even experts can't reliably avoid undefined cases in C++, so how can beginners be expected to do so?
Con No two programmers can agree on which 10% subset of C++ to use
C++ is such a huge and complicated language, that programmers have to learn a disciplined subset of it to reliably get anything done. The problem is, no-one can agree on which subset to use and they can't understand each other.
Con Retains nearly all bad habits of C
Con Tough to learn as the first language
Many of the concepts are hard to grasp if you have no prior programming experience.
Con Bugs easily corrupt the memory you need to find them
You can usually get a core dump, but often the call stack gets completely overwritten. Compilers are not even consistent in how they map the binary objects to code.
Con Painfully slow compilation
Beginners need fast feedback
Con No reflection
C++ objects are frustratingly opaque. This makes debugging especially difficult, something beginners have to do a lot.
Con No way to locate definitions
No modules, just files, and no way to tell where anything came from.
Con Complicated types
Con Undefined behaviors and weak limited type safety
Undefined behavior in a program can cause unexpected results, making it hard to debug. With UB, program behavior may vary wildly depending on optimization settings. There are many cases that invoke UB, such as signed overflow, invalid dereferences, large integer shifts, uninitialized variables, etc. C++ allows for non-type safe operations such as logic errors, wild pointers, buffer overflow, etc. UB and type safety issues create a large number of bugs and security vulnerabilities.
Con Standard library missing important features
Con Arcane binding rules
Con Incomprehensible operator overloading resoution
Con Exceptions incompatible with C++ manual memory management
Con Duplicates C features in incompatible ways
Arrays, strings, pointers, etc. have both C and C++ versions. Sometimes the C++ versions are worse. This is more useless trivia beginners have to sort through.
Con Confusing error messages
Clojure's error messages more often than not are very confusing. They usually involve stack traces that do not thoroughly explain where the error was caused or what caused it.
Con Tied to the JVM and it's limitations.
Some language constructs were obviously created as workarounds for JVM limitations. This makes the language much less elegant than it could have been.
Also, the JVM has a very cumbersome FFI.
Con Syntax can be alien / jarring for those used to other Lisps
Perhaps some may consider this attribute an advantage, but I do not. Clojure does not attempt to maintain significant compatibility with other Lisps. So, if you already know a Lisp or are used to the way Lisp works in general, you'll probably be confused if you take a look at Clojure. See these resources for more details on this subject: