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