# 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)