5 ms·
Hi, is Nim a good replacement for python? I write a lot of scripts, but I find that python can get cumbersome to maintain. I'm looking for something with strict
by cumshitpiss 4y ago
Hi, is Nim a good replacement for python? I write a lot of scripts, but I find that python can get cumbersome to maintain. I'm looking for something with stricter typing and a sane packaging/directory system, but also easy/fast to write. If Nim can work with numpy it's a plus
- PMunch 4y agoWell it depends a bit on your usecases. Nim certainly has a stricter type system, and since it is compiled you can be fairly certain that a program you have compiled won't suddenly start to misbehave (e.g. no JavaScript leftpad issue since it won't pull in libraries on runtime). The packaging system is fine for most purposes, and it recently got better with the introduction of lock-files. Once you get comfortable with the standard library and your favorite packages it's also very fast to write, maybe even more so than Python because it has less boilerplate. As for numpy there are libraries that allow you to work with Python from Nim, and vice-versa. Not entirely sure how well they work for numpy as I haven't tried that myself. But there are also packages which does similar things in Nim. However packages will probably be your biggest hurdle when converting stuff to Nim. The Nim ecosystem is definitely smaller than Pythons, so it's a bit hit-or-miss if it has the packages you need for your specific usecases. You are more than welcome to join the Discord/IRC/Matrix room and ask around though.
- cardanome 4y agoI think out of the bunch of new system programming languages it sure is the most friendly towards users coming from dynamic programming languages. My nim solutions were actually more concise than my JS code when doing some Advent Of Code puzzles. And it has nimpy which is a bridge to the Python world though I haven't used it personally. The only downside I can think of regarding nim is that the standard library is OK-ish I guess but not great. Still needs some work but I think they are aware of it.
- deleted 4y ago[deleted]
- pietroppeter 4y agoyes, definitely for me nim has replaced python as my go to language even for small tasks. I find it even more productive than python thanks to the typing system. An often neglected highlight that I appreciate a lot is the fact that static typing + procedure overload has the additional benefit that names of functions tend to be very natural (you can reuse the name of function if the type signature is different). That along with UFCS (universal function call syntax), allows to create great apis in no times. Also template are a very easy way to boost productivity and allow to write great DSLs. See also an old but still relevant and very valid introduction of Nim for Python programmers [0] It can work with numpy and even better there is a performant numpy replacement called arraymancer. Take into account that since you do not need to be afraid of loops, even working with standard sequences is very performant. See also the SciNim getting started book [1] [0]: https://blog.zdsmith.com/posts/nim-for-python-programmers.html https://blog.zdsmith.com/posts/nim-for-python-programmers.ht... [1]: https://scinim.github.io/getting-started/ https://scinim.github.io/getting-started/
- nimmer 4y ago> If Nim can work with numpy it's a plus Nim goes further there by removing the need for tools like Pandas and numpy. You don't have to write code in "Pandas-style" because native Nim is equally fast and sometimes faster.
- memling 4y ago> Nim goes further there by removing the need for tools like Pandas and numpy. You don't have to write code in "Pandas-style" because native Nim is equally fast and sometimes faster. Can you clarify this? Is there an equivalent data stack in Nim? Or is it that nim is lighter-weight because, for example, it permits transforming tabular data into language structures natively (i.e., without library support)?
- nimmer 4y agoThe latter. For most uses of Pandas you can simply use native arrays. You can use for loops and so on. For N-dimensional array computation: https://github.com/mratsim/Arraymancer/ https://github.com/mratsim/Arraymancer/
- cb321 4y agoBesides @nimmer's fine response, there is also https://github.com/SciNim/Datamancer https://github.com/SciNim/Datamancer
- ThomasTJdev 4y agoFor me it was. Python was everything for me - but too slow. It was a pretty quick to convert software to Nim, and I have never looked back. You don't get the whole ecosystem from python, but you get fast code and easy syntax. We even often use Nim instead of small shell scripting.