14 ms·
Nim: Scripting Ease in a Compiled Language
- errantspark 7y agoI've been considering getting into Nim for a while now as something more lightweight/terse to write thin CLI utilities in. I'm glad to hear that it's performing well for this usecase. It's a very attractive alternative to Rust for it's simplicity and terseness. I still haven't gotten around to picking it up though, these days I just use QuickJS for anything that needs to be reasonably portable and thin. Maybe next side project...
- Phillips126 7y agoI would highly recommend it. Setup is incredibly easy (VSCode has great plugins for it), the language is simple to read/write and compiled Nim is very fast with small binaries. I also really like nimfmt to keep my code tidy so I don't need to worry about it. Nim compiles VERY quickly and errors seem to be easy to comprehend. It's definitely one of my go-to languages for most of my projects.
- refaqtor 7y agoNim is great for knocking out commandline apps, I recommend "cligen" for quick and clean options, or "docopt" for friendlier cli options. They feel "scripty" when you can begin with a couple lines and grow it up from there. I found it the easiest to learn. And difficulties getting my other favorite, D, on embedded and Haiku and OS/2 (which also have poor javascript support) was my prompt to give it a try. I found cross-compiling easy. But just as easy was having Nim installed on all my platforms.
- dglass 7y agoIs there anyone using Nim either in side projects or in production that can comment on how they like it? I keep hearing about Nim and it sounds interesting, but I'm not sure I have the mental capacity right now to do a deep dive into the language and build something with it. I'd like to at some point soon though.
- keyle 7y agoI've used Nim a bit for side projects (on and off, even back when it was called Nimrod). I found it really really powerful once I got past the initial bump. It's a fairly small learning curve to be honest, especially if you're familiar with reading Python. What I love about it is the small binaries.
- iikoolpp 7y agoI used Nim for a few projects. My best description is that it's fun, but everything feels kinda off when writing stuff.
- DrKabab 7y agoCan you please elaborate? What about it feels off?
- rwbt 7y agoI used it in production for a small yet fairly critical utility and it worked out very well.
- hackeridiot 7y agoI've used Nim for most of my personal projects for the past ~2 years, and it's generally enjoyable. There are a lot of useful language features. C interop, generics, tagged unions (I always miss these in languages without them), traits (powerful duck typing), channels, generators. Metaprogramming via templates/macros if you want to get crazy. Lots of rope to hang yourself, so to speak. I wouldn't choose to use it in production, mostly because of the developer experience. The documentation and tooling are both pretty bad, and the compiler errors can be arcane (especially when using generics, or when the error only surfaces during C compilation).
- qwerty456127 7y agoLooks cool already but is it easy to cross-compile? I can copy a Python script from my Linux machine and run it on both Mac and Windows PCs. Can Nim build executables for other platforms nearly as easy?
- bloblaw 7y agoWell, you sorta can. As long as you wrote it: * to work in both Python 2 and 3 (no telling what other system's Python will be) * don't use any modules outside of stdlib (that requires install too) Those aren't always requirements, but they are the reason I reach for compiled languages when I can't control the target environment where the program needs to run (or don't want to).
- creatornator 7y agoIn addition to compiler switches that allow you to cross compile from the nim compiler [0], you can compile to c or c++, and then invoke whatever cross-compilation toolchain to compile to more esoteric platforms. [0] https://nim-lang.org/docs/nimc.html#cross-compilation https://nim-lang.org/docs/nimc.html#cross-compilation
- uvtc 7y agoIf cross-compilation is important to you, and you like Nim's level of abstraction, you might have a look at Haxe, which can compile to [lots of different targets](https://haxe.org/documentation/introduction/compiler-targets.html https://haxe.org/documentation/introduction/compiler-targets...).
- iffycan 7y agoYes! I use Nim on macOS to build a Windows exe for bootstrapping a Windows VM. A year ago, you had to dig a little to figure out the right command line incantation, but maybe it's better now.
- refaqtor 7y agocross-compiling to ARM embedded was surprisingly simple
- nimmer 7y ago
- Jefro118 7y agoShameless plug - I interviewed Andreas, the creator of Nim, about his philosophy and design choices here: https://sourcesort.com/interview/andreas-rumpf-on-creating-and-growing-nim https://sourcesort.com/interview/andreas-rumpf-on-creating-a... Might be an interesting read for people who are thinking about using Nim and wondering how it compares to the C family, Python, Go, etc.
- jstimpfle 7y ago> The C-family of languages has quirky syntax, grossly unsafe semantics and slow compilers but is overall quite flexible to use. This is mostly thanks to its meta-programming features like the preprocessor and, in C++'s case, to templates. > The Pascal family of languages has an unpleasant, overly verbose syntax but fast compilers. It also has stronger type systems and extensive runtime checks make it far safer to use. However, it lacks most of the metaprogramming capabilities that I wanted to see in a language. While Nim somehow is not appealing to me, this absolutely nails it.
- SamReidHughes 7y agoIf you like reading stuff like this, you might love the book, The Design and Evolution of C++, by Stroustroup.
- haberman 7y agoIs Nim stable? I have vague memories that some parts of its runtime had some deep issues that weren't yet resolved, like maybe around concurrency? I see the language is at 1.0 now, does it have a stable, solid, dependable implementation and runtime?
- nphard85 7y agoOne thing I find annoying about Nim is the case insensitivity [0]. There was no strong reason for this "feature" and literally no mainstream language does it. Moreover it makes code search a pain. [0] https://nim-lang.org/docs/manual.html#lexical-analysis-identifier-equality https://nim-lang.org/docs/manual.html#lexical-analysis-ident...
- creatornator 7y agoYou can use nimgrep [0] to find symbols that match each other with case insensitivity, but yeah it is unusual. [0] https://nim-lang.org/docs/nimgrep.html https://nim-lang.org/docs/nimgrep.html
- nphard85 7y agonimgrep's alright. I was thinking of code search on, say, github. I feel the additional complexity was unnecessary in an otherwise well designed language.
- lazulicurio 7y agoVB.net is case-insensitive, and probably more popular than you think[1]. I think that case insensitivity actually does make sense when working with symbolic identifiers. I've seen justifications for "Foo" and "foo" being distinct symbols; personally, I find that playing with casing like that reduces my ability to read code quickly. Case insensitivity does have its downsides, but usually it's not as noticeable in VB.net because most development is done in VS, which automatically re-cases symbols to match the original definition. [1] Number 6 based on search engine popularity according to https://www.tiobe.com/tiobe-index/ https://www.tiobe.com/tiobe-index/ Also, anecdotally, it's used quite a bit in industrial automation.
- nine_k 7y agoWith a tool which removes case inconsistency, it's almost like a language which is case-sensitive.
- lone_haxx0r 7y agoNim's syntax is everything I hate in a language. It's not bad, objectively speaking, but its design opinions are the polar opposite of mine.
- andybak 7y agoI'm half and half. I adore syntactic whitespace and it makes me sad that it hasn't become more prevalent. However the flexible identifier rules bother me no end. But as soon as my editor of choice handles it transparently then I guess I might come round.
- edflsafoiewq 7y agoWhat're compile times like?
- todotask 7y agoDo you mean compile times for Nim or a project? It's accurate to test it yourself since it's free.
- pastage 7y agoProjects of any note are notoriously hard to test for yourself since they often use build systems. Golang is nice in this respect, pretty easy and fast.
- PMunch 7y agoNim projects typically use `nimble` that ships with the install. So all you would need to do is `nimble build` in the root folder and voilà! Of course that also pulls the dependencies from the package manager, so you might want to just extract the build step from the `.nimble` file if you wanted to time just the compilation.
- yumaikas 7y agoFor me, I'm seeing compile times averaging around 5-10 seconds, with outlier builds taking up to 40 seconds if the files in question aren't cached. It feels faster than Go, but I think part of that is down to Nim's compile output being verbose by default.
- staticassertion 7y agoHow do data scientists feel about Nim? It feels very pythony, but way faster - could be a really cool language for them, similar to what Julia is trying to be. Curious if anyone in a DS role has tried it out. I'm certainly tempted to try it out, I'm sure I'm losing lots of performance in parts of my analytics pipeline due to Python being garbage slow.
- thanatropism 7y agoRe: speed, I'm seeing the Rust ecosystem get better and better; I'm also learning the language on the weekends with small projects. But also: many many moons ago I had Matlab code that was really slow (and I wanted to run 10^LARGENUM simulations for Monte Carlo purposes) and decided to learn Fortran. It was surprisingly easy to learn, and it did cut my running time from afternoons to minutes. But in the process I found out that my Matlab performance problems were mostly due to arrays being dynamically resized all the time -- while static memory preallocation could be hacked easily in straight Matlab. As for Python, numpy is a fast embedded minilanguage written in C; the difference between "pythonic" and "numpythonic" is not emphasized enough in bootcamps, I think.
- galangalalgol 7y agoMatlab usually flags cases like that in the editor suggesting you reserve space outside a loop. My experience with numpy was that it was 11x slower than visual basic access in excel. I was deali g with a lot of small matricies instead of a big one and I think that contributed. I want to try julia in production. About to try out rust in production.
- pastage 7y agoThe options in python to speed up your code are vast without really having to do much, on a fundamental level. My outdated experience with Nimrod told me that it was a tad too opinionated E.g. Everything is a string in dbs is mentioned in the article. It was an interesting language, for me it felt like a stepping stone to something better. But the docs were really bad,
- jxy 7y agoYou know the language has potential when the top comments on HN are all about syntax. To generate more talking points, somebody ought to write an inverse of dumpLisp: https://nim-lang.org/docs/macros.html#dumpLisp.m%2Cuntyped https://nim-lang.org/docs/macros.html#dumpLisp.m%2Cuntyped
- jimws 7y agoI am confused if you this is an honest opinion or if you are saying with a touch of sarcasm. If it is the latter, a winking smiley or "</sarcasm>" or "/s" would have been nice to avoid triggering Poe's Law. In my honest opinion, discussion on syntax is a distraction. One of the reasons I like Lisp/Clojure is that there is very little syntax. I can just focus on my problem and writing good code.
- PMunch 7y agoI think he meant that if the worst thing people can say about a language is that it has slightly quirky syntax it must've done a lot of things right.
- whateveracct 7y agoI don't think it speaks to potential - it's just Wadler's Law ;)
- gonzus 7y agoDoes nim have any way to write a one-liner that includes nested scopes? Something like `nim --run="if(...) { while(...) { foo; bar;} }"`? Not knowing nim, I just made that syntax up... :-)
- yumaikas 7y agoAuthor of the article here, feel free to ask me anything if you're wanting to understand something about the article, or about Nim. I am not the author of Nim. I also want to point out that Nim does have an IRC channel (#nim) on freenode, which was helpful for understanding some of these things.