From Go to Nim

I have been using Go to build small project for a while, and I’m now looking into Nim.

Coming from Go to Nim gives certain challenges.

  • Go compiles directly to a binary. Nim compiles to c/c++ and depend on a c-compiler to compile to binary.
  • Go used { } to define blocks of code. Nim uses indention to define blocks og code, like Python.
  • In Go there are one primary terminal command go to manage packages, compile and run your project. Nim has nim for compilation and nimble for package management.
  • go.mod is in Nim called projectname.nimble.
  • go get both download a library and add this library to the local go.mod file. Using nimble install, Nimble downloades a library, but you must manually add the library to the local .nimble file to be able to use it in the project.
  • Go usually has few ways to do something and Nim seems to have many ways to do the same thing, making the code less readable:
    • parentheses can be omitted
    • method can be called with obj.method(x) or method(obj,x)

Go does not warn about modifying content in methods. If the method has a pointer receiver it works, if not, its just changes in the local copy and discarded when the method ends.