Things I Like About Nim

Method Call Syntax

In Nim, a.f(b) is really just syntactic sugar for f(a, b). Note: they look like methods but aren’t attached to the type/object at all. Which function to call will be figured out at compile time, just like normal function calls.

You can use this to implement pseudo extension methods on standard types like strings:

import
  nim_utils/files,
  os,
  strformat

proc makeBackup(filename: string) =
  let backupPath = fmt"{filename}.bak"
  case filename.fileType
  of ftFile, ftSymlink:
    copyFile(filename, backupPath)
  of ftDir:
    copyDir(filename, backupPath)
  else:
    raise newException(IOError, fmt"Cannot make backup of {filename}")


for f in @["fstab", "systemd"]:
    fmt"/etc/{f}".makeBackup() # Same as makeBackup(fmt"/etc/{f}")

You can also use this to chain calls together nicely:

[Read More]

When to Use Programming Languages

Java

  • Willing to take a small speed decrease in order to have a much better time programming than C/C++
  • Need to interface with <Obscure Technology>. Because Java probably has a library for it

Kotlin

  • Want/need to use Java libraries but want to feel modern

Groovy

  • I want to write a version of Java that gets rid of everything good about Java while keeping all of the bad

C

  • Need the maximum amount of speed possible

C++

  • Need the maximum amount of speed possible while also having the maximum number of language features that don’t fit together

Javascript

  • Need to write something quick for the browser

Typescript

  • Need to write something large for the browser

Python

  • Short scripts, one-offs
  • Want to have a good time programming while not caring about speed or ease of refactoring

Go

  • Want the power of concurrency, but don’t want to actually learn concurrency

Clojure

  • Want/need to use Java libraries but are a hipster
  • Rich Hickey is my spirit animal
  • Seriously though, Clojure is really good for processing data. It has a lot of functions in the standard library for manipulating lists and maps. It’s my tool of choice when working with large JSON files.

Rust

  • I’m a sub and I want my compiler to be the dom

Haskell

  • Want to prove that all those years of mathematics were useful
  • Want to feel superior to the plebs that can’t understand your beautiful monads

OCaml

  • Want to use a high-level language but am intimidated by Haskell
  • Want a functional language with the opportunity to use imperative programming without having to wrap all values in a ThisIsImpureDontLetItContaminateThePurity monad

PHP

  • No
  • Just no