# Nim

Nim is a statically typed compiled systems programming language that compiles to C, C++, or JavaScript.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Announcing Ethereum Foundation and Co-Funded Grants

DevFeed: [Announcing Ethereum Foundation and Co-Funded Grants](<https://devfeed.tech/articles/announcing-ethereum-foundation-and-co-funded-grants-16857.md>)

Original publisher: [Read original article](<https://blog.ethereum.org/en/2019/08/26/announcing-ethereum-foundation-and-co-funded-grants>)

Author: Ethereum Foundation

Published: 2019-08-26T00:00:00Z

Content type: release

Language: en

Sources: [Ethereum Foundation Blog](<https://devfeed.tech/sources/ethereum-foundation-blog.md>)

Topics: [Ethereum](<https://devfeed.tech/topics/ethereum.md>), [Development](<https://devfeed.tech/topics/development.md>), [networking](<https://devfeed.tech/topics/networking.md>), [interoperability](<https://devfeed.tech/topics/interoperability.md>), [Security](<https://devfeed.tech/topics/security.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>), [browser](<https://devfeed.tech/topics/browser.md>), [Nim](<https://devfeed.tech/topics/nim.md>), [Tooling](<https://devfeed.tech/topics/tooling.md>)

Tags: [beacon](<https://devfeed.tech/tags/beacon.md>), [bounty](<https://devfeed.tech/tags/bounty.md>), [bug-fixes](<https://devfeed.tech/tags/bug-fixes.md>), [ecosystem-support-program](<https://devfeed.tech/tags/ecosystem-support-program.md>), [ethereum](<https://devfeed.tech/tags/ethereum.md>), [funding](<https://devfeed.tech/tags/funding.md>), [interoperability](<https://devfeed.tech/tags/interoperability.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [launch](<https://devfeed.tech/tags/launch.md>), [networking](<https://devfeed.tech/tags/networking.md>), [security](<https://devfeed.tech/tags/security.md>)

### AI overview

The Ethereum Foundation announces more than $2 million in Foundation-led and co-funded grants for Serenity (Eth2.0) development. Funding supports client implementations, Beacon Chain and testnet work, networking and interoperability, security research, and Lodestar JavaScript development, alongside open research and development bounties.

### Source excerpt

We are today unveiling over $2M USD in Foundation-led and co-funded grant funding aimed at furthering Serenity (Eth2.0) development as we move nearer to the launch of the Beacon Chain....

## Nim Code Coverage

DevFeed: [Nim Code Coverage](<https://devfeed.tech/articles/nim-code-coverage-30829.md>)

Original publisher: [Read original article](<https://hookrace.net/blog/nim-code-coverage/>)

Published: 2016-10-31T23:00:00Z

Content type: tutorial

Language: en

Sources: [Dennis Felsing](<https://devfeed.tech/sources/dennis-felsing.md>)

Topics: [Nim](<https://devfeed.tech/topics/nim.md>), [test-coverage](<https://devfeed.tech/topics/test-coverage.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>)

Tags: [code-coverage](<https://devfeed.tech/tags/code-coverage.md>), [command-line](<https://devfeed.tech/tags/command-line.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [nim](<https://devfeed.tech/tags/nim.md>)

### AI overview

A tutorial on generating Nim code coverage reports with gcov and lcov. It shows how to enable Nim line information and compiler coverage flags, while noting that optimization and dead-code elimination can exclude impossible code and uncovered functions from coverage results.

### Source excerpt

Creating code coverage reports with Nim is surprisingly easy. You can simply use the good old gcov and lcov tools. Nim can be told to insert its own line information with the --debugger:native command line parameter. Here's the small example program we're looking at: var x = 0 if x > 1: echo "foo" echo "bar" Note that if we change the condition to if false: the Nim compiler optimizes the impossible code away and it will not count as uncovered. The same thing can happen with entire uncovered functions when optimizations and dead code elimination are enabled. The file is saved as x.nim. Here's the script I use to create the code coverage report: #!/bin/sh rm -rf *.info html nimcache nim --debugger:native --passC:--coverage --passL:--coverage c x lcov --base-directory . --directory . --zerocounters -q ./x lcov --base-directory . --directory . -c -o x.info lcov --remove x.info "lib/*" -o x.info # remove Nim system libs from coverage genhtml -o html x.info You can look at the final html report generated.

## Writing a 2D Platform Game in Nim with SDL2

DevFeed: [Writing a 2D Platform Game in Nim with SDL2](<https://devfeed.tech/articles/writing-a-2d-platform-game-in-nim-with-sdl2-30846.md>)

Original publisher: [Read original article](<https://hookrace.net/blog/writing-a-2d-platform-game-in-nim-with-sdl2/>)

Published: 2016-06-13T22:00:00Z

Content type: tutorial

Language: en

Sources: [Dennis Felsing](<https://devfeed.tech/sources/dennis-felsing.md>)

Topics: [Nim](<https://devfeed.tech/topics/nim.md>), [Simple DirectMedia Layer](<https://devfeed.tech/topics/sdl.md>), [Game Development](<https://devfeed.tech/topics/game-development.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Graphics](<https://devfeed.tech/topics/graphics.md>), [GitHub](<https://devfeed.tech/topics/github.md>)

Tags: [game-development](<https://devfeed.tech/tags/game-development.md>), [github](<https://devfeed.tech/tags/github.md>), [graphics](<https://devfeed.tech/tags/graphics.md>), [linux](<https://devfeed.tech/tags/linux.md>), [nim](<https://devfeed.tech/tags/nim.md>), [programming](<https://devfeed.tech/tags/programming.md>), [sdl](<https://devfeed.tech/tags/sdl.md>), [tutorial](<https://devfeed.tech/tags/tutorial.md>), [windows](<https://devfeed.tech/tags/windows.md>)

### AI overview

This tutorial explains how to build a simple 2D platform game in Nim with SDL2. It covers user input, graphics, tile maps, 2D physics with collision detection, camera movement, game logic, text rendering with caching, source code organization, and cross-compiling Nim programs for Windows on Linux.

### Source excerpt

Japanese Translation In this article we're going to write a simple 2D platform game. You can also consider this as a tutorial for game development with SDL2 in Nim. We will read in user input, display graphics and a tile map, and simulate simple 2D physics with collision detection and handling. Afterwards we will implement simple camera movement and game logic. To display some information we will render texts and develop a caching mechanism for said text rendering. The final result will be a binary file that requires only SDL2 and can be easily distributed, perfect for games. If you're on Linux we will also present a simple way to cross-compile Nim programs for Windows. For the sake of simplicity we're going to use the familiar graphics from DDNet and Teeworlds, with the end result of this tutorial looking like this: We're going to follow along with the development throughout this article with illustrative images and videos, but the best way to learn is if you follow along yourself by implementing the steps from this article. The code is purposefully kept simple and easy to extend so that you can play around with it and try out all kinds of changes to get an intuitive understanding. At the end of every section there is a link to its full source code. The iterations of the code of this article and the final result are available in a repository on GitHub. The resulting binaries can be downloaded here: Win64, Win32, Linux x86_64, Linux x86 Preliminaries For this post we require: The Nim programming language and its package manager Nimble SDL 2, SDL_image 2, SDL_ttf 2 (all for developers) Nim SDL2 wrapper and strfmt, which can be installed using Nimble On a unixoid system like Linux or Mac OS X the installation looks something like this: # Debian / Ubuntu $ sudo apt-get install git libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev # Arch Linux $ pacman -S git sdl2 sdl2_image sdl2_ttf # Homebrew on OS X $ brew install git sdl2 sdl2_image sdl2_ttf # FreeBSD $ pkg install git

## Introduction to Metaprogramming in Nim

DevFeed: [Introduction to Metaprogramming in Nim](<https://devfeed.tech/articles/introduction-to-metaprogramming-in-nim-30821.md>)

Original publisher: [Read original article](<https://hookrace.net/blog/introduction-to-metaprogramming-in-nim/>)

Published: 2016-06-05T22:00:00Z

Content type: tutorial

Language: en

Sources: [Dennis Felsing](<https://devfeed.tech/sources/dennis-felsing.md>)

Topics: [Nim](<https://devfeed.tech/topics/nim.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [generics](<https://devfeed.tech/topics/generics.md>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [generics](<https://devfeed.tech/tags/generics.md>), [metaprogramming](<https://devfeed.tech/tags/metaprogramming.md>), [nim](<https://devfeed.tech/tags/nim.md>), [programming](<https://devfeed.tech/tags/programming.md>)

### AI overview

This tutorial introduces metaprogramming in Nim and explains a progression from ordinary procedures and iterators to generic procedures, closure iterators, templates, and macros. It describes how these constructs can work with or transform program code.

### Source excerpt

Introduction to the Introduction (Meta-Introduction) Wikipedia gives us a nice description of metaprogramming: Metaprogramming is the writing of computer programs with the ability to treat programs as their data. It means that a program could be designed to read, generate, analyse and/or transform other programs, and even modify itself while running. In this article we will explore Nim's metaprogramming capabilities, which are quite powerful and yet still easy to use. After all great metaprogramming is one of Nim's main features. The general rule is to use the least powerful construct that is still powerful enough to solve a problem, in this order: Normal procs and inline iterators Generic procs and closure iterators Templates Macros So before looking at Nim's two main metaprogramming constructs, templates and macros, we'll look at what we can do with procs and iterators as well. Regular Programming Constructs Normal procs We're in normal programming land here. Regular procedures are what you know as functions elsewhere and they're pretty easy to define and use: proc sayHi(name: string) = echo "Hello ", name sayHi("World") sayHi "World" "World".sayHi Generic procs With generics we can define procs that work on multiple types. Actually a new proc will be generated based on our generic definition for each instantiation: proc min[T](x, y: T): T = if x < y: x else: y echo min(2, 3) # more explicitly: min[int](2, 3) echo min("foo", "bar") # min[string]("foo", "bar") Inline iterators Inline iterators are the default iterators in Nim. They get compiled into high performance loops: iterator reverseItems(x: string): char = for i in countdown(x.high, x.low): yield x[i] for c in "foo".reverseItems: echo c So this code gets compiled into: let x = "foo" for c in countdown(x.high, x.low): let c = x[i] echo c Of course we can make iterators generic too: iterator reverseItems[T](x: T): auto = for i in countdown(x.high, x.low): yield x[i] Closure iterators Inline iterators simultane

## DDNet Server Statistics with ServerStatus, RRDtool and Nim

DevFeed: [DDNet Server Statistics with ServerStatus, RRDtool and Nim](<https://devfeed.tech/articles/ddnet-server-statistics-with-serverstatus-rrdtool-and-nim-30834.md>)

Original publisher: [Read original article](<https://hookrace.net/blog/server-statistics/>)

Published: 2016-05-13T22:00:00Z

Content type: tutorial

Language: en

Sources: [Dennis Felsing](<https://devfeed.tech/sources/dennis-felsing.md>)

Topics: [Server](<https://devfeed.tech/topics/server.md>), [Nim](<https://devfeed.tech/topics/nim.md>), [Statistics](<https://devfeed.tech/topics/statistics.md>), [Python](<https://devfeed.tech/topics/python.md>), [c/c++](<https://devfeed.tech/topics/c-c-plus-plus.md>), [JSON](<https://devfeed.tech/topics/json.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Linux](<https://devfeed.tech/topics/linux.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>)

Tags: [http](<https://devfeed.tech/tags/http.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [json](<https://devfeed.tech/tags/json.md>), [linux](<https://devfeed.tech/tags/linux.md>), [nim](<https://devfeed.tech/tags/nim.md>), [programming](<https://devfeed.tech/tags/programming.md>), [python](<https://devfeed.tech/tags/python.md>), [servers](<https://devfeed.tech/tags/servers.md>), [statistics](<https://devfeed.tech/tags/statistics.md>)

### AI overview

This article explains how DDNet monitors its official game servers using ServerStatus, RRDtool, and Nim while keeping resource usage low. It describes collecting server metrics with Python clients, transmitting them over TCP to a C/C++ server, aggregating them into JSON, displaying them through a JavaScript frontend, and recording CPU, network, and memory data in RRDtool.

### Source excerpt

About a month ago I set up statistics for the official DDNet servers. My motivations for this are: Monitor the servers more easily Get notified about server problems Have nice graphs to look at The choices for the software used are mainly made to keep resource usage low, a general principle used for DDNet since we run on cheap VPSes all around the world and are limited in CPU and memory resources. In the rest of this post we will explore the 3 major tools used, their purpose in our solution as well as their performance impact: ServerStatus: Gather live server statistics RRDtool: Record and graph data Nim: Favorite programming language for performance and readability Gathering live server statistics with ServerStatus We've been running BotoX's ServerStatus to get live server statistics for some time now. It works quite well to quickly notice major server problems like a high load or incoming (D)DoS attacks, provided that you keep an eye out for it. We use ServerStatus by running its simple Python client on each server to gather interesting information. The client transmits that data by TCP to the C/C++ server, which aggregates it into a JSON file. This JSON file is then fetched and displayed every two seconds by the JavaScript frontend of our Status page. On a regular Saturday morning the end result looks like this: On a quick glance you notice that the DDNet.tw server has high CPU usage (which is totally normal since it runs some hefty cron jobs every 20 minutes) and DDNet RUS is receiving a small DoS attack with just 1.6 MB/s (unfortunately also totally normal). Apart from that everything looks fine. ServerStatus footprint, calculated from Linux /proc statistics as follows (in Nim): import os, strutils, posix, strfmt # CPU and memory usage of process, based on PROC(5) and # http://stackoverflow.com/a/16736599 let pid = paramStr(1) # Clock ticks per second frequency = sysconf(SC_CLK_TCK) # Size of memory page in bytes pagesize = sysconf(SC_PAGESIZE) uptime = readFil

## Writing an Async Logger in Nim

DevFeed: [Writing an Async Logger in Nim](<https://devfeed.tech/articles/writing-an-async-logger-in-nim-30847.md>)

Original publisher: [Read original article](<https://hookrace.net/blog/writing-an-async-logger-in-nim/>)

Published: 2016-01-27T23:00:00Z

Content type: tutorial

Language: en

Sources: [Dennis Felsing](<https://devfeed.tech/sources/dennis-felsing.md>)

Topics: [Nim](<https://devfeed.tech/topics/nim.md>), [Logging](<https://devfeed.tech/topics/logging.md>), [async](<https://devfeed.tech/topics/async.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Code](<https://devfeed.tech/topics/code.md>), [Server](<https://devfeed.tech/topics/server.md>), [client](<https://devfeed.tech/topics/client.md>)

Tags: [async](<https://devfeed.tech/tags/async.md>), [logging](<https://devfeed.tech/tags/logging.md>), [nim](<https://devfeed.tech/tags/nim.md>), [programming](<https://devfeed.tech/tags/programming.md>), [programming-language](<https://devfeed.tech/tags/programming-language.md>), [syslog](<https://devfeed.tech/tags/syslog.md>), [terminal](<https://devfeed.tech/tags/terminal.md>)

### AI overview

A step-by-step Nim tutorial that builds an asynchronous logger for a game server and client. It discusses configurable output to files or stdout, non-blocking disk writes, performance, logging formats, compile-time caller information, and existing Nim logger implementations.

### Source excerpt

Surprisingly I'm working on HookRace again. I might share a few interesting code snippets and thoughts in this blog along the way. I'm still going with Nim as the programming language. For an easy start let's write a logging module that can be used everywhere in the game's server as well as client. There are mostly three aspects that I care about: Can be configured to write to different files and/or stdout Writes to the disk asynchronously, preventing any blocking when the disk is overloaded Reasonable performance Follow along if you want to witness how fun it is to write code in Nim! Motivation A few logger implementations for Nim already exist: logging: A simple logger in the standard library. Configurable, but no async writing omnilog: An advanced logger with lots of features, no async writing syslog: A bit too high level for my taste and no Windows support We could adapt the logging or omnilog modules to our requirements, mainly by adding async writing. For now let's write our own simple logging module from scratch instead. If it turns out to be usable after a few iterations one might merge it with an existing module. Also, this post would be rather boring if I just ended up using an existing logger. Implementation Let's start with the simplest logger possible: proc log*(text: string) = echo text log "Hello World!" We have a procedure log that is exported (*). It takes a value text of type string and prints this text to the standard output. Super simple and can be used like this from another file (or the same one): import logger log "Hello World!" This simply prints Hello World to the terminal for now when we execute it. We want to keep using the logger in this exact format. Next step: Add a fancy logging format: import strutils, times proc log*(text: string) = echo "[$# $#]: $#" % [getDateStr(), getClockStr(), text] This uses the strutils and times modules from Nim's standard library. The % operator formats the string "[$# $#]: $#" with a date, clock and our te

## Nim binary size from 160 KB to 150 Bytes

DevFeed: [Nim binary size from 160 KB to 150 Bytes](<https://devfeed.tech/articles/nim-binary-size-from-160-kb-to-150-bytes-30828.md>)

Original publisher: [Read original article](<https://hookrace.net/blog/nim-binary-size/>)

Published: 2015-05-03T22:00:00Z

Content type: tutorial

Language: en

Sources: [Dennis Felsing](<https://devfeed.tech/sources/dennis-felsing.md>)

Topics: [Nim](<https://devfeed.tech/topics/nim.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Linux](<https://devfeed.tech/topics/linux.md>)

Tags: [c](<https://devfeed.tech/tags/c.md>), [clang](<https://devfeed.tech/tags/clang.md>), [compilation](<https://devfeed.tech/tags/compilation.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [gcc](<https://devfeed.tech/tags/gcc.md>), [glibc](<https://devfeed.tech/tags/glibc.md>), [linux](<https://devfeed.tech/tags/linux.md>), [measurements](<https://devfeed.tech/tags/measurements.md>), [nim](<https://devfeed.tech/tags/nim.md>), [x86](<https://devfeed.tech/tags/x86.md>)

### AI overview

This tutorial explores how to reduce the size of a simple Nim binary on Linux. It demonstrates builds using GCC and Clang, including a 6 KB binary, a 952-byte binary without the C standard library, and a 150-byte binary using a custom linker script and ELF header.

### Source excerpt

The size of binaries in the Nim programming language seems to be a popular topic recently. Nim's slogan is expressive, efficient, elegant, so let's examine the efficient part in this post by exploring a few ways to reduce the size of a simple Nim Hello World binary on Linux. Along the way we will: Build a regular program into a 6 KB binary Disregard the C standard library and build a 952 byte binary Use a custom linker script and ELF header to build a 150 byte binary (1 byte smaller than in Rust) The full source code of this post can be found in its repository. All measurements are done on Linux x86-64 with GCC 5.1 and Clang 3.6.0. Using the C Standard Library echo "Hello!" By default Nim uses GCC as the backend C compiler on most platforms, and we dynamically link against glibc. We can try optimizing for speed and size, as well as strip unnecessary symbols after the compilation: Command (GCC backend) Binary Size nim c hello 160 KB nim -d:release c hello 61 KB nim -d:release --opt:size c hello 25 KB nim -d:release --opt:size c hello && strip -s hello 19 KB That's pretty nice and can be done with any Nim program to reduce binary size. Now let's try to get rid of glibc, at least temporarily (we will come back to a more permanent solution later). Instead of glibc we're now statically linking against musl libc: $ nim --gcc.exe:/usr/local/musl/bin/musl-gcc \ --gcc.linkerexe:/usr/local/musl/bin/musl-gcc \ -d:release --opt:size --passL:-static c hello $ strip -s hello 30 KB Update: The order of arguments to nim matters, --passL:-static has to be passed after setting the gcc exe so that it isn't overwritten. So that's a statically linked binary in 30 KB, which can be deployed without depending on any glibc version (or any other libraries)! What about using Clang instead of GCC by setting --cc:clang: Command (Clang backend) Binary Size nim --cc:clang c hello 168 KB nim --cc:clang -d:release c hello 33 KB nim --cc:clang -d:release --opt:size c hello 29 KB nim --cc:clang -d:re

## Porting a NES emulator from Go to Nim

DevFeed: [Porting a NES emulator from Go to Nim](<https://devfeed.tech/articles/porting-a-nes-emulator-from-go-to-nim-30832.md>)

Original publisher: [Read original article](<https://hookrace.net/blog/porting-nes-go-nim/>)

Published: 2015-04-30T22:00:00Z

Content type: article

Language: en

Sources: [Dennis Felsing](<https://devfeed.tech/sources/dennis-felsing.md>)

Topics: [Emulator](<https://devfeed.tech/topics/emulator.md>), [Nim](<https://devfeed.tech/topics/nim.md>), [Go Language](<https://devfeed.tech/topics/go-language.md>), [Programming language](<https://devfeed.tech/topics/programming-language.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>)

Tags: [c](<https://devfeed.tech/tags/c.md>), [emulator](<https://devfeed.tech/tags/emulator.md>), [go](<https://devfeed.tech/tags/go.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [nim](<https://devfeed.tech/tags/nim.md>), [porting](<https://devfeed.tech/tags/porting.md>), [programming](<https://devfeed.tech/tags/programming.md>), [programming-language](<https://devfeed.tech/tags/programming-language.md>)

### AI overview

The article describes porting a NES emulator from Go to Nim, using SDL2 as the backend and comparing compilation, binary size, source size, CPU usage, and memory usage. It also explains compiling the Nim-generated C code to JavaScript with Emscripten.

### Source excerpt

Let me get this straight. We have an emulator for 1985 hardware that was written in a pretty new language (Go), ported to a language that isn't even 1.0 (Nim), compiled to C, then compiled to JavaScript? And the damn thing actually works? That's kind of amazing. -- Summary by haberman I spent the last weeks working on NimES, a NES emulator in the Nim programming language. As I really liked fogleman's NES emulator in Go I ended up mostly porting it to Nim. The source code is so clean that it's often easier to understand the internals of the NES by reading the source code than by reading documentation about it. The choice of backend fell on SDL2 for me, contrary to GLFW + PortAudio that the Go version used. This was mainly motivated by the great portability promised by SDL2. Later we will see how porting to JavaScript and Android worked. If you're impatient and want to play a game, there's a JS demo. Comparison of Go and Nim Most Go concepts are quite trivial to translate to Nim. This made the porting process simple. Let's compare some data that I found interesting: Metric Go Nim (clang backend) Compile command go build nimble build Fresh compile time 2.1 s¹ 1.7 s Recompile time 1.5 s 0.5 s Binary size 16 MB (static) 136 KB + 1MB SDL2 Source code size² 3260 lines, 74 KB 2145 lines, 60 KB CPU usage 71 % 53 % Memory usage 79 MB 73 MB ¹ Excluding go-glfw, go-gl and portaudio, which take 17 s to compile ² Emulation code only It's nice to see Nim doing well. Even the compile time is shorter than that of Go, which is well known for its short compile times. Now that the port seems to be doing fine and should be running on all Desktop platforms, let's look into some other interesting things we can do with Nim: JavaScript port via emscripten Nim has a JavaScript backend, but I don't trust it to be stable enough for this task yet. So I opted for emscripten instead, which can compile C code into JavaScript. Since Nim outputs C code, this sounds like a perfect fit. Luckily eeeee h

## NimES: a NES emulator in Nim

DevFeed: [NimES: a NES emulator in Nim](<https://devfeed.tech/articles/nimes-a-nes-emulator-in-nim-30830.md>)

Original publisher: [Read original article](<https://hookrace.net/blog/nimes/>)

Published: 2015-04-29T22:00:00Z

Content type: release

Language: en

Sources: [Dennis Felsing](<https://devfeed.tech/sources/dennis-felsing.md>)

Topics: [Emulator](<https://devfeed.tech/topics/emulator.md>), [Nim](<https://devfeed.tech/topics/nim.md>), [Programming](<https://devfeed.tech/topics/programming.md>)

Tags: [demo](<https://devfeed.tech/tags/demo.md>), [emulator](<https://devfeed.tech/tags/emulator.md>), [github](<https://devfeed.tech/tags/github.md>), [nim](<https://devfeed.tech/tags/nim.md>), [programming](<https://devfeed.tech/tags/programming.md>)

### AI overview

NimES is a NES emulator written in Nim, announced alongside the release of Nim 0.11. The article points readers to its GitHub repository and JavaScript demo.

### Source excerpt

Since today Nim 0.11 has been released, I guess it's a good time to release this as well: NimES is a NES emulator written in Nim. More info in the GitHub repository and the JS demo. Discussion on Hacker News and Reddit.

## Make a Lisp in Nim

DevFeed: [Make a Lisp in Nim](<https://devfeed.tech/articles/make-a-lisp-in-nim-30824.md>)

Original publisher: [Read original article](<https://hookrace.net/blog/make-a-lisp-in-nim/>)

Published: 2015-03-03T23:00:00Z

Content type: tutorial

Language: en

Sources: [Dennis Felsing](<https://devfeed.tech/sources/dennis-felsing.md>)

Topics: [Nim](<https://devfeed.tech/topics/nim.md>), [Lisp](<https://devfeed.tech/topics/lisp.md>), [Code](<https://devfeed.tech/topics/code.md>), [Benchmark](<https://devfeed.tech/topics/benchmark.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [make](<https://devfeed.tech/topics/make.md>)

Tags: [benchmark](<https://devfeed.tech/tags/benchmark.md>), [benchmarks](<https://devfeed.tech/tags/benchmarks.md>), [build](<https://devfeed.tech/tags/build.md>), [code](<https://devfeed.tech/tags/code.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [lisp](<https://devfeed.tech/tags/lisp.md>), [nim](<https://devfeed.tech/tags/nim.md>), [programming](<https://devfeed.tech/tags/programming.md>), [writing](<https://devfeed.tech/tags/writing.md>)

### AI overview

The article describes implementing a Lisp interpreter in Nim by following the Make a Lisp guide. It explains how to build, run, and test the implementation, and reports rough benchmark results comparing Nim with several other languages. The author notes that the measurements are not optimized or definitive.

### Source excerpt

I spent the last weekend working through the amazing guide for Make a Lisp, writing a Lisp interpreter in Nim. The final result just made it into the repository. Running the Nim version is pretty simple. You need the Nim compiler from the devel branch and nre which can be installed through nimble. After installing those you can build and run the MAL interpreter: $ cd nim $ make # OR $ nimble build $ ./stepA_mal Mal [nim] user> 12 12 user> (+ 2 3) 5 Running the tests: $ cd .. $ make "test^nim^step1" # A single test $ make "test^nim" # All tests $ make "perf^nim" # All benchmarks There is a nice presentation in MAL about MAL you can read: $ cd nim $ ./stepA_mal ../examples/clojurewest2014.mal And you can run MAL implented in MAL itself using the Nim interpreter: $ ./stepA_mal ../mal/stepA_mal.mal Mal [nim-mal] mal-user> The benchmark results from Joel Martin, the author of MAL, don't look bad for Nim. Edit: Note that these are just rough measurements to see that the Nim implementation is doing fine. Don't judge the other languages for their numbers, which may not have ideal implementations performance-wise. In the short benchmarks Nim is the fastest, in the long benchmark only the JVM can beat it. I didn't really try to optimize and oriented mostly on the Python implementation, which is quite a lot slower as you can see. So it's pretty nice to see idiomatic Nim performing well: perf1 perf2 perf3 macros math macros ms ms iters/sec java 6 24 17969 scala 47 87 15963 nim 1 1 11121 ocaml 1 3 7063 cs 10 11 5414 vb 12 13 4523 rust 2 5 4084 c 1 4 3649 go 1 6 3048 racket 3 10 2461 coffee 5 11 2326 js 6 14 1726 ruby 4 15 1255 haskell 4 14 1163 clojure 11 23 1174 forth 9 29 563 php 13 51 331 python 14 51 304 bash 1673 9000 276 perl 18 69 215 ps 41 332 48 R 116 490 28 miniMAL 779 3448 4 matlab 1688 5844 2 make 3427 28453 0 I also didn't really aim for a low amount of code but rather good readability, but it may still be interesting to look at. I guess Nim's size being so close to

## Conclusion on Nim

DevFeed: [Conclusion on Nim](<https://devfeed.tech/articles/conclusion-on-nim-30807.md>)

Original publisher: [Read original article](<https://hookrace.net/blog/conclusion-on-nim/>)

Published: 2015-01-25T23:00:00Z

Content type: article

Language: en

Sources: [Dennis Felsing](<https://devfeed.tech/sources/dennis-felsing.md>)

Topics: [Nim](<https://devfeed.tech/topics/nim.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Haskell](<https://devfeed.tech/topics/haskell.md>), [Python](<https://devfeed.tech/topics/python.md>), [Rust](<https://devfeed.tech/topics/rust.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [conclusion](<https://devfeed.tech/tags/conclusion.md>), [haskell](<https://devfeed.tech/tags/haskell.md>), [language](<https://devfeed.tech/tags/language.md>), [nim](<https://devfeed.tech/tags/nim.md>), [programming](<https://devfeed.tech/tags/programming.md>), [python](<https://devfeed.tech/tags/python.md>), [rust](<https://devfeed.tech/tags/rust.md>)

### AI overview

The author concludes that Nim is the most efficient language for them because it balances code efficiency, readability, and development time. They acknowledge that Nim is not the fastest or easiest language and lacks a single defining feature, but say it compares favorably with Rust, C++, Python, and Haskell in their personal use.

### Source excerpt

In my last two posts, "What is special about Nim?" and "What makes Nim practical", I forgot the important conclusion - why I personally have decided for Nim in favor of Rust, C++, Python and Haskell: Nim is not the fastest language, it's not the easiest language to write in and it surely has some flaws that should be fixed. Nim has no single "killer feature" like go's goroutines or Rust's memory management. But Nim doesn't need a killer feature. Instead it strikes a reasonable balance that makes it the most efficient language for me: I can produce reasonably efficient code (faster than Python and Haskell) that is reasonably readable (more so than Rust, C++ and Haskell) in a reasonable amount of time (less than Rust, C++ and Haskell)

## What makes Nim practical?

DevFeed: [What makes Nim practical?](<https://devfeed.tech/articles/what-makes-nim-practical-30844.md>)

Original publisher: [Read original article](<https://hookrace.net/blog/what-makes-nim-practical/>)

Published: 2015-01-22T23:00:00Z

Content type: tutorial

Language: en

Sources: [Dennis Felsing](<https://devfeed.tech/sources/dennis-felsing.md>)

Topics: [Nim](<https://devfeed.tech/topics/nim.md>), [Programming language](<https://devfeed.tech/topics/programming-language.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Library](<https://devfeed.tech/topics/library.md>), [Package manager](<https://devfeed.tech/topics/package-manager.md>), [C](<https://devfeed.tech/topics/c.md>)

Tags: [c](<https://devfeed.tech/tags/c.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [gcc](<https://devfeed.tech/tags/gcc.md>), [install](<https://devfeed.tech/tags/install.md>), [libraries](<https://devfeed.tech/tags/libraries.md>), [nim](<https://devfeed.tech/tags/nim.md>), [programming-language](<https://devfeed.tech/tags/programming-language.md>)

### AI overview

This article explains why Nim is practical for distributing programs. It covers statically linking the Nim runtime and libraries into binaries, using nimble for dependencies, compiling with Clang or GCC, creating source distributions for different operating systems and CPU architectures, and distinguishing debug and release builds.

### Source excerpt

In my last post I showed what makes the Nim programming language special. Today, let's consider Nim from another angle: What makes Nim a practical programming language? Binary Distribution Programs written in interpreted languages like Python are difficult to distribute. Either you require Python (in a specific version even) to be installed already, or you ship it with your program. This even causes some to reconsider Python as a teaching language. How does Nim work around this problem? For starters your program gets statically linked against the Nim runtime. That means you end up with a single binary that depends solely on the standard C library, which we can take for granted on any operating system we're interested in. Let's write a small program and give this a try: echo "Hello World" If you want to follow along, get the Nim compiler. Save this code as hello.nim. Let's compile it now so that we can distribute the hello binary: $ nim -d:release c hello CC: hello CC: stdlib_system [Linking] $ ./hello Hello World $ ls -lha hello -rwxr-xr-x 1 def def 57K Jan 22 09:37 hello* $ ldd hello linux-vdso.so.1 (0x00007fffd5973000) libdl.so.2 => /lib64/libdl.so.2 (0x00007f0f92c6b000) libc.so.6 => /lib64/libc.so.6 (0x00007f0f928c3000) /lib64/ld-linux-x86-64.so.2 (0x00007f0f92e6f000) Now our little program starts growing and we get interested in using a few Nim libraries. Do we have to add compiled versions of these libraries to our distributions now? Do not fret! Nim libraries are statically compiled into our binary as well. Let's get a library using Nim's package manager, nimble: $ nimble install strfmt Installing strfmt-0.5.4 strfmt installed successfully. And use the library in our, admittedly not very useful, program: import strfmt echo "Hello {} number {:04.1f}".fmt("World", 6.0) If we want to compile with Clang instead of GCC as the backend, that's easy as well and Clang is usually much faster to compile and yields a smaller binary: $ nim --cc:clang -d:release c hello $ .

## What is special about Nim?

DevFeed: [What is special about Nim?](<https://devfeed.tech/articles/what-is-special-about-nim-30843.md>)

Original publisher: [Read original article](<https://hookrace.net/blog/what-is-special-about-nim/>)

Published: 2014-12-31T23:00:00Z

Content type: tutorial

Language: en

Sources: [Dennis Felsing](<https://devfeed.tech/sources/dennis-felsing.md>)

Topics: [Nim](<https://devfeed.tech/topics/nim.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Programming language](<https://devfeed.tech/topics/programming-language.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Tutorial](<https://devfeed.tech/topics/tutorial.md>)

Tags: [arrays](<https://devfeed.tech/tags/arrays.md>), [build](<https://devfeed.tech/tags/build.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [import](<https://devfeed.tech/tags/import.md>), [metaprogramming](<https://devfeed.tech/tags/metaprogramming.md>), [nim](<https://devfeed.tech/tags/nim.md>), [programming](<https://devfeed.tech/tags/programming.md>), [programming-language](<https://devfeed.tech/tags/programming-language.md>), [run](<https://devfeed.tech/tags/run.md>), [sequences](<https://devfeed.tech/tags/sequences.md>), [syntax](<https://devfeed.tech/tags/syntax.md>), [tutorial](<https://devfeed.tech/tags/tutorial.md>), [xor](<https://devfeed.tech/tags/xor.md>)

### AI overview

An introductory article that demonstrates Nim through runnable examples, compile-time execution, CRC32 table generation, templates, macros, and language extension techniques.

### Source excerpt

Russian Translation by frol, Chinese Translation by JiyinYiyong, Japanese Translation by Mutsuha Asada The Nim programming language is exciting. While the official tutorial is great, it slowly introduces you to the language. Instead I want to quickly show what you can do with Nim that would be more difficult or impossible in other languages. I discovered Nim in my quest to find the right tools to write a game, HookRace, the successor of my current DDNet game/mod of Teeworlds. Since I'm busy with other projects for now, this blog is now officially about Nim instead, until I find time to continue developing the game. Easy to get running Ok, this part is not exciting yet, but I invite you to follow along with the post: for i in 0..10: echo "Hello World"[0..i] If you want to do so, get the Nim compiler. Save this code as hello.nim, compile it with nim c hello and finally run the binary with ./hello. To immediately compile and run, use nim -r c hello. To use an optimized release build instead of a debug build use nim -d:release c hello. With all of these settings you will see the following output: H He Hel Hell Hello Hello Hello W Hello Wo Hello Wor Hello Worl Hello World Run regular code at compile time To implement an efficient CRC32 procedure you need a lookup table. You could compute it at runtime or write it into your code as a magic array. Clearly we don't want any magic numbers in our code, so we'll do it at runtime (for now): import unsigned, strutils type CRC32* = uint32 const initCRC32* = CRC32(-1) proc createCRCTable(): array[256, CRC32] = for i in 0..255: var rem = CRC32(i) for j in 0..7: if (rem and 1) > 0: rem = (rem shr 1) xor CRC32(0xedb88320) else: rem = rem shr 1 result[i] = rem # Table created at runtime var crc32table = createCRCTable() proc crc32(s): CRC32 = result = initCRC32 for c in s: result = (result shr 8) xor crc32table[(result and 0xff) xor ord(c)] result = not result # String conversion proc $, automatically called by echo proc `$`(c: CRC32)

## Exploring Nim through Rosetta Code and HookRace

DevFeed: [Exploring Nim through Rosetta Code and HookRace](<https://devfeed.tech/articles/nim-adventures-30827.md>)

Original publisher: [Read original article](<https://hookrace.net/blog/nim-adventures/>)

Published: 2014-07-12T22:00:00Z

Content type: tutorial

Language: en

Sources: [Dennis Felsing](<https://devfeed.tech/sources/dennis-felsing.md>)

Topics: [Nim](<https://devfeed.tech/topics/nim.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Algorithms](<https://devfeed.tech/topics/algorithms.md>), [Code](<https://devfeed.tech/topics/code.md>), [HTTP](<https://devfeed.tech/topics/http.md>), [JSON](<https://devfeed.tech/topics/json.md>), [Parser](<https://devfeed.tech/topics/parser.md>)

Tags: [algorithms](<https://devfeed.tech/tags/algorithms.md>), [github](<https://devfeed.tech/tags/github.md>), [http](<https://devfeed.tech/tags/http.md>), [json](<https://devfeed.tech/tags/json.md>), [nim](<https://devfeed.tech/tags/nim.md>), [programming](<https://devfeed.tech/tags/programming.md>), [python](<https://devfeed.tech/tags/python.md>), [rosetta](<https://devfeed.tech/tags/rosetta.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>)

### AI overview

The author describes learning Nim through a talk and Rosetta Code exercises, comparing its code with Python and finding similar ease of problem-solving with higher performance. The article also highlights Nim's standard library and its use in ranking programming languages on Rosetta Code.

### Source excerpt

To learn some Nim I held a talk about it at the GPN14 (in German, Slides). Afterwards I started solving Rosetta Code tasks in Nim to get a better feel for the language and standard library. That also made me discover some rough edges in the language, but luckily the community, albeit small, is active and competent. All the small code pieces I wrote are now on Github too. What I noticed is that most problems are as easy to solve as in Python, but much more performant. I'm now more confident that this language is the right choice for writing HookRace in. Some highlights: Insertion Sort Once in Python: def insertion_sort(l): for i in xrange(1, len(l)): j = i-1 key = l[i] while (l[j] > key) and (j >= 0): l[j+1] = l[j] j -= 1 l[j+1] = key and in Nim: proc insertSort[T](a: var openarray[T]) = for i in 1 .. <a.len: let value = a[i] var j = i while j > 0 and value < a[j-1]: a[j] = a[j-1] dec j a[j] = value Rank languages by popularity The standard library is extremely useful, providing an HTTP client, JSON parser, regular expressions, string utils and algorithms, which I use to create a ranking of the popularity of languages on Rosetta Code: import httpclient, json, re, strutils, algorithm, future const langSite = "http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Languages&cmlimit=500&format=json" catSize = "http://www.rosettacode.org/w/index.php?title=Special:Categories&limit=5000" let regex = re"title=""Category:(.*?)"">.+?</a>.*\((.*) members\)" var langs = newSeq[string]() for l in parseJson(getContent(langSite))["query"]["categorymembers"]: langs.add(l["title"].str.split("Category:")[1]) var ranks = newSeq[tuple[lang: string, count: int]]() for line in getContent(catSize).findAll(regex): let lang = line.replacef(regex, "$1") if lang in langs: let count = parseInt(line.replacef(regex, "$2").strip()) ranks.add((lang, count)) ranks.sort((x, y) => cmp[int](y.count, x.count)) for i, l in ranks: echo align($(i+1), 3), align(

## What is HookRace?

DevFeed: [What is HookRace?](<https://devfeed.tech/articles/what-is-hookrace-30842.md>)

Original publisher: [Read original article](<https://hookrace.net/blog/what-is-hookrace/>)

Published: 2014-07-06T22:00:00Z

Content type: article

Language: en

Sources: [Dennis Felsing](<https://devfeed.tech/sources/dennis-felsing.md>)

Topics: [Nim](<https://devfeed.tech/topics/nim.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [SVG](<https://devfeed.tech/topics/svg.md>), [Graphics](<https://devfeed.tech/topics/graphics.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [graphics](<https://devfeed.tech/tags/graphics.md>), [linux](<https://devfeed.tech/tags/linux.md>), [nim](<https://devfeed.tech/tags/nim.md>), [programming](<https://devfeed.tech/tags/programming.md>), [programming-language](<https://devfeed.tech/tags/programming-language.md>), [svg](<https://devfeed.tech/tags/svg.md>), [windows](<https://devfeed.tech/tags/windows.md>)

### AI overview

The article introduces HookRace, a planned standalone successor to DDraceNetwork rather than a Teeworlds-based modification. It outlines planned SVG graphics, client-and-server physics, support for high player counts, and anti-faking accounts, and explains why the author chose Nim for development.

### Source excerpt

I have been running DDraceNetwork for 1 year, which started out as a little server of a Teeworlds modification called DDRace. It has turned into the biggest project within Teeworlds, offering servers in 6 countries with thousands of players and dozens of mappers. We also offer a custom server and client (Windows, Linux, OS X, Android). Now it's time to start something new. I'm working on a new game called HookRace, which will be the successor to DDraceNetwork. It will be its own game, not based on Teeworlds. Some of the plans I have so far for HookRace: Vector Graphics (SVG) ingame for a sharp image on any screen Whole physics is executed at the client as well as the server, for perfect prediction No lags with high player numbers Accounts to prevent faking As the programming language for HookRace, I chose Nim: # Game of Life in terminal import os, strutils, math randomize() var w, h: int if paramCount() >= 2: w = parseInt paramStr 1 h = parseInt paramStr 2 if w <= 0: w = 30 if h <= 0: h = 30 # Iterate over fields in the universe iterator fields(a = (0,0), b = (h-1,w-1)) = for y in a[0]..b[0]: for x in a[1]..b[1]: yield (y,x) # Create a sequence with an initializer proc newSeqWith[T](len: int, init: T): seq[T] = result = newSeq[T] len for i in 0 .. <len: result[i] = init # Initialize var univ, univNew = newSeqWith(h, newSeq[bool] w) for y,x in fields(): if random(10) < 1: univ[y][x] = true while true: # Show stdout.write "\e[H" for y,x in fields(): stdout.write if univ[y][x]: "\e[07m \e[m" else: " " if x == 0: stdout.write "\e[E" stdout.flushFile # Evolve for y,x in fields(): var n = 0 for y1,x1 in fields((y-1,x-1), (y+1,x+1)): if univ[(y1+h) mod h][(x1 + w) mod w]: inc n if univ[y][x]: dec n univNew[y][x] = n == 3 or (n == 2 and univ[y][x]) swap univ, univNew sleep 200 Nim is a rather new language, and it took me some time to choose it. What I love about the language: Python-like syntax Statically typed, compiled High performance (same ballpark as C/C++) Garbage Col