Hide
Scraps
RSS
Showing all entries tagged with: Programming

Tips and tricks with implicit return in Nim

1st November 2019

One feature in Nim that it shares with several other languages, especially functional ones, is implicit return of values. This is one of those small features that might just seem like a way to avoid writing return everywhere. But in fact it can be used for much more than that! So what is implicit return? In Nim we have three ways to return a value from a procedure, you have the explicit way with return,…


Metaprogramming and read- and maintainability in Nim

4th June 2019

One thing I've mentioned about metaprogramming in Nim, both in posts on this site and in talks, is that metaprogramming in Nim can enhance read- and maintainability. Opponents of metaprogramming would probably sneer at that and remark that it's quite the opposite. And sure, metaprogramming is a powerful tool, and with any sufficiently powerful tool you have to be careful. The same way a chainsaw can take your leg off if you're not careful, a…


Optional value handling in Nim

6th August 2018

I recently had a look at a functional language named Toccata which amongst other things does away with booleans. While this migth seem utterly insane it's not an entirely new concept and proponents of such ideas will warn you of the perils of boolean blindness. This refers to the fact that booleans themselves carry no information apart from their value. But as others have pointed out this is true of all values and the linked article instead refers…


Handling files in Nim

4th May 2018

In a post over on Reddit someone noted that Nim doesn't really have any article or tutorial about file reading. Trying to prove them wrong led me to a half-answer over on Rosetta Code and a forum post from 2014 asking about examples on file handling. Since this is a rather simple topic I decided to write down some of the most common ways to handle files in Nim, partially in an attempt to make the…


Nim types (originally a Reddit reply)

9th January 2018

While perusing the Nim subreddit I stumbled across a post asking for an explanation of how types work in Nim, especially how Nim allocates different types on the heap and the stack. Since the answer grew pretty long I decided to post it here as well for perpetuity. What follows is a copy of my response with some additional markdown.

First order of business heap vs. stack

Whenever you call a function it creates a stack…