News for hackers. Stuff that matters.
Re:A Cost Model for Nim by alberth on Friday November 11, 2022 @12:13PM (#33563511)
I've always been surprised Nim hasn't taken off more.

All the productivity of a language like Python but with the performance of C.

Re:A Cost Model for Nim by nerdponx on Friday November 11, 2022 @12:40PM (#33563936)
I have really enjoyed using it for random scripts and small programs, but it definitely is slower than plain C for simple things like "loop over lines of stdin and do some basic calculations". Of course, you also get a lot of nice abstraction, memory safety, GC, a great standard library, compiler-checked effects (!), less-noisy syntax, and a nice easy compiler CLI, and that's a tradeoff I'm happy to make. Not to mention that I would feel much more comfortable writing a bigger application in Nim than in C.
Re:A Cost Model for Nim by monetus on Friday November 11, 2022 @01:11PM (#33564431)
That slowness is tied to the GC, which you can swap in and out with others or turn off. I feel like this is a really undersold feature of the language.
Re:A Cost Model for Nim by cb321 on Friday November 11, 2022 @01:20PM (#33564564)
It's a mixture of allocation, copying, and reclamation. You can actually side-step a lot of such issues in a mostly mm-agnostic way with a `var` like interface in Nim -- sticking to one initial allocation like the common pattern of caller-allocated storage in C. These days on three-level cache server CPUs the real cost of hitting virgin, uncached memory is probably worse than other pieces..DRAM latency is >10x L3, but almost everything "depends on..".
Re:A Cost Model for Nim by arc776 on Friday November 11, 2022 @02:15PM (#33565343)
100% my experience too. GC in Nim is a rounding error at worst and is often statically elided, anyway. Performance is almost entirely about memory access patterns and you have the same access to this as C.

In other words, performance in Nim is entirely down to the algorithm used, which is a nice place to be.

Re:A Cost Model for Nim by cb321 on Friday November 11, 2022 @01:14PM (#33564468)
I have not found this slower-than-C to be the case. You may need to use something like `iterator getDelims` in https://github.com/c-blake/cligen/blob/master/cligen/osUt.ni... to manage memory with fewer copies/less alloc "more like C", though or perhaps `std/memfiles` memory mapped IO.

More pithy ways to put it are that "there are no speed limits" or "Nim responds to optimization effort about as well as other low level languages like C". You can deploy SIMD intrinsics, for example. In my experience, it's not that hard to "pay only for what you use".

As a more concrete thing, I have timed (yes, on one CPU, one test case, etc..many caveats) the tokenizer used in https://github.com/c-blake/bu/blob/main/rp.nim to be faster than that used by the Rust xsv.

Of course, you really shouldn't tokenize a lot if it's costly, but rather save a binary answer that does not need parsing (or perhaps more accurately is natively parsed by the CPU).

Re:A Cost Model for Nim by nerdponx on Friday November 11, 2022 @01:19PM (#33564550)
This stuff honestly goes over my head and beyond my current skillset, but it's useful to know that there is no "speed limit" in the hands of someone who knows what they're doing.

My experience has been with basically translating Python and shell scripts into Nim, and occasionally comparing them with my own feeble attempts at doing the same in C.

Re:A Cost Model for Nim by elcritch on Saturday November 12, 2022 @01:43AM (#33570660)
Just a note that the "loop over lines of stdin and do some basic calculations" use case highlights probably one of the places where it's really easy to blow up Nim's performance benefits -- string or seq copies. :/

The issue is that Nim's string library ends up making copies when doing things. It's a sane default and ensures sane behavior. However, it often leads beginner's to make slower programs, sometimes even slower than equivalent Python ones. If you used `strcopy` in C a lot, you'd get similar results.

Often the solution is trivial and is just to use the `var` or `openArray[T]` variants of proc's. It's one of the points in the blog post and is crucial for good real time code. I'm hopeful the new `lent` and `view` features will make it easier to use non-copy slices on strings. That'd be nice!

Re:A Cost Model for Nim by xigoi on Saturday November 12, 2022 @08:24AM (#33572813)
Just to be sure, did you compile it with -d:release/-d:danger? This is a common mistake people make when benchmarking Nim.
Re:A Cost Model for Nim by 0cf8612b2e1e on Friday November 11, 2022 @12:56PM (#33564182)
No 800 pound gorilla has taken the language under its wing, so really difficult to build mindshare. Without a Google, Microsoft, etc who can throw unlimited funding to have full time developers polishing rough edges, writing docs, or implementing libraries, a new language is always lacking vs established alternatives.
Re:A Cost Model for Nim by olah_1 on Friday November 11, 2022 @01:07PM (#33564382)
The only thing close is some ethereum tools like these:

- https://github.com/status-im/nwaku

- https://github.com/status-im/nimbus-eth2

But I think the real killer feature to me is the javascript target. It seems like a real dream for a fullstack experience.

Re:A Cost Model for Nim by arc776 on Friday November 11, 2022 @02:28PM (#33565556)
> the real killer feature to me is the javascript target

Agree, this is amazing because you can share code and data structures between front and backend (for example: https://github.com/karaxnim/karax).

Also, it's really nice having high level stuff like metaprogramming and static typing spanning both targets. Things like reading a spec file and generating statically checked APIs for server/client is straightforward, which opens up a lot of possibilities.

Re:A Cost Model for Nim by dom96 on Friday November 11, 2022 @03:12PM (#33566169)
Honestly as someone that has used Nim for this extensively, I think that these days with WASM and TypeScript available this isn’t much of a killer feature anymore.
Re:A Cost Model for Nim by arc776 on Friday November 11, 2022 @03:44PM (#33566559)
Only if you consider the web side.

Backend and frontend in the same language is a massive feature for many reasons, not least performance and uniformity. Adding TypeScript is increasing interface friction and complexity, instead of simplifying things.

Of course, right now this may or may not be easier/harder/feasible with just Nim depending on the project, and many more people know TypeScript, but the ideal of one language > many languages is a worthy one.

Re:A Cost Model for Nim by dom96 on Friday November 11, 2022 @05:25PM (#33567700)
What do you mean? I am considering it from both sides.

TypeScript already allows this, i.e. you can build the backend and frontend in one language (TypeScript). Same for most languages that compile to WASM.

My point is that with TypeScript this killer feature is already realised and in a way that is far more familiar to the many thousands of developers that already know JavaScript.

Re:A Cost Model for Nim by arc776 on Friday November 11, 2022 @06:19PM (#33568131)
> you can build the backend and frontend in one language (TypeScript)

Sure, from the uniformity side, but what about performance?

It's not just latency performance either, it's resource performance and overheads, such as with embedded servers.

> with TypeScript this killer feature is already realised

It really depends on your requirements whether this is true. Personally, a systems language I can use for web stuff is more useful and has a wider scope to me than running JavaScript or WASM in a systems role, even though it is technically possible to do so.

Re:A Cost Model for Nim by dom96 on Friday November 11, 2022 @06:33PM (#33568237)
In the general case I think you underestimate how performant JavaScript JITs are these days. For 99.9% of use cases the performance is enough.

Sure, for embedded it might not be workable, but again- since we're discussing killer features I think we need to think bigger. Embedded is far too small a niche to be considered to be Nim's killer feature, especially when this space is already dominated by Rust which supports WASM very well (and therefore hits the performance + uniformity you desire).

Re:A Cost Model for Nim by arc776 on Friday November 11, 2022 @08:12PM (#33568963)
> In the general case I think you underestimate how performant JavaScript JITs are these days.

No, I'm well aware of JS and WASM performance, internals, and pitfalls.

> For 99.9% of use cases the performance is enough.

Again, it depends on your perspective and requirements. Statistically, PHP is enough for most people so why use TypeScript? At the edges of the resources bell curve however the details do matter. It's not enough to say that for those concerns you must use different language and potentially a whole different set of semantics, intricacies, libraries and workflows.

> I think we need to think bigger. Embedded is far too small a niche to be considered to be Nim's killer feature

That wasn't my point, and ironically you might be underestimating how much minimising power and resource usage drives much of the modern world. Memory/storage + CPU ticks == money.

My point is that a language that can act as a universal tool without sacrificing efficiency, productivity, or extensibility (via AST macros), is itself a 'killer feature'. Nim hits that sweet spot of being easy to read and write as well as 'close to the metal'. It lets me target JS, embedded, and natively interface with C and C++ ABI. That gives me a lot of options with one language. There are other languages that have some of these traits, but not all together in a nice package IMO.

> especially when this space is already dominated by Rust

You mean C?

Re:A Cost Model for Nim by dom96 on Saturday November 12, 2022 @05:32AM (#33571846)
> Statistically, PHP is enough for most people so why use TypeScript?

In the context of our discussion PHP doesn't make sense as it doesn't have native support for running in the browser. TypeScript is specifically a good choice because it has been built with the browser and the backend in mind.

> you might be underestimating how much minimising power and resource usage drives much of the modern world. Memory/storage + CPU ticks == money.

I have learned over the years that what actually drives the modern world is pragmatism. Sure, performance matters, but when you have to reimplement hundreds of libraries from scratch because the ecosystem doesn't exist then you are losing far too much time (and your implementations of those libraries are likely to be suboptimal). You're better off losing some performance and picking the established language, so that you actually ship your project within a couple of months instead of a couple of years.

Nim has been going now for 15 years and has thus far failed to reach critical mass. With each year gaining that critical mass becomes less and less likely. A killer feature for Nim needs to be so beneficial that it overcomes the lacking ecosystem.

> You mean C?

I was referring to the space of languages that work well on embedded and in the browser. C doesn't support the browser side well.

Re:A Cost Model for Nim by arc776 on Saturday November 12, 2022 @07:44PM (#33578787)
> TypeScript is specifically a good choice because it has been built with the browser and the backend in mind.

Sure, if your only use case is web front/back end uniformity.

My use case covers web front and back end, but also custom embedded, HPC, ML, simulations, and a lot of other stuff that is simply not viable with TS/JS or WASM. This language lets me share abstractions and reuse code across all this stuff and use C/C++/JS/Python ecosystems directly.

All the above are possible with just JS. Yes, you can even run JS on a microcontroller: https://www.espruino.com/

The V8 JS/WASM engine, however, is written in C++ for good reason. TS/JS/WASM/web is built on people counting ticks and aligning bytes to give even the floppiest callback spaghetti of frameworks the overhead to be responsive as abstractions increase.

> I have learned over the years that what actually drives the modern world is pragmatism.

I agree, except I think it's more pragmatic to have one language that can service any industry. TS/JS ain't it, from my perspective.

> reimplement hundreds of libraries from scratch because the ecosystem doesn't exist then you are losing far too much time

Why would you reimplement libraries from scratch instead of using FFI? FFI is one of the many, apparently unrecognised, 'killer features'. Specifically killer is FFI with ABI compatibility to C++. The pragmatic approach is always to stand on the shoulders of giants and FFI with existing libraries for the reasons you listed.

I'm surprised to hear you say that to be honest as you've used the language for years. Is there an experience behind it?

> You're better off losing some performance and picking the established language, so that you actually ship your project within a couple of months instead of a couple of years.

Well, I don't disagree with the sentiment, but this is more of a commentary on the job market/cost of business than capability.

Again, though, it really depends what you're doing. Chucking out a web app for an internal tool and distributed websites have different requirements.

> Nim has been going now for 15 years and has thus far failed to reach critical mass. With each year gaining that critical mass becomes less and less likely.

What a strange take. Programming languages aren't food left out of the fridge, they're tools to do a job.

Python was made in the 1980s and took decades to even be known about. Why did people start using Python? Because it was readable, convenient, and very productive. Why did it become popular? Because people used it more...

What you call 'critical mass' is just a visible hiring pool.

Companies need confidence to find or train people in the language, and developers need confidence they can pay their bills by learning it. Confidence is increased when people hear of business use, say, if FAANG started a some minor project with it, and it feeds back.

Re:A Cost Model for Nim by elcritch on Saturday November 12, 2022 @02:26AM (#33570915)
I'd agree embedded is a pretty niche area, and that it's likely not a killer app for Nim. Though it does bring a fair bit of attention.

However Rust doesn't dominate embedded. That's still C or even C++.

Rust has a lot of embedded crates, but supports a pretty small subset of hardware given the number of crates and amount of effort poured into them. The trait system particularly sucks for modeling hardware, IMHO, and with the "re-write the world" mentality it means there's still quite a bit of pain.

So it seems rosier than it actually is -- for now. Rust on embedded is gaining momentum.

Re:A Cost Model for Nim by dom96 on Saturday November 12, 2022 @05:36AM (#33571869)
> However Rust doesn't dominate embedded. That's still C or even C++.

I don't disagree. What I meant specifically is that Rust dominates the space where you want to target embedded and the browser (Rust does well on embedded and has good WASM support). C/C++ does not support the browser well at all (you can say that it supports WASM too, but Rust has far more front-end frameworks that actually target the browser than C afaik).

Re:A Cost Model for Nim by elcritch on Saturday November 12, 2022 @04:05PM (#33577070)
Ah, gotcha. Rust's tooling for WASM + embedded is pretty good.

I actually want to get Nim + WASM running on embedded so we could do our own MicroPython like setup and not require people to know how to flash the hardware directly.

I know Andreas doesn't care for WASM, but Nim could support native WASM relatively easily. It already does a "re-looper" for the JS backend AFAICT. which is the biggest challenge of WASM.

Re:A Cost Model for Nim by alberth on Friday November 11, 2022 @02:57PM (#33565969)
Who’s the 800 lb gorilla for Rust (because it seems to have large community behind it)?
Re:A Cost Model for Nim by 0cf8612b2e1e on Friday November 11, 2022 @03:09PM (#33566123)
Mozilla funded multiple full time developers for years. While not a “big” company, it does have significant financial resources and creates a very impactful product.
Re:A Cost Model for Nim by azakai on Friday November 11, 2022 @06:37PM (#33568263)
Yes, in fact, almost every successful language of the last decade has had such support: Mozilla funded a Rust team for years, Google funded a Go team, Apple a Swift team, Microsoft for TypeScript, etc. etc.

There are examples of rising languages that never had such corporate sponsorship, like Zig and Julia, but I actually can't think of one as successful as Rust/Go/Swift/etc.?

Re:A Cost Model for Nim by 0cf8612b2e1e on Friday November 11, 2022 @09:29PM (#33569395)
I almost mentioned zig as a counterpoint. I’m sure it is a HN bubble thing, but zig does feel like it has a lot of momentum for a grassroots language without a juggernaut supporting development.
Re:A Cost Model for Nim by open-source-ux on Saturday November 12, 2022 @09:28AM (#33573339)
I agree, but a counterpoint: Dart from Google. Despite the resources poured into Dart, it does not enjoy Go-levels of popularity. Flutter + Dart is now the focus, but it's too early to see if the language will grow in adoption.
Re:A Cost Model for Nim by pjmlp on Saturday November 12, 2022 @03:28PM (#33576702)
Because it wanted to take over the Web via Dartium, then Chrome dropped support for it, it almost disbanded if it weren't for AdWords team, and Flutter gave it a 2nd life.
Re:A Cost Model for Nim by fleventynine on Friday November 11, 2022 @05:00PM (#33567466)
Almost every large tech company that uses C++ heavily is jumping onto the Rust train.
Re:A Cost Model for Nim by winrid on Friday November 11, 2022 @02:45PM (#33565772)
The reason is tooling. The Clion plugin doesn't even do type checking and is a year out of date. The language server has been in progress for five years and is still not done. The VSCode plugin is okay, but refactoring, auto-imports, and autocomplete are nowhere near as easy as other languages like Java in jetbrains products. Not to mention a good debugger.

I hope Jetbrains can prioritize the Clion plugin. It would help a lot.

Re:A Cost Model for Nim by fuckstick on Friday November 11, 2022 @02:48PM (#33565831)
Without disagreeing on the specific points about the tooling, I’m not convinced. Golang took off with a far weaker tooling story. Maybe the table stakes have changed in a decade - but I believe other factors are more important. Moreover I remain skeptical that even if those tooling issues were fixed tomorrow it would help Nim turn the corner.
Re:A Cost Model for Nim by 0cf8612b2e1e on Friday November 11, 2022 @03:28PM (#33566357)
> Golang took off with a far weaker tooling story

All Go had to do was say, “Built by Google” and people came running.

Re:A Cost Model for Nim by elcritch on Friday November 11, 2022 @07:05PM (#33568464)
Well, the "designed by UNIX co-creator" piece helped too I'm sure.
Re:A Cost Model for Nim by silisili on Saturday November 12, 2022 @01:50PM (#33575842)
Dart was built by Google, and nobody wants to touch it. Well, a few diehard fans.

Go is a nice language that gets a lot right. Saying people only use it because of Google is kinda shortsighted.

Re:A Cost Model for Nim by pjmlp on Saturday November 12, 2022 @03:25PM (#33576672)
Because Chrome kind of sabotaged the project by dropping Dartium, while Angular team decided to sponsor Typescript and moved away from Dart.

The language was saved from dying by AdWords, which had just migrated from GWT into AngularDart.

Key designers from Dart 1.0 eventually left Google, like Gilad and Lund.

Flutter gave it a new life, but also is the only reason to use Dart, Flutter apps.

Re:A Cost Model for Nim by winrid on Friday November 11, 2022 @02:51PM (#33565875)
Maybe! It would get me on board, though :) I'm working on a new server side project and am using Java for now, because of this reason. I hope someday I have time to help build IDE plugins and so on :)
Re:A Cost Model for Nim by goodpoint on Monday November 14, 2022 @05:15AM (#33592103)
> Golang took off with a far weaker tooling story

Corporate marketing budget and related astroturfing.

Re:A Cost Model for Nim by xigoi on Saturday November 12, 2022 @08:23AM (#33572798)
Due to the abstraction that Nim offers, things like autocomplete and refactoring are not needed as much as in Java.
Re:A Cost Model for Nim by winrid on Saturday November 12, 2022 @02:16PM (#33576089)
If I start typing newSeq, give me the option to auto import from std, etc. These little things add up.

Also basic usage of generics doesn't really work w/ the vs code plugin, which is the best one.

Re:A Cost Model for Nim by xigoi on Monday November 14, 2022 @08:45AM (#33593774)
> If I start typing newSeq, give me the option to auto import from std, etc.

Good idea! I've made a proof-of-concept Neovim plugin: https://sr.ht/~xigoi/nvim-summon/

It wasn't difficult, so if you use a different editor, you can make one too (feel free to reuse my documentation scraper).

Re:A Cost Model for Nim by winrid on Monday November 14, 2022 @06:34PM (#33602986)
Neat! But I pay for Clion, so I'm hoping they can prioritize this so I don't have to write plugins myself... :)

We'll see when I start my next nim project, how I can contribute..

Re:A Cost Model for Nim by winrid on Monday November 14, 2022 @10:50PM (#33605049)
I am considering betting my next big project on Nim. If it works out and I can work on it full time then I'll have lots of time to help Nim!
Re:A Cost Model for Nim by winrid on Monday November 14, 2022 @06:35PM (#33602995)
Note - looks like generics do work, the issue was my file names had dashes in them. Evidently that is not supported, but I didn't get any errors :p