Hide
Scraps
RSS
Showing all entries tagged with: Nim

Labelled exceptions for smoother error handling

1st November 2023

Error handling, a contentious and oft-discussed topic. Each language has some way of dealing with errors, be it error codes, result types, exceptions, something entirely different, or a mix. How to properly deal with things going wrong in our programs has been important pretty much ever since we started writing programs. Papers have been written about it, talks have been held on the topic, and countless libraries have been written to bring one languages way…


Teaching old C code new tricks with Nim

8th September 2023

Recently I was met with an interesting problem when wrapping a C library in Nim. The library in question was MAPM, an older but quite complete library for dealing with arbitrary precision maths. Unfortunately the library doesn’t have much in the way of error handling. If something goes wrong it almost always writes to stderr and returns the number 0. And to be fair, there isn’t a whole lot that can go wrong in…


Setting up a Nim server for dummies

8th June 2023

Nim is a great candidate for server development, but if you want to run your own server and are new to the world of server management or Linux there can be a daunting amount of information to consume in order to do it right. In this article I’ll give a quick rundown of setting up a small server capable of running your Nim server in a safe way. It is much more low-level than many…


Wrapping C libraries in Nim

17th April 2023

As we discovered in my last article, Nim will by default generate C code and then call on a C compiler to actually produce a binary. This might seem like an odd choice, especially in the age of LLVM. However it’s actually not uncommon for languages to compile or transpile into another language. Initially the choice to not use LLVM was simply because it wasn’t as mature back when Nim was created. Though going through…


Dynamic libraries in Nim

20th February 2023

This is a question which has been asked in various places over the years, and recently on the forum in multiple separate threads. Seeing how I’ve built commercial software with Nim dynamic libraries, I thought I’d chime in with my knowledge. But since there are multiple threads out there and this is a large-ish topic I figured it would be better to do it as a post on here.

The problem

As you’re probably aware Nim…