Live data from Hacker News

Nim 2.0

nim-lang.org

121–130 of 213 posts

Re: Nim 2.0

#121
As someone who doesn't know much about Nim:

    Improved type inference
    ...
    let foo: seq[(float, byte, cstring)] = @[(1, 2, "abc")]
This looks like a normal type declaration to me, why is there any inference involved?

Re: Nim 2.0

#122

Earlier quoted context omitted.

There's no unwrapping any pointers or boxes or what-not That doesn't happen by default in C++ either. std::vector some_seq{1, 2, 3, 4, 5, 7};

or even just std::vector some_seq{1, 2, 3, 4, 5, 7}; nowadays (for a value of nowadays that is 5 years old for GCC and 6 years old for Clang)

Indeed there's no question that Nim is basically following C++'s lead on this. Nim iirc always had constructors and destructors. Final piece of the puzzle is move semantics, and I recall a blog post where Araq came up with something very similar.

Re: Nim 2.0

#123
post #88

Earlier quoted context omitted.

Also Nim requires you to use unique field names across all variants.

This annoying restriction is lifted in Nim 2; see the linked announcement.

Where in the announcement does it say that?

Re: Nim 2.0

#124

Been happily crunching away at Nim in production. I'm working on what is mainly a data analysis and report generation tool, compiled as a CLI executable that gets called by server scripts. Nim makes fast, small executables. It has an excellent heterogenous JSON data structure and a good dataframe library. It prefers the stack so strongly that dynamic data structures (sequences and tables, basically its lists and dict…

You have convinced me to look in to Nim! Can you speak to the build system(s)? CMake is the bane of my existence.

Ugh, I just got done spending months fighting CMake before moving back to a position using Nim!

You can also compile C projects with Nim like bearssl [1]. Nim takes care to compile the C files and recompile them when config flags change. It's actually really nice.

1: https://github.com/status-im/nim-bearssl/blob/99fcb3405c55b2...

Re: Nim 2.0

#125
post #119

Earlier quoted context omitted.

For Rust at least one can use https://github.com/arnetheduck/nbindgen

that looks interesting, thanks! Did you try it if it delivers on promises? There was not any new commit since 2020 so not sure if the project is stale by now.

I do not use Rust, so sadly I have not.

Re: Nim 2.0

#126

As someone who doesn't know much about Nim: Improved type inference ... let foo: seq[(float, byte, cstring)] = @[(1, 2, "abc")] This looks like a normal type declaration to me, why is there any inference involved?

It looks simple but in a typed language it's actually somewhat tricky. The compiler needs to infer that the 1 is a float type, 2 is a byte, and compile it appropriately.

Previously Nim didn't do any "reverse" type inference so you'd need to say `@[1'f64, 2'byte, "abc")]`. That was because it's a constraints problem that can become exponentially expensive to solve. Exploding compile times in Rust and Swift are good examples of this. But there's limited subsets which can still be quick and are helpful like this case.

Re: Nim 2.0

#127
post #96

It seems almost too good to be true. Well done! Could someone share some bad experiences when adopting Nim so I can weight that in? I'm seriously considering it.

I have a shortlist of pain points: - Tooling is not great. The language server has a tendency to silently crash on occasion, and it's no rust-analyzer to begin with. A tooling rewrite has been delayed behind proper incremental compilation, which has been delayed behind ARC/ORC... - Interfaces ("concepts") are experimental and there are two differing implementations. - It lacks proper sum types and structural pattern…

> It lacks proper sum types

We've talked about this before! You know it has sum types, just not the variation you want.

Re: Nim 2.0

#128
post #123

Earlier quoted context omitted.

This annoying restriction is lifted in Nim 2; see the linked announcement.

Where in the announcement does it say that?

They likely read "overloadable enums" and went "Oh Rust calls their tagged unions enums" so assumed all languages did.

Re: Nim 2.0

#129
post #57

Looking forward to trying out this release! After programming professionally for 25 years, IMO Nim really is the best of all worlds. Easy to write like Python, strongly typed but with great inference, and defaults that make it fast and safe. Great for everything from embedded to HPC. The language has an amazing way of making code simpler. Eg UFCS, generics, and concepts give the best of OOP without endless scaffoldin…

> Imagine writing Python style pseudoocode for ESP32 and it being super efficient without trying, and with bare metal control when you want.

To be fair, I did have to spend like 2 hours tuning my ESP32 code for handling a 22 kSPS ADC where microseconds matter. ;) Mostly just to avoid extra allocations as I was pretty new to Nim at the time.

Ah, but no major regressions in performance or changes needed for ~4 years!

Re: Nim 2.0

#130

As someone who doesn't know much about Nim: Improved type inference ... let foo: seq[(float, byte, cstring)] = @[(1, 2, "abc")] This looks like a normal type declaration to me, why is there any inference involved?

The problem apparently is that they didn't actually have full type inference and the expressions on the right were given their types (probably a tuple of int x int x cstring) before they attempted the assignment into foo. Now they're using unification (they call it "top-down inference", so I'm guessing it's regular unification like other type inference systems use) so that the expression on the right will have the correct type and be assignable into the variable on the left.
Post reply on HN