Learn 12 programming languages in 23: Nim

Samuel Teixeira
3 min readApr 4, 2023

--

3/12 new programming languages learned

Hey, you again đź‘‹. I did not post here last month!

I took some days off from work and from the internet, other than that I was sick so many days that I just could not write.

One thing that I wanted to continue was to keep learning new programming languages, and so I did.

Learning Nim was hard

This time I did not feel the same pressure as learning the previous languages and did just a minimum of 5 exercises using Nim.

Yes, learning a new programming language can be boring if you don’t like the syntax of other aspects of it.

Yes, it can be hard if you are stuck and can find help in the official documentation or other sources like Stack Overflow.

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula.

Learning with others it’s nice on Exercism

One of the big advantages of Exercism is the possibility to look into the Community Solutions tab and learn, looking into the solution of other developers.

This is my solution to the problem pangram. As you can see this is trivial.

import strutils

proc isPangram*(s: string): bool =
let allchars = "abcdefghijklmnopqrstuvwxyz"
for item in items(allchars):
if not toLower(s).contains(item):
return false
return true

A pangram is a sentence using every letter of the alphabet at least once. It is case insensitive, so it doesn’t matter if a letter is lower-case (e.g. k) or upper-case (e.g. K).

For this exercise we only use the basic letters used in the English alphabet: a to z.

If you don’t know Nim, you could say this is a good solution, but let’s compare when we use the language capabilities.

import strutils
import sequtils
proc is_pangram*(phrase: string): bool =
let filtered = phrase.toLower.toSeq.filter(isAlphaAscii)
return filtered.deduplicate.len == 26

It uses toLower as I did and introduce, toSeq, filter and duplicate.

Reading the code from this other developer made me learn three more concepts in just two lines. Even if I don’t know Nim that well I can understand what is happening and I believe you too.

Multiple ways of resolving the same problem

When I am writing this, there are 295 solutions published for the pangram using Nim.

There are many ways of solving even a simple problem like this. What will influence the different solutions are two factors:

1 — The experience of the developer in programming logic

2 — The level of knowledge of the programming language.

My code is worse because the other developer knows Nim better. This example is so simple that we can’t say the programming logic is that different.

More about Nim

To learn more about Nim visit https://nim-lang.org/

There is a playground online too https://play.nim-lang.org/#ix=2lK1

Keep learning

I am motivated to keep learning about new languages and ways to improve my code.

I will start to learn Julia. So wait for my story about it.

By sharing this I hope to inspire other developers to start learning new languages for fun and to be better developers.

proc hello*(liked: bool): string =
if liked == true:
return "Yeeeeeehaw!"
else:
return ":("

--

--

Samuel Teixeira

Developer (15+ years) | Staff Engineer at IAS | Master of Computer Science | Interests — Backend Dev , Machine Learn, Code performance, System Design