DEV Community

Cover image for Ode to Nimpy
Juan Carlos
Juan Carlos

Posted on

Ode to Nimpy

Alt Text

The Nim experience

So far...

When PIP3 got broken on Arch Linux,
lots of Python modules got broken,
my Nim Nimpy Python modules continue working.

When Python3 become default on most Linux,
lots of Python modules got broken,
my Nimpy Python modules continue working.

When "ABI3" of Python3 launched,
some Python modules got broken,
my Nimpy Python modules continue working.

When Python3.8 become default on Linux,
lots of Python modules got broken,
my Nimpy Python modules continue working.

Alt Text

"Deprecation Warning" for a year on Nimpy,
my Nimpy Python modules continue working.

"Experimental" features for a year on Nimpy,
my Nimpy Python modules continue working.

If Nimble get broken someday, just use Git or Curl,
Install packages is copy&paste a file.

My Nimpy Python modules are faster than PyPy,
the most super-optimized Python3.8 code is several orders of magnitude slower than the crappiest unoptimized equivalent on Nim.

Most times I use a lot less lines of code than CPython, without code-golf,
it is not only about more performance but also it uses less code.

C interop is a lot better than CTypes, JavaScript too,
you can interoperate with anything that has C/C++ or JS API.

I write a lot less Type Annotations thanks to Type Inference,
but yet Types are strongly enforced,
variables are not None out of thin air, integers are not float out of thin air.

Deploy

Deploy anywhere where you can compile C:

Alt Text

  • scp the binary to the server & run!, forget installers and prepared environments, those are kludges of the past.

You can learn today

Hello World:

echo "Hello World"
Enter fullscreen mode Exit fullscreen mode

For Python:

import nimpy

proc hello() {.exportpy.} =
  echo "Hello World"
Enter fullscreen mode Exit fullscreen mode
  • {.exportpy.} is a Pragma to export to Python, is like a Decorator.
  • proc is like def of Python, it also has func for Pure-Functional.
  • You can use Python Syntax, but for this example I go with std lib.

On Python:

from module import hello
hello()
Enter fullscreen mode Exit fullscreen mode

Install, Tutorial, Documentation, Manual, Docker, Chat, Try Nim on the browser, Nim for Python devs, Standard Library, Python integration, Python Syntax, Python/Nim Cheatsheet.

Advanced Nimpy Example:

Alt Text

Welcome to the Nim

50 years on the past you can compile C,
100 years on the future you can compile C.
Dennis Ritchie was right.
👑🥰👍

Top comments (1)

Collapse
 
nlhnt profile image
Marcin Borawski

Sad to see the small adoption.
The compilation to C is a great and undervalued feature.
Python has that as well with Cython, but it requires some mental overhead and extra steps to be used... there are some great books about it though :)
Great thing is you don't have to forget about Python, you can just use nim if you think the usecase is the right choice.
Can't force people in organisation to drop Python or anything else in favor of Nim, that's unreasonable, but for your personal projects or Python extension modules this is a great option - doesn't require a recompilation with a Python version change (Cython reqires that).

Great step towards the future.