Showing all entries tagged with: Programming

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…

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…

Is Nim a transpiler?

19th October 2021

This is a question that has come up time and time again in the IRC channel, when talking to people in person, and in the comment section pretty much every time Nim has an article on Hackernews or one of the bigger programming subreddits. It’s also a question that has been answered a lot of times, both with a short and efficient “no”, but also in longer form. This article will go into some detail…