Hacker News new | ask | show | jobs
by treeform 301 days ago
I feel like Nim made me fall in love with programming again.

Nim fixes many of the issues I had with Python. First, I can now make games with Nim because it’s super fast and easily interfaces with all of the high performance OS and graphics APIs. Second, typos no longer crash in production because the compiler checks everything. If it complies it runs. Finally, refactors are easy, because the compiler practically guides you through them. The cross compiling story is great you can compile to JS on the front end. You can use pytorch and numpy from Nim. You can write CUDA kernels in Nim. It can do everything.

See: https://www.reddit.com/r/RedditEng/comments/yvbt4h/why_i_enj...

4 comments

I feel like Nim, along with C#, is one of the few languages that just cannot be used without a great IDE.

It heavily encourages namespace pollution and `import *`, making it very hard to figure out what where a given function is coming from and hence what it does.

I agree with all your points but last I tried, the VS Code LSP was terrible. It’s hard to justify a new language when even the basics of autocomplete, inline errors and go to definition don’t work well. Part of the reason was that any function can be called on anything, which pollutes the autocomplete list.

Has the LSP situation improved yet? Similar issue with Crystal lang, which I enjoy even more than Nim.

Unfortunately the LSP hasn’t improved that much. There’s been some work on to kill errant processes and such. So it’s a bit more stable. It does work pretty well when it works though. But I just kill it now.

Unfortunately it may not be until Nim 3 based on the Nimony rewrite comes out. It supports incremental compiling and caching which will make the underlying LSP tooling much better.

However I find with Cursor that I don’t mind so much the missing autocomplete. I’ve actually thought about writing an alternative LSP just for quick find and error inlining…

Frankly, I'm surprised this is the only issue you bring up (I had many, when I first tried Nim several years ago - I think they were related to cross-platform GUI libraries for Nim, or the lack of them, or their awful state back then).

But LSP as a major concern? For me these little helpers are useful to catch small typos but I could happily do without them.

It's not just small typos, it's the ability to explore apis, the standard library, go to definition, quickly catch any error at the location it happens, not having to memorize large models and their field names, the list goes on.

I can work without an LSP, but when I'm searching for a new language that would be used by a team (including Junior devs) it's hard to justify something missing the basics of good DX. I haven't tried it with Cursor though, it might be less of a dealbreaker at this point.

How do you navigate through a project with things like `go to definition` or `incoming calls`? (given that we are talking about a relatively large code base maintained by more that one or two individuals)

You can do it with just rg or something similar but it will give you many false positives and are going to waste quite some time.

That’s very interesting actually. Can you call only specially wrapped libraries from Nim, or is any Python library importable? When you cross-compile to JS can you only use pure-Nim libraries or how does that work?
It's not a built-in Nim feature, and it'll only work with native backends (C/C++/ObjC). The project that makes it possible is https://github.com/yglukhov/nimpy
>typos no longer crash in production because the compiler checks everything.

Gentle correction: Python is typed now too and you can get the benefits of typing both in your IDE (via LSP) and before deploying to production (via mypy and the like). This happens both by type inference as well as explicit type annotations.

That's the dream. Reality is very different. Mypy presents numerous false negatives and false positives. Useful to screen for some bugs, but definitely far from giving guarantees.

Not to mention, if a library does not or does sloppily use type annotations, you would not get reliability even with a perfect type checker.

Sure but you can also write bugs in a perfectly typed compiled language. Short of formal verification the best we can do is try to minimise the possible surface for errors to occur. I'm of the opinion that language and tooling plays only a small part in writing robust software. What's more important is designing software using simple components that are small enough to be obviously correct.
I'm sure you're right that there are situations where mypy or ty or LSP give false positives/negatives, but in my use of them over the last ~6 months I really haven't run into many of those situations, or at least none come to mind. Libraries without type annotations do reduce the effectiveness to just what can be inferred by the type checker.
you need to work on big project for these flaws to become a problem. Say, you have a huge code base, 100000's of lines that you didn't write. Then you want to refactor a method's name. Python can't give you any guarantee the refactoring is fully complete. Only a real typed language can do that.

I write 95% of my code in python, I love it, it's my go to language for many things. But for huge code base which I don't master, the lack of type system makes me more than nervous.

"Is typed now" is false.

"Can be typed now" is somewhat correct.

"Can be partially typed now" is actually correct.

> Gentle correction: Python is typed now too

No it's not and you should lose your union card for lying like this.

Take a deep breath
What percentage of typing features does a language need to have to be "good enough"? Because I'm gaining benefits of typed languages in Python, but responses to this thread are, literally: You aren't a programmer.
The fact that you have to run a separate tool just to check typing is a joke.
True but IME languages that are historically dynamically typed have a rough time truly converting to static types.

Php even seems to have decent static types these days, but do my coworkers use them? Hell no

Somehow "gentle correction" sounds more aggressive (passive aggressive) than just saying correction.
It's patronizing.