13 ms·
What makes Nim practical?
- moe 12y agoI love how these new languages compile into a static binary and thereby avoid the deployment nightmares of Ruby/Python. More of that please!
- andybak 12y agopy2app and py2exe are fairly solid in this regard, aren't they?
- Wilya 12y agoNo experience with py2app, but I've used py2exe and pyinstaller in production. They can be made to work, but you regularly stumble on some more or less obscure bugs. The short of it, is that you have no guarantee that the compilation step won't introduce bugs in your program, so you need a solid test suite for the compiled binary. It's feasible, but clunky, and you really get the feeling that the compilers aren't first-class citizens.
- untitaker_ 12y agoI came across [pex](https://github.com/pantsbuild/pex https://github.com/pantsbuild/pex) a while ago. It basically compiles your package and all its dependencies into a single zipped module. I never had the opportunity to try it out myself though.
- woadwarrior01 12y agoIf PEP-441[1] makes it to Python 3.5, pex like functionality will be a part of the standard library. [1]: https://www.python.org/dev/peps/pep-0441/ https://www.python.org/dev/peps/pep-0441/
- untitaker_ 12y agoIt's not quite the same I think. The format is very similar, yes, and I think it'd be nice if the PEX program could be made to work with this PEP. However, the PEX program bundles dependencies, which this PEP doesn't seem to be explicitly about.
- pjmlp 12y agoIf Common Lisp, Scheme or Dylan had been adopted by mainstream programmers, dynamic languages with JIT/AOT compilers would already be a common practice instead of only available to a few that care to look around.
- JimmyM 12y agoGreat post. I thought I'd comment just to say about the relative URL ../what-is-special-about-nim not working as intended from the homepage and the link to http://nim-lang/ http://nim-lang/ which should presumably be http://nim-lang.org http://nim-lang.org Seems a shame to make such a pedantic and insubstantial comment on such an interesting article about a language I'd not come across, but thought the author might like to know.
- def- 12y agoOops, I thought I checked all links. Thank you!
- iopq 12y agoI just realized something: Nim is like a faster Python or a better Go lang It's not really competing in quite the same space as say, D or Rust. It's like a statically typed scripting language.
- def- 12y agoWhy would you say it's not competing with D and Rust? Performance-wise Nim should be in the same ball-park, and you can do systems programming in it. For me Nim is a universal language which I can use for almost anything.
- Rusky 12y agoD maybe, since it has a GC, but Rust not as much. A lot of defaults are different, affecting how libraries and idiomatic code are written and what situations it can be used in without turning things off or avoiding features.
- iopq 12y agoRust is where you can write code that relies on a custom allocator. Or a program that doesn't allocate memory. It's usable for the really low level stuff. Because of this everything must be explicit. Nim is implicit. It doesn't require you to declare a main() function, for example.
- pcwalton 12y agoNim does not have the memory safety without garbage collection features of Rust. If you want memory safety in Nim, you have to use the garbage collector (which, last I looked, is not thread safe either, although I see that Boehm is now an option). It's easy to write (a) an unsafe language that has no GC, or (b) a safe language that relies on GC for safety. It's also easy to write a language that is in category (b) but lets you drop down to category (a) in an unsafe dialect. It's a very difficult problem to write a safe language that does not rely on GC, and I know of no other industry language that has done it. Unfortunately, people often lump Rust into categories (a) or (b), without realizing that what makes it interesting is that it isn't in either. Nim may be in category (b) (if the thread safety issues in the GC have been solved, or you use Boehm, or your app is solely single-threaded) with the ability to drop down to category (a), but it is not in Rust's category.
- BoppreH 12y agoI read the Nim manual a while ago (http://nim-lang.org/manual.html http://nim-lang.org/manual.html), back when it was Nimrod. As a Python user, I loved it. Every single problem I had with Python, Nim seemed to have solved elegantly. Performance, distribution, typing... Everything looked perfect, and none of the Python expressiveness seemed to have been sacrificed. But it was transpiled to C, and the abstraction was leaky. Every once in a while the manual would mention that certain structures were not supported, and it was clear C was the culprit. I think the most glaring example were nested functions, or something similar. I thought to myself "this will bite me in the ass sooner or later" and gave up. Maybe it's time to try again. If they plugged the abstraction holes, this will be a killer language, with applications everywhere.
- def- 12y agoNested functions like this?: proc a = proc b = proc c = proc d = echo "Hello World" d() c() b() a() Works fine.
- falcolas 12y agoIf (and I haven't been interested enough in Nim to investigate) it is indeed compiled to C and then compiled down to platform specific code, unless they are implementing functions differently, nested functions are not a standard part of C; they are a compiler extension (which GCC supports). Not necessarily a problem, but unless implemented as something other than nested functions in C, there may be some portability issues. Worth investigating.
- antman 12y agoI tried it and it is easy and fast. But the ecosystem is still not very large. I think that it should support building libriaries directly accessible from python including passing numpy arrays directly to nim. That would make a lot of people to jump right in creating libraries and thus extending its own ecosystem.
- curiouslearn 12y agoSomething like Julia's PyCall package that allows calling arbitrary Python packages from Julia would also be great.
- chrisheller 12y agoNimBorg is what you're looking for, https://github.com/micklat/NimBorg https://github.com/micklat/NimBorg
- namuol 12y agoI perked up as soon as I read this: # Table created at compile time const crc32table = createCRCTable()
- CyberShadow 12y agoThis is not an unique feature today, you can do the same in D and Rust and even C++14, I think.
- namuol 12y ago"Hey Nim, 2014 called... they want their language features back." I jest. But seriously, D, Rust, and C++14 are about as familiar to me as Nim.
- CyberShadow 12y agoTo be fair, D has had it since 2007 :)
- Symmetry 12y agoRust is planning to add that eventually, but in the meantime: fn foo(n: i32) -> i32 { n * 2 } const y: i32 = foo(3); error: function calls in constants are limited to struct and enum constructors [E0015]
- pcwalton 12y agoYou can do it with a compiler plugin; I suspect that's what the parent comment was referring to. Admittedly compiler plugins are pretty experimental at this time.
- CyberShadow 12y agoSorry about that. I haven't tried this myself, I was told by a Rust user that its CTFE was on par with D's. I guess he was mistaken.
- egeozcan 12y agoI keep coming back to it, and I really like it but wouldn't it be great if it had interfaces? I really want to restrict the generic type but there seems to be no way other than using templates[1]. [1]: https://github.com/Araq/Nim/blob/master/lib/pure/collections/lists.nim#L109 https://github.com/Araq/Nim/blob/master/lib/pure/collections...
- def- 12y agoUser defined type classes can be used for this, but they're still experimental: http://nim-lang.org/manual.html#user-defined-type-classes http://nim-lang.org/manual.html#user-defined-type-classes
- egeozcan 12y agoI can't believe how I missed that. Maybe this is added recently? Anyway, thank you very much!
- CyberShadow 12y agoNim has some good ideas but I can't get over the syntax: - Significant whitespace, but tabs are forbidden - No block comments, save for `discard """ ... """` - Identifiers are case and underscore-insensitive (FOO_BAR === fooBar === fo_ob_ar)
- def- 12y ago> - Significant whitespace, but tabs are forbidden Here's the reasoning: https://github.com/Araq/Nim/wiki/Whitespace-FAQ#tabs-vs-spaces https://github.com/Araq/Nim/wiki/Whitespace-FAQ#tabs-vs-spac... If you still want tabs you can add this at the top of your files and they work: #! replace("\t", " ") > - Identifiers are case and underscore-insensitive (FOO_BAR === fooBar === fo_ob_ar) This changed recently, now the first letter is considered case sensitive: http://nim-lang.org/manual.html#identifier-equality http://nim-lang.org/manual.html#identifier-equality
- CyberShadow 12y ago> Here's the reasoning: https://github.com/Araq/Nim/wiki/Whitespace-FAQ#tabs-vs-spac.. https://github.com/Araq/Nim/wiki/Whitespace-FAQ#tabs-vs-spac.... Honestly, there are less drastic solutions to these problems. Some languages (forgot which) simply forbid mixing tabs and spaces when the tab size makes the code ambiguous. And their C example will generate an "ambiguous else" warning in D, which you can disambiguate by adding braces.
- dom96 12y ago> - No block comments, save for `discard """ ... """` I believe a different syntax for those will be added soon: https://github.com/Araq/Nim/issues/1535 https://github.com/Araq/Nim/issues/1535
- filwit 12y agoNot that it's even really needed... Just select the section of text and use your IDE's shortcuts to comment it out (which now works fine in any IDE due to comments no longer being part of the AST)
- Roboprog 12y agoIs there a "ctags / etags" utility for nim yet?
- def- 12y agoThat's something nim-idetools can do once it works properly: http://nim-lang.org/idetools.html http://nim-lang.org/idetools.html
- towelguy 12y ago> Nim libraries are statically compiled into our binary as well. Does that mean one can not use GPL libraries in non-GPL programs? With other languages you can get around that by linking dinamically.
- pavlov 12y agoActually that only applies to LGPL libraries -- pure GPL doesn't allow dynamic linking, even. (That's the most common interpretation anyway, and the reason why LGPL exists.)
- xtrumanx 12y ago> That means you end up with a single binary that depends solely on the standard C library, which we can take for granted on any operating system we're interested in. What exactly does that mean? Does the end-user of my binaries require a C compiler? Which operating systems are "we" interested in. I'm interested in Windows and specifically Windows CE.
- sanxiyn 12y agoNo, binaries do not require a C compiler. Yes, Windows and Windows CE are included.
- def- 12y agoThat means if programs written in C work on your OS, so do the ones in Nim.
- xtrumanx 12y agoSorry if this is a silly question but I've always thought of C as generating machine code and it had compilers available in any imaginable platform besides perhaps really niche stuff. Were my assumptions accurate?
- geoelectric 12y agoSimplified, but yeah. It generates intermediate object code, which is transformed to machine code. And as you say, pretty much every platform in existence has a C compiler targeting it. In many cases, you use what's a called a cross-compiler, which lets you generate code for, say, Arduino using tools run on, say, Linux. But one way or the other there'll be a way to compile for it. Net result is that as long as the code isn't doing something that is specific to the platform (memory layout assumptions, asm blocks, Windows API, etc.) the same C code will run on many different platforms. You'll have to recompile it for each one, but you won't have to change the source (much). If I understand correctly, Nim ultimately generates C source (among other options) which then goes through the above process. So it has the same level of portability.
- 12y ago
- joelthelion 12y agoJust add autocompletion and syntax checking for the major editors and people will start adopting it.
- def- 12y agoThat's on its way!
- codexon 12y agoDoesn't nim already have autocomplete?
- girvo 12y agoBuilt into the Nim compiler, yeah, it has a `idetools` feature that makes integrating it into an IDE far simpler. I've been playing around lately with getting it into Textadept, now that Textadept has a better "call some particular binary and get input and output from it" story.
- towelguy 12y agoI wonder if it can generate bindings for Python like Vala does[0]? That would make it even more interesting for Python developers. [0] https://github.com/antono/vala-object https://github.com/antono/vala-object
- chrisheller 12y agoI haven't looked closely at the Vala stuff that you mentioned, but it is very straightforward to generate shared libraries in Nim with exported functions that you can access via ctypes. That's not quite the same as generating a python module that you can directly import, but it gets the job done. You might also be interested in NimBorg, https://github.com/micklat/NimBorg https://github.com/micklat/NimBorg , which supports embedding Python or Lua in a Nim program.
- jwiley 12y agoCan someone point me to an explanation of "Nim is the only language that leverages automated proof technology to perform a disjoint check for your parallel code"? This is mentioned prominently on the main page...but scanning the docs, the FAQ, Dr. Dobbs, and Googling 'nim disjoint' didnt lead me to a detailed explanation.
- pcwalton 12y agoIt doesn't seem like an accurate claim, as Rust also has the ability to reason about uniqueness of data. Rust uses a type system to do it—which, via Curry-Howard, qualifies as "automated proof technology" :) It looks like Nim has some ability to reason about arithmetic identities natively, which is neat. In practice Rust uses iterators to encode the same sorts of common patterns in the type system.
- marvy 12y agoWell, it will be hard to find a proof for it being the "only" language to do so, since as one of the commenters mentioned there is indeed at least one other. But http://nim-lang.org/manual.html#parallel-spawn http://nim-lang.org/manual.html#parallel-spawn seems to discuss it a bit. Or did you want more details? If so, what kind? Actually I don't know anything about Nim anyway, so whatever your question is I can't answer it.
- Araq 12y agoWell I did my homework. When you find another language that does it in a somewhat similar fashion, I'll happily change the website. ;-) I didn't think Rust counts, but since it's constantly changing, I will have a fresh look at it.
- marvy 12y agoI did not do my homework. I know neither Rust nor Nim. So I'm inclined to take your word for it :)
- def- 12y agoThis is all I found: http://nim-lang.org/manual.html#parallel-statement http://nim-lang.org/manual.html#parallel-statement
- malkia 12y agoI'm assuming "staticExec" is not sandboxed in any way... It's one thing to make your compile stuck it's head while doing #include "aux" in windows, but completely different to treat source code as "shell"-script. (I see the point, and it's a great feature, but with too much power).
- monono 12y agoSure, just don't use it then.
- honhon 12y agoI played around with Nim and it has huge potential. It is early days and I would like to thank the creators of the language. A decent IDE is the only issue for me. I tried all the IDE options and it was stark. The idetools didn't work for me and the unit tests failed on Ubuntu 14.04. At the moment small projects and libraries should be fine but the lack of IDE would be an issue for bigger projects.