News for hackers. Stuff that matters.
Re:Nimony: A New Compiler for Nim by jphoward on Tuesday November 17, 2026 @04:19AM (#50529214)
I love Nim but my only problem with it previously was support for dictionaries/objects felt really weird? There was some sort of JSON structure as I recall, but it didn't seem anywhere near as easy to use as the analogous structures in Python/JS.
Re:Nimony: A New Compiler for Nim by ZoomZoomZoom on Tuesday November 17, 2026 @04:59AM (#50529474)
I suspect you're talking about heterogenous containers which are antithetical to a strongly typed language but nevertheless are supported via std/json's JsonNode dynamic data.

In Nim regular hash maps (called tables here) have pretty regular accessors via `[]` `[]=` overloads (`foo["frob"]=42`), plus additional routines such as `.get(otherwise)`.

https://nim-lang.github.io/Nim/tables.html

Don't know why are you conflating objects in your question.

Re:Nimony: A New Compiler for Nim by jphoward on Tuesday November 17, 2026 @05:03AM (#50529507)
I'm 'conflating' them because they're called objects in javascript, so people unfamiliar with Python know what I mean. Ok thanks.
Re:Nimony: A New Compiler for Nim by setr on Tuesday November 17, 2026 @10:52AM (#50533122)
The difference isn’t between JS/Python; objects exist in many languages with various representations, JS happens to model objects using dictionaries.

So it’s really the case that JS conflates objects/dictionaries, so only people familiar with only JS would know what you mean

Re:Nimony: A New Compiler for Nim by PMunch on Tuesday November 17, 2026 @06:11AM (#50529934)
Nim is very strict about types, which is probably what you remember. Things that are typically expressed as a dictionary/object in JavaScript and Python are better represented as a fully typed tree of objects in Nim. The language of course supports the data-structure dictionary/hashmap/table (called Table in Nim) which is "anything hashable" -> "any type" lookup. This is what's used for things like `myTable["hello"] = 5` for storing the number 5 for the key "hello". However because of the strict types you can't mix which types they map to without creating some sort of wrapper type that gives you the alternatives you're allowed to use. Many people reach for Nims JsonNode type to fill this gap for small collections of string/number/array/dictionary since it already is such a wrapper type.
Re:Nimony: A New Compiler for Nim by jeremyjh on Tuesday November 17, 2026 @08:07AM (#50530853)
I wonder if this is more palatable with first-class sumtypes/ADTs in Nim 3? Or is that already what JsonNode essentially was?
Re:Nimony: A New Compiler for Nim by xigoi on Tuesday November 17, 2026 @02:40PM (#50537039)
Sum types already existed in Nim 2, but Nimony makes them more convenient to use.
Re:Nimony: A New Compiler for Nim by klibertp on Tuesday November 17, 2026 @07:57PM (#50540481)
As others wrote, what makes it unpalatable for you is static typing. You simply cannot make working with arbitrary JSON as convenient in a statically typed language as in a dynamic language (like JS or Python). No matter what you do, in a static language you need to provide or recover/generate the full type information of anything before you can use it (unless the language or the runtime system offers an escape hatch: some kind of "dynamic" type (but that means the language is now gradually typed) or strong reflection capabilities - which Nim doesn't provide to my knowledge). On the other hand, Nim has macros, so typing your JSON payloads is as painless as it can possibly be in the presence of static types.

So it's not really Nim's characteristic to make working with arbitrary JSON (heterogeneous collections more generally) "unpalatable" - it's common to (almost) all statically typed languages. While Nim looks a lot like a scripting language, it really isn't. It can be used as one, and it's much better for that than C, but it's better used for apps and systems programming than for scripting, like all the other languages in its class (ie. Go, Crystal, OCaml; Rust and Java are also close).