Nim or formerly known as ‘Nimrod’ is a statically-typed open source programming language which combines the speed and memory efficiency of C, an expressive syntax, memory safety and multiple target languages. The language mainly focuses on compile-time mechanisms in various forms to give the programmer the power without compromising runtime efficiency.
Though Nim language is relatively younger than the popular Python language, yet it has created a buzz around the community of having a potential to replace Python.
According to a report of 2019, Python continued to be the most popular language in the industry in 2019 with its popularity growing to 68%. The favourite language for data scientists in today’s era is Python, and it has one of the largest programming communities in the world.
Nim compiles to C language so that it can run on Arduino and similar hardware. The language has several memory management strategies, including full manual memory management. Also, the binaries in Nim are smaller in size so that it can easily fit into any tiny hardware storage.
Some of the intuitive features of Nim are mentioned below.
- Nim generates native dependency-free executables and is not dependent on a virtual machine.
- Nim is self-contained as the compiler, and the standard library is implemented in Nim.
- Nim has a powerful macro system which allows direct manipulation of the AST, offering nearly unlimited opportunities.
- The Nim compiler and the generated executables support all major platforms like Windows, Linux, BSD, and macOS.
- The language is a successful combination of concepts from mature languages like Python, Modula and Ada.
Comparing Python and Nim
Below here, we have compared Python and Nim language and listed down a few differences between them.
- Pointers: In Python, there are no pointers, and everything is treated as a reference. On the other hand, there are pointers in Nim, which are mostly reserved for interfacing with C and doing low-level system programming.
- Sets: Python sets are not like Nim set type. If the values that will go in the set are known beforehand and finite, one can create an Enum for them. Otherwise one can also emulate a Python set using a HashSet. While the Nim set type is way faster and memory-efficient.
- Execution Model: The execution model of Python is a virtual machine, JIT, which is an interpreter, whereas, the execution model of Nim is machine code via C/C++, which is a compiler.
- Version: The latest version of Python is 3.x, and that of Nim is 1.x.
- Written Using: Python programming language is written in C, whereas the Nim language is written in Nim.
- Meta-Programming: The meta-programming in Python includes metaclass, eval, whereas, Nim includes template and macro.
- Package Manager: The package manager of Python is pip, and that of Nim is nimble.
- File Extensions: The file extensions of Python include .py, .pyi, .pyd, .pyo, .pyw, .pyz, .pyx whereas the file extensions of Nim include .nim, .nims.
- Imports: While Python needs a different line of codes for using imports, Nim can use the imports on the same line.
The key to understanding Nim is that it was designed to be as fast as C, also keeping in concern that the language possesses more safeness than the older language. Last year in September, the developers at Nim programming language released a version 1.0 which promised to provide a stable base and make sure that the code which compiled under Nim 1.0 continues to compile under any stable Nim 1.x version in the future.
Enjoyed this story? Join our Telegram group. And be part of an engaging community.