this post was submitted on 31 Aug 2025
76 points (97.5% liked)

Programming

22516 readers
143 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 2 years ago
MODERATORS
 

I've been researching programming languages to find a good, high level language that compiles to a single binary that is preferably pretty small. After tons of research, I landed on Nim and used it to make a quick txt parser for a project I'm doing.

Nim seems absolutely fantastic. Despite being sold as a systems programming language, it feels like Python without any of its drawbacks (it's fast, statically typed, etc.) - and the text parser I made is only a 50kb binary!

Has anyone here tried Nim? What's your experience with it? Are there any hidden downsides aside from being kinda unpopular?


Bonus: I want to give a shoutout to how easy it is to open a text file and parse it line-by-line in this language. Look at how simple and elegant this syntax is:

import os

if paramCount() == 0:
  quit("No file given as argument", 1)

let filepath = paramStr(1)

if not fileExists(filepath):
  quit("File not found: " & filepath, 1)

for line in lines(filepath):
  echo line
you are viewing a single comment's thread
view the rest of the comments
[โ€“] Ephera@lemmy.ml 9 points 5 days ago (1 children)

I don't have proper experience with it, I just built a small prototype with it back in 2021, to evaluate it for a project. But yeah, apparently these were my notes:

Nim: Significant whitespace [derogatory], no interfaces/traits, imports throw random functions into scope like in Python (plays a big role with supposed object-orientation, as methods don't get imported along with a type; they're loosely attached and just imported along), somewhat ugly syntax

Apparently, past-me wasn't as big on the syntax. ๐Ÿ˜…

But I can see why, because this is the code I wrote back then, apparently (I wanted to create a OS configuration framework ร  la Puppet, Ansible etc.):

main.nim:

import strformat
import role, host

let host2 = Role(
  description: "sdadsj",
  code: proc (host: Host) = echo "sakjd"
)

echo host2


type Role2 = ref object of RootObj
  description: string
method deploy(self: Role2) {.base.} = discard


type KWriteConfig5 = ref object of Role2
  cheese: string
method deploy(self: KWriteConfig5) = echo fmt"Deploying: {self.cheese}"


let test = KWriteConfig5(
  description: "Deploy KWriteConfig5.",
  cheese: "cake"
)

test.deploy()


let rolerole = Role2(
  description: "RoleRole",
)

rolerole.deploy()

host.nim:

type Host* = object

role.nim:

import host

type Role* = ref object of RootObj
  description*: string
method deploy(self: Role) {.base.} = discard

Certainly some syntax elements in there where I have not even the faintest guess anymore what they would do...

[โ€“] atzanteol@sh.itjust.works 5 points 5 days ago (1 children)

Apparently, past-me wasn't as big on the syntax. ๐Ÿ˜…

You were right. Using whitespace for code blocks is literally the worst option.

[โ€“] FizzyOrange@programming.dev 8 points 5 days ago (2 children)

I dunno I would say Lisp syntax is probably the worst option. Or APL style.

[โ€“] bitcrafter@programming.dev 4 points 5 days ago (1 children)

Lisp syntax would not even necessarily be that bad if in practice people did not lump all of the closing parentheses in a place where it is really hard to visually match them with their respective opening parentheses so that it is hard to immediately see what is going on. (I have been told that the trick is to read the whitespace instead of the parentheses, but that does not actually help because the whitespace is not significant in Lisp!)

[โ€“] FizzyOrange@programming.dev 2 points 5 days ago (1 children)

Yeah I agree. Presumably they don't do that though because you'd end up with pages of nothing but ).

I never understood why they don't add just a little syntactic sugar. You don't need much to take it from a mess of brackets to something comprehensible.

[โ€“] anton@lemmy.blahaj.zone 2 points 4 days ago

I never understood why they don't add just a little syntactic sugar. You don't need much to take it from a mess of brackets to something comprehensible.

It was in the original design, but not the first implementation. By the time someone got around to it, people where used to S-expressions.

[โ€“] atzanteol@sh.itjust.works 0 points 5 days ago

You make a strong argument! ๐Ÿ˜†