11 ms·
Nim – Python-like statically-typed compiled language
- xiaodai 6y agoI am just surprised this hasn't been on HN before.
- emit_time 6y agoNim has been mentioned on here many times.
- xiaodai 6y agothen why is this on the front page?
- gameswithgo 6y agowe ran out of new things
- tomrod 6y agoTo be fair, I discovered it on exercism.io and am thoroughly enjoying learning it.
- mroche 6y agoWhat are your thoughts on exercism, if you don’t mind me asking? I personally liked it when I dove into Go and Rust and was searching for practice material.
- tomrod 6y agoAbsolutely love it to learn syntax. Work through the logic once in language of choice, then apply to several languages to learn its syntax. If there is time, go through code review to get antipatterns worked out. Also fun to mentor, I would reckon.
- snazz 6y agoThis is arguably a dupe, since Nim has been discussed on here in the last 12 months.
- ilaksh 6y agoIt often gets posted and ends up on the home page because many developers are very impressed by Nim and love it.
- trenchgun 6y agoIndeed. https://hn.algolia.com/?q=nim https://hn.algolia.com/?q=nim
- solarkraft 6y agoIt has.
- Grimm1 6y agoI'm stuck in this cycle with langs like this. I want to use Nim I want to use Crystal they to me represent real tangible improvements over the languages they were based on but run into the issue of ecosystem and adoption every-time. I know it's chicken or the egg but I have real problems choosing these languages when they just aren't as battle hardened or package wise versatile as say python or ruby when making decisions for my own tech stacks in a startup or for other companies I have or will work for.
- tomrod 6y agoI hear you. For me it makes compiled languages fun again. I like rust but package maintenance gets rough. Things like this are what I'm enjoying discovering: https://robert-mcdermott.gitlab.io/posts/speeding-up-python-with-nim/ https://robert-mcdermott.gitlab.io/posts/speeding-up-python-...
- elcritch 6y agoSecond that, I find Nim fun to program. Not sure exactly why.. Perhaps, it‘a a bit of the feel of the old Python 2 days, but with better package management, less OO, and static binaries. Or it has more advanced abilities that solve annoying points with static languages like C++ via proper macros. Crystal looks nice too, but I want code that compiles to C/C++, not llvm for embedded work. Not sure about Crystal, but I’ve been able to find all the packages I needed for embedded and even some ML work. That Nim can wrap C/C++ libraries really helps there, otherwise it’d be a pain. For example I wanted to load PNG images, well someone wrapped a C library [1]. Or to create Elixir NIFs (with exception safety!) [2]. Generally if there’s a C/C++ package it only takes a few hours to wrap and use. Nim has some annoying parts, like understanding the ref/var distinction and lack of examples. The documentation is fairly complete otherwise. 1: https://github.com/define-private-public/stb_image-Nim https://github.com/define-private-public/stb_image-Nim 2: https://github.com/wltsmrz/nimler https://github.com/wltsmrz/nimler
- triangleman 6y agoStrange to see powershell core have such poor performance. Isn't it basically .NET in a scripting language? I've had great success grepping through gigs of log files with powershell, though I recognize that's apples to oranges.
- manishsharan 6y agoI debated whether to start learning Rust vs Nim... Rust does seem to have more libraries to get stuff done.
- Waterluvian 6y agoI find that with JavaScript, Rust, and Python, my tool belt is pretty well equipped these days.
- adamnemecek 6y agoAlso consider julia.
- collyw 6y agoI would say that you need to present a case where Julia would be needed. I do Python and Javascript it covers most stuff that isn't low level. Rust does that, so what is the need for Julia?
- adamnemecek 6y agoNumerics and ml.
- Majestic121 6y agoPython handles that pretty well. Maybe Julia does it marginally better, but I don't think it's worth learning a whole new language for this unless your day job is only 'Numerics and ml'
- snazz 6y agoFrom this perspective, I totally agree. If you enjoy learning new languages (at a surface level understanding) for the increase in perspective, you might find Julia worth learning.
- 6y ago
- NateEag 6y agoShouldn't the title be "with static typing?" Python has strong types. It's just that it checks them at runtime, not before. If you don't use MyPy or similar, anyway.
- tomrod 6y agoThat may be the case. I apologize, I am a tinkerer programmer and the semantics are sometimes lost on me.
- cheez 6y agoPython's new typing is so useful. mypy works most of the time. Sometimes misses some things. Running in --strict is a bother (no one is going to annotate __init__ returning None thanks...)
- ghostwriter 6y agoyou don't have to https://github.com/python/mypy/pull/5677 https://github.com/python/mypy/pull/5677
- cheez 6y agoWeird... Looks like you're right. Edit: aha, looks like this is the case under which it happens: class Testing123: def __init__(self): self.blah = whatever()
- phoe-krk 6y agoIt should. It's the same as with Common Lisp, which is strongly dynamically typed. Strongly, because it is impossible to confuse a given value's type via some sort of implicit casting; dynamically, since types are checked at runtime.
- guenthert 6y agoI think in modern parlance Common Lisp uses a gradually typed system, at least some implementations. Common Lisp allows for type inference and some compilers use that to various degree, as well as to declare a type of a given symbol (or the signature of a function). Depending on compiler and optimization settings, that information is then used to generate optimized code, much like a compiler for a (weakly) statically typed language would or detect mismatches. SBCL is probably one of the most advanced Common Lisp compilers in this regard.
- sergiotapia 6y agoWhen I started learning Nim I noticed the docs and even the getting started tutorial just threw the kitchen sink at you, it totally overwhelemed me. So here's a simple project I wrote that's easier to understand. I work on this every couple of weeks on Saturdays. https://github.com/sergiotapia/torrentinim https://github.com/sergiotapia/torrentinim For example: parsing html https://github.com/sergiotapia/torrentinim/blob/master/src/crawlers/leetx.nim https://github.com/sergiotapia/torrentinim/blob/master/src/c... I wish the Nim team worked on an easier onboarding process to the language. The documentation is in depth but it just throws everything it has at you all at once with no progression.
- tomrod 6y agoI use exercism.io to pick up syntax, I'm finding this to be helpful for nim.
- planetis 6y ago> When I started learning Nim I noticed the docs and even the getting started tutorial just threw the kitchen sink at you, it totally overwhelmed me. This sums my experience as well. But nowadays there are more resources to learn Nim. The Nim in action book is a few years old but still holds. Nim basics is a free tutorial for beginners https://narimiran.github.io/nim-basics/ https://narimiran.github.io/nim-basics/ When did you start learning Nim?
- open-source-ux 6y agoYes, if you search on the web or YouTube there are surprisingly few tutorials for Nim. Compare that to Julia which has a couple of books published, and also has courses available on Udemy, LinkedIn Learning and YouTube. Some of these Julia courses are pre-1.0 Julia while Nim doesn't even have a course post 1.0 release which is a shame. Let's hope that changes soon - more learning resources can only help interest in Nim grow.
- ilaksh 6y agoNim has a book. The one Dom made. Nim in Action or whatever.
- pansa2 6y agoWhat concurrency support does Nim have? Anything like coroutines, async-await etc? Or just OS threads?
- elcritch 6y agoAll of the above. Though the coroutine library looks out of date. Most network libraries use async. Threads are possible, but weave looks promising: https://github.com/mratsim/weave https://github.com/mratsim/weave
- fiatjaf 6y agoRosettaCode comparison between Rust and Nim: https://rosetta.alhur.es/compare/Rust/Nim/# https://rosetta.alhur.es/compare/Rust/Nim/#
- open-source-ux 6y agoI like Nim. It's almost a year since version 1.00 of the language was released (in September 2019), but I wonder how the language has fared since then. Has usage grown since that key milestone? Gaining 'mindshare' among developers is obviously important but also difficult. Of course, supporting libraries are also important in encouraging adoption, but that is just one piece of the picture. I see a pattern of sorts for some new(ish) languages: without a prominent, well-known sponsor, the language might struggle to gain attention among developers. I wonder what will be the fate of other languages without generous sponsors as they head to their version 1.00 e.g. Crystal or Zig? Julia is doing relatively well without a big main sponsor - interest seems to be growing in the language. Rust and Go are two languages that have benefited hugely from support from Mozilla (Rust) and Google (Go). But back to Nim. Who's using Nim? What are you using it for and how are you finding it?
- gw 6y ago> Who's using Nim? What are you using it for and how are you finding it? I am using it for game and music programming: https://github.com/paranim https://github.com/paranim Only been using it since the beginning of the year and it is fantastic. Much less development friction than rust, and perf is very good, especially with ARC.
- DennisP 6y agoOne of the near-production clients for Ethereum's proof-of-stake blockchain is written in Nim.
- exdsq 6y agoDidn’t know that! Any good articles on why the chose Nim?
- planetis 6y agoIt's called Nimbus, since it wasn't mentioned, here's their website: https://nimbus.team/ https://nimbus.team/ and why Nim is explained here: https://our.status.im/status-partners-with-the-team-behind-the-programming-language-nim/ https://our.status.im/status-partners-with-the-team-behind-t...
- cpach 6y agoIf anyone wants to know how Nim can be used in practice, you might want to take a peek at the NimSvg library. It’s a DSL for generating SVG files and GIF animations and to me it looks quite compelling. https://github.com/bluenote10/NimSvg https://github.com/bluenote10/NimSvg
- Igelau 6y agoThe contents of the examples dir are pretty slick. I've never even touched Nim but these make more sense to my brain than svg. It says DSL but reads more like an improved alternate syntax. Thanks for sharing this and there goes my afternoon :)
- pbsds 6y agoWorth mentioning is NimScript, a subset of nim which can be interpreted, and embedded like lua: https://nim-lang.org/docs/nims.html https://nim-lang.org/docs/nims.html If for some reason the nim compiler starts becoming slow, then this could also drastically speed up development
- gw 6y agoYeah it really is a hidden gem. You can use it as a bash replacement, and with the new compiler API you can embed the entire interpreter in your program. My only complaint is that the interpreter aborts the process when the nimscript code has an error, so you can't really use it for hot code reloading right now. I hope they fix that eventually.
- ilaksh 6y agoThere is really no way to trap it? Maybe fork the NimScript stuff to give the option to try to hang around?
- gw 6y agoI did manage to fork it and prevent it from aborting, but i don't want to maintain it forever. I tracked it down to this function: https://github.com/nim-lang/Nim/blob/cd28fe2ef7a204721efa72082c9f65f8d13bcfb3/compiler/msgs.nim#L408-L421 https://github.com/nim-lang/Nim/blob/cd28fe2ef7a204721efa720... It's calling `quit` which cannot be caught in a try statement.
- zeeone 6y agoNim is just right down ugly and borrowed the worst from Pascal and Python. The multi-paradigm concept is a mess. Tried it a couple of years ago and moved on to better, more simple tools.
- blargmaster33 6y agoNo {} no deal
- pansa2 6y agoOther than having superficially similar syntax, is Nim really Python-like? Also, Nim seems to be targeting a different niche from Python. As Nim is statically-typed and AOT-compiled, its closest competitor is probably Go. The difference is that Go deliberately tries to be a simple language, while Nim is much more complex.
- nafey 6y agoIn what ways will you say Go is simpler than Nim? I did try out Go but found it a bit difficult. Maybe would need to spend some more time.
- tyingq 6y agoNim does have a fair amount of Perl like "more than one way to do it" things. Like countup(), ".." and "..<".
- auxym 6y agoNim has more features like generics and metaprogramming via templates and macros. You don't have to use them, but if you read someone else's code that uses it, you might have trouble understanding it, which probably doesn't happen with Go.
- cma 6y agoGo is adding generics, so you may have to read other people's code using them.
- mesaframe 6y agoThat's a poor excuse. You cannot do everything in just few things and would want things that help you do more, or create abstractions easily. That will require additional syntax. In Go absence of generics will make you write more code that will increase code length unnecessarily.
- auxym 6y ago
- thom 6y agoLoads of interesting stuff available in the talks from NimConf 2020: https://www.youtube.com/playlist?list=PLxLdEZg8DRwTIEzUpfaIcBqhsj09mLWHx https://www.youtube.com/playlist?list=PLxLdEZg8DRwTIEzUpfaIc...
- fraciel 6y agoQue decir esxelente pagina muy adecuada para despejar dudas sobre python lenguaje que me atrae mucho y deceo dominar
- mlthoughts2018 6y agoIf you like Nim but you are looking for something that can be practical for corporate use cases where adopting a new language with a young ecosystem is extremely hard, consider Cython. Cython is a superset of Python that allows super easily compiling custom Python extension modules directly in C or C++, interoperates easily with Python packaging, and is very battle tested. It allows you to “just write for loops in native Python” and get the statically typed & compiled optimizations you’d get in C or C++ for free. It also supports fused types for multiple dispatch of compiled functions. I’ve used it in production workflows at many companies. It’s very easy to use. The best part is that you can apply it gradually, only bothering to implement small sections of code as Cython extension modules when there’s real proof from a profiler that the code is a bottleneck for reasons addressable with static typing. You don’t have to live with the huge premature optimization baked in as a premise to languages that enforce this for all code. “Static typing when _you_ need it.” https://cython.org/ https://cython.org/
- tomrod 6y agoGreat points. The bits of cython I've used are solid.
- montebicyclelo 6y agoCython is excellent. The Numba [1] and NumPy combination is also strong. > Numba translates Python functions to optimized machine code at runtime using the industry-standard LLVM compiler library. [1] http://numba.pydata.org/ http://numba.pydata.org/
- airocker 6y agoHas there ever been an analysis of what percentage of total bugs can be prevented by static typing? I moved from static to dynamic languages and in my experience static languages dont provide too much upside but then I have always worked in smaller teams.
- pansa2 6y agohttps://softwareengineering.stackexchange.com/questions/10032/dynamically-vs-statically-typed-languages-studies https://softwareengineering.stackexchange.com/questions/1003...
- airocker 6y agoThis is good read. In a nutshell, Would it be fair to say start with Python and move to Java when team grows to 50+?
- worldsayshi 6y agoTo me the benefit of static types is more about providing help as I type. Anything that can make the error appear as early as possible as well as provide suggestions that makes sense makes me so much more efficient.
- airocker 6y agoMy experience: I used to interview and do leetcode in C++ and I could never match the speed of Python people. I switched to Python and I could.
- worldsayshi 6y agoWhat is easy or hard in a few hundred lines of code doesn't say much about what is easy or hard in thousands of lines.
- yawaramin 6y agoSee https://blog.acolyer.org/2017/09/19/to-type-or-not-to-type-quantifying-detectable-bugs-in-javascript/ https://blog.acolyer.org/2017/09/19/to-type-or-not-to-type-q...
- xrisk 6y agoMy main gripe with Nim is that documentation (even for the standard library!) is in absolute shambles. Not to mention the lack of an ecosystem. I think that authors of Nim libraries get so tied up in their superiority over having types and being compiled that they forget that most devs don’t really care about these things on their own. It’s only when these things are combined with good documentation and tooling (see Rust for example) that they become useful.
- tyingq 6y agoI'd guess a fair amount of that is just because it's a much smaller team of folks, with fewer resources.
- planetis 6y agoHey that's unfair :(. Nim's dev team had done user surveys for three years now https://nim-lang.org/blog/2020/02/18/community-survey-results-2019.html https://nim-lang.org/blog/2020/02/18/community-survey-result... and improved the docs significantly. Rust has excellent docs but also a larger dev-team.
- ilaksh 6y agoI liked the documentation when I was looking at it before. What are you talking about "shambles"?
- fwsgonzo 6y agoIt has a RISC-V backend in case anyone was curious. And it can compile down to C/C++! I have a C/C++ runtime environment that is very unique, and I don't even know how to begin explaining it, but the fact that I potentially don't have to build shims on top of it is just very interesting to me. I'm going to tinker with it.
- elcritch 6y agoExactly, llvm doesn’t support many unique backends. Be sure to use the ARC garbage collector! Certainly checkout c2nim.
- planetis 6y agoA very informative interview with Araq (the creator of Nim) was posted a few months ago: https://www.youtube.com/watch?v=-9SGIB946lw https://www.youtube.com/watch?v=-9SGIB946lw It's mostly up-to-date.
- planetis 6y agoNimConf 2020 [1] also took place just recently, was great success. [1]: https://conf.nim-lang.org/ https://conf.nim-lang.org/ Hacker news coverage: https://news.ycombinator.com/item?id=23585006 https://news.ycombinator.com/item?id=23585006
- FRidh 6y agoFor a while now I've been looking at using Nim, and this weekend I did my first project with it: a tool for creating binary wrappers. In Nixpkgs we often create wrappers, but those have thus far been shell scripts causing trouble at times on e.g. OSX. https://github.com/NixOS/nixpkgs/pull/95569 https://github.com/NixOS/nixpkgs/pull/95569 I found it easy to get up to speed and do something useful with it. The language is also in my opinion very readable. The documentation could use some more (larger) examples though. For this wrappers tool I needed a front-end for which I wanted to create an interface with argparse. Unfortunately the standard library lacks an implementation, and third-party packages did not deliver what I needed. In the end I wrote that part in Python still. The biggest issue I currently find is the lack of a lock file format for its package manager. It's being developed, and as soon as its there I intend to implement support for it in Nixpkgs. https://github.com/nim-lang/nimble/issues/127 https://github.com/nim-lang/nimble/issues/127. The compiler gives very useful output and is fast as well, and the generated binaries are small. I like this language!
- cb321 6y agoIf you use the TinyCC/tcc back end then compiling is nearly instant (I use the "tcc mob branch" all the time). You can even put a shebang at the top of your file (#!/usr/bin/nim r) and have an edit-run cycle similar to scripting languages, just a tiny edit toward "nim c -d:danger foo.nim" the file to get a production/deployment performance self-contained binary.
- disruptek 6y agoNimph has had lockfiles for months. https://github.com/disruptek/nimph https://github.com/disruptek/nimph
- FRidh 6y agoThanks! I was only aware of Nimble. I'll have a look at it. One thing I noticed right away that it seems to be lacking (judging from the `nimph.json` assuming that is the lock file) are checksums over the data or hashes of revisions the references correspond to. References such as tags are mutable, and thus hashes are needed to validate them. See e.g. the discussion over at https://github.com/NixOS/nix/pull/3216 https://github.com/NixOS/nix/pull/3216.
- darthrupert 6y agoNim is an amazing language that suffers from a lack of momentum and hype. Technically, there’s little reason why it shouldn’t be a good choice for many programming problems. Reality doesn’t work like that, of course. Hype is important, and not just because that will mean more libraries. Hype motivates people to do things they wouldn’t have otherwise done at all. Rust demonstrates this well.
- throwaway815190 6y ago> Nim is an amazing language that suffers from a lack of momentum and hype. And good multithreading and network libraries.
- planetis 6y agoIs it hype, or controversy then? :P Latest development in Nim is reference counting is planned to replace the GC https://forum.nim-lang.org/t/6549 https://forum.nim-lang.org/t/6549. However this is done in a non-breaking way and their isn't much criticism, except the development effort and the countless bugs that were introduced. Hopefully this will lead to better multi threading which is a shortcoming of the language, thus opening new fields.
- Aardappel 6y agoAnother statically typed language that "looks like Python": http://strlen.com/lobster/ http://strlen.com/lobster/
- efgha4351 6y agoAnother language, which is a possible alternative to Nim, is Slider, available at http://mrsename.blogspot.com/ http://mrsename.blogspot.com/