When comparing Nim vs OCaml, the Slant community recommends Nim for most people. In the question“What are the best (productivity-enhancing, well-designed, and concise, rather than just popular or time-tested) programming languages?” Nim is ranked 4th while OCaml is ranked 19th. The most important reason people chose Nim is:
Checks your code at compile time.
Ranked in these QuestionsQuestion Ranking
Pro Strict typing
Checks your code at compile time.
Pro Really crossplatform
The same code can be used for web, server, desktop and mobile.
Pro Easy to read
Nim has a lot of common with Python in terms of syntax.
Indentation-based syntax, for/while loops
Pro Built-in Unicode support
You can use unicode names for variables, there is "unicode" module for operations with unicode
Pro Multi paradigm
Imperative, OOP, functional programming in one language.
Pro Great metaprogramming features
There are generics, templates, macros in Nim. They can allow you to write new DSL for your application, or avoid all boilerplate stuff.
Pro Type interferencing
You only need to specify types in your procedures and objects - you don't need to specify type when you're creating a new variable (unless you're creating it without initialization)
Pro Has built-in unittest module
With built-in "unittest" module you can create test with a very readable code
You don't need to deal with all those manual memory allocations, Nim can take care of it!
But also you can use another GC, or tweak it for you real-time application or a game
Pro Easy to integrate with another languages
You can use Nim with any language that can be interfaced with C.
There's a tool which helps you to create new C and C++ bindings for Nim - c2nim
Pro Compile-time execution
Nim has built-in VM, which executes macros and some other code at compile time.
For example - you can check if you're on Windows, and Nim will generate code only for it
Pro Supports UFCS (Unified Function Call Syntax)
writeLine(stdout, "hello") can be written as stdout.writeLine("hello")
proc add(a: int): int = a + 5 can be used like 6.add.echo or 6.add().echo()
Pro Has built-in async support
Nim has "asyncdispatch" module, which allows you to write async applications.
Pro Encourages functional style
It steers you towards a functional style, but doesn't bother you with purity and "monads everywhere" like other languages, such as Haskell.
Pro Actively-developed functional programming language at the forefront of research
Functional programming is based on the lambda calculus. OCaml is in its functional parts almost pure lambda calculus, in a very practical manner: useful for many daily programming tasks. The acitve development makes improvements to the type system like generalized algebraic data types (GADT) or polymorphic variants, so when learning this language you get at once a down to earth usable compiler and advanced abstraction features.
Pro Sophisticated and easy-to-use package manager
OPAM is a package manager for OCaml, which is really easy to use, just like npm. It creates a .opam folder in home directory.
The documentation is great as well, and you can switch between multiple versions of OCaml for each project. You can also package your project and publish it on OPAM repositories, even if the dependencies do not exists on OPAM.
Pro One of the best for writing compilers
OCaml is compiled to native binary, so it's amazingly fast. Being a member of ML-family languages, it has expressive syntax for trees, and has great LLVM support.
Pro Stable syntax
The syntax is consistent, some syntaxic sugar but at a reasonable level, so reading code of others isn't too much confusing.
Pro Strong editor integration
merlin editor tool provides all you need to develop OCaml in your favourite editor.
Con Still in pre 1.0
Not very stable and has a rather small community.
Con Strong focus on *nix systems, lacking native support for MS Windows
Lacks native support for Windows systems.