11 ms·
Question (genuine, not trolling): what's the use-case for Nim regarding other languages? What are its pros/cons?
by nfrankel 7y ago
Question (genuine, not trolling): what's the use-case for Nim regarding other languages? What are its pros/cons?
- 19ylram49 7y agoThose are valid questions when evaluating an unknown technology. How could anyone consider this trolling? Not to digress but have we become too sensitive?
- ptx 7y agoIt all depends on the tone of the question, which is hard to discern in writing, so the clarification is helpful. Edit: Yes, those are very valid and reasonable questions. Clarifying that it's not meant as trolling is also valid and reasonable, because writing is easily misunderstood in exactly that way - which is the reason smileys were invented. (And, to be clear, I'm not accusing anyone of missing smileys or of trolling. I am trying to express my agreement with both parent and grandparent.)
- markdog12 7y agoAsking a question in plain English like this shouldn't require further clarification.
- nimmer 7y agoSometime people troll by sealioning: http://wondermark.com/c/2014-09-19-1062sea.png http://wondermark.com/c/2014-09-19-1062sea.png (I'm not accusing the granparent post)
- anchpop 7y agoI've seen that comic before but have no idea what it's trying to express, could you explain? Is it just when you repeatedly pester someone with questions to annoy them?
- simplify 7y agoUnfortunately, asking questions on the internet is often seen as "opposing" or "arguing against" the thing you're asking about. So many qualify their statements to avoid this sort of misreading.
- markdog12 7y agoWhich just makes things worse. Having to qualify everything by default is a whole lot of foolishness.
- nfrankel 7y agoCommunication by writing is harder because you miss facial expressions. Because of this, a lot of it is subject to interpretation on the part of the reader. The tone can be inferred from a lengthy piece, but not so much from a small paragraph. So, in order to avoid bias on the reader part, I preferred to explicitly tell it was not trolling.
- treeform 7y agoTo me Nim is a faster python that prevents typos. It can also compile to javascript. I used it where I would use python - backend of web apps. But now instead running a cluster of servers I can just run 1 because nim is fast. I also used to write frontend in CoffeeScript, but switched to nim because I can share code between backend and frontend. I don't have typos. I don't inherit any JS or OOP legacy like TypeScript.
- steve_adams_86 7y ago> faster python that prevents typos This was sort of my use-case and experience as well. I also find it can do what I needed JavaScript-based CLI tools to do with less dependencies/ecosystem bloat, and the resulting code is a lot nicer to work with. People have told me that's because I was using JS wrong, but I felt like Nim was such a huge step up for my use cases. It's also just a pleasure to learn something new occasionally.
- pier25 7y agoDo you use any JS libraries in the front end?
- mumblemumble 7y agoAt first blush, it's easy to describe Nim as C-flavored Python, but I'm not sure that quite captures it. The syntax is similar, but that's about where the similarities end - Python is deeply, fundamentally a dynamic language, and Nim one of the more firmly statically typed non-functional languages out there. You could also describe it as being competitive with Rust, but with more compromises for the sake of developer ergonomics. Garbage collection, for example. For my part, I'm finding it attractive as a potential Java-killer. It isn't write-once-run-everywhere, but, now that x86 and Linux have eaten the world, that's not quite such a compelling feature anymore. And Nim smooths things over a bit by making cross compiling dead easy. In return, I get better type safety, better performance, a much better C FFI, and less verbose, easier-to-understand code.
- stakhanov 7y agoI disagree in quite a few respects. I think there's not much merit in discussing "C-flavored Python" as a description of nim, as that description seems just wrong. Aside from significant whitespace, I don't find that many similarities with Python syntax. Describing Nim as non-functional is misleading. Nim does have functional constructs and is a mixed-paradigm language involving both procedural and functional elements, just like Python. "Firmly statically typed" is misleading. It's actually strongly-typed with great capabilities around type-inference so that, at times, you start to forget that it's typed in the first place and gives you a similar feel to a dynamically-typed language like Python. Nim can run with garbage collection disabled. As a matter of fact, I seem to recall that the authors postulated that as a basic requirement that the language should be able to run in a low-level systems programming mode with garbage collection disabled (where it would be able to compete with Rust), and in a more high-level mode where it would rather compete on developer ergonomics/productivity. I find Java-killer a potentially misleading analogy. I do think that it captures the kind of platform-independence that matters nowadays. And that is no longer Intel vs Sparc and Windows versus Linux, but rather the native ecosystem versus the JavaScript ecosystem.
- PMunch 7y agoNot agreeing or disagreeing with either of you just wanted to add some details to the garbage collector thing. Nims GC is able to either be controlled in terms of when and how long it runs, and it can be completely disabled in favour of manual memory management. In fact people have gotten it to run on really low-powered microcontrollers like the Attiny85, as well of course as various Arduino boards. The benefit of Nim in these systems is that since it compiles and has such a rich macro system your are able to write abstractions that the compiler will turn into highly efficient code. So you can still write business logic level readable and maintainable code, while the compiler spits out super-optimised versions. This of course requires you to first write these macros, but often times a little goes a long way.
- 13415 7y agoIt's as easy as Python and as fast as C. That was my take when I looked at it and bought the book last year.
- 19ylram49 7y ago> as fast as C I mean, it actually is C, since the code is transpiled to C.
- gjm11 7y agoThe fact that it uses C as a compilation target doesn't have much to do with whether it's as fast as C in practice. It's easy to imagine a compiler that generates C but generates terrible C that runs really slowly. (E.g., imagine it goes via some sort of stack-machine intermediate representation, and variables in the source language turn into things like stack[25] in the compiled code.) Or consider: Every native-compiled language ends up as machine code, which is equivalent to assembly language, but for most (perhaps all) it would be grossly misleading to say "as fast as assembler".
- 19ylram49 7y agoI’m not sure that I understand your argument. If the code from which the resulting machine code is compiled is C, then it’s objectively “as fast as C” … because, at the end of the day, it actually is C. Being “as fast as C” means that your resulting program will perform as fast as a C compiler [worth its salt] can get you. Your comparison to machine code (or human readable assembly code) is less useful in that such a statement means very little until one knows how said machine code is being produced (e.g., manually, from a IR, etc.).
- detaro 7y ago"As fast as C" would commonly be interpreted as "a program written in it will be as fast as a well-written C equivalent", not as "there is a C program with the same performance characteristics". That a language is compiled to C does not mean that its compiler is going to be able to produce a C program that's as good as a that well-written C equivalent. (A relatively obvious example would be a compiler that introduces a heavy runtime, and doesn't give the C compiler enough information for it to get rid of the runtime) It's the same with assembly code: that a compiler produces assembly does not mean the resulting program is fast.
- nepeckman 7y agoNim occupies an interesting place between Rust and Go. It has an easier learning curve than Rust. I picked up the basics in a weekend, and some of the more advanced functionality over a month. The optional GC is ideal for the application space, and I also don't find myself fighting the compiler very frequently. When compared to Go, Nim provides a lot more functionality. Object variants, a working implementation of generics, not to mention a great macro system.
- danielecook 7y agoI stumbled onto nim because a sequencing-data (DNA/RNA/etc) library was written for it (https://github.com/brentp/hts-nim https://github.com/brentp/hts-nim). In addition to Go, it's been a great way to learn a compiled language. It's fast, easy to use, and has a friendly community.
- vasili111 7y agoHow good is nim performance with sequencing-data in comparision with other programming languages you used for it before?
- danielecook 7y agoI have only used python (check out cyvcf2 by brentp!), R, and bash previously - so nothing else really compiled (its faster than these in general). But my guess is that you will have an easier time writing nim than the alternatives, and after that it is easy to optimize once you have basic functionality.
- TylerE 7y agoNim performance is really really good. Like, maybe C - 5%. Comparable with stuff like Rust or D... way way faster than Go or anything interpreted.
- neverartful 7y agoI think it depends on the nature of the code. For a side project of mine, I recently re-wrote the same code in a dozen or so languages. The application reads input data from text file and does a bunch of conversions to integers and floats (atoi and atof). It then runs through an algorithm that does calculations and identifies proper actions. Finally, it writes the output data as formatted text file. Regardless of implementation, it runs quick. Sorry I can't provide more details on nature of the code (it has IP that belongs to another person). Here are the top 10 best execution times (all run on same hardware). Times obtained by 'time' utility (e.g., "time ./run.sh"). Some of these were run on Ubuntu 16.04 and a few were run on FreeBSD 11.2. Where the compiler has optimization flags, I used it. 1. C++ 0.04 (gcc version 5.4.0) 2. Rust 0.11 (version 1.37.0) 3. Go 0.13 (version 1.12.7) 4. D 0.16 (tied with Pascal) (DMD64 D Compiler v2.073.2-devel) 5. Pascal 0.16 (tied with D) (fpc 3.0.2) 6. C# 0.25 (mono 4.8.1) 7. Nim 0.50 (1.0.0) 8. Kotlin 0.81 (Kotlin version 1.3.50-release-112, JRE 1.8.0_222) 9. Java 0.95 (openjdk version "1.8.0_131") 10. Scala 1.79 (version 2.12.2, running on 1.8 openjdk)
- danielecook 7y agoI've used it to develop command-line based utilities. The binaries tend to be small and fast.
- asdf21 7y agoAre any of these open source? Would love to check them out.
- danielecook 7y agoThese are both works in progress! But here is the first one for working with sequencing data: https://github.com/danielecook/seq-collection https://github.com/danielecook/seq-collection And the second: https://github.com/danielecook/tut https://github.com/danielecook/tut The second one has a really useful utility called "stack" that you can use to concatenate datasets where one might lack some columns or the columns come in a different order. It glues it all together and has an option to include the filename. It's useful for data analysis. Both of these lack 'polish' at this point but a few of the subcommands work quite well.
- gtycomb 7y agoWhen I started an enterprise data project with a small team where Python was the familar workhorse we stopped for moment initially to think of ways to improve performance. Cython was the familiar route with Python but we started building small prototyes in Rust, Go, and Nim. Beyond the basics our progress slowed down with Rust and Go (yes, I know Go is very easy for some) but Nim allowed us to put together a fully fairly complex application in short time. Just one book, 'Nim in Action', gave us all the ropes, every example in it worked (thanks Dominic), and some of our key integrations such as Postgresl Client drivers, built-in web UI (Jester) framework, Json processin, Nim's build/packaging support, generics, fast static typechecking, etc were exceptionally robust (for this young a language) and worked in an intutive way for us ... we reached production rather smoothly.
- pdimitar 7y agoI'm curious why did your progress with Rust stalled and at which point? I’m starting to learn it and so far I haven’t noticed any productivity blockers.
- gameswithgo 7y agojust keep at it, eventually you run into data structures hard to represent with a borrow checker and it will slow you down, at least at first
- gtycomb 7y agoI heartily wish that you continue learning Rust, another significant contribution to open source languages. What has been already commented, things such as borrow/checker are humps you work through and it will work out for you eventually. The other challenges are some of your enterprise 3rd party integrations with the outside world, some of which may again demand your time if they are still in beta, etc. Also, the organization has no desire to invest in training or experimenting. The project is funded by the "business" and they want to see a business result in return for their money ... so you basically you sneak in a bit of time as you try/test something new. Nim won out by somehow getting a team with python expertise learn and deploy their product fast enough.
- mratsim 7y agoI'm from Status, Nim's main sponsor and a blockchain company that is doing Ethereum 2.0 research and implementation in Nim. Nim had the following appeal for us: - Ethereum research is done in Python, we actually started our code with a tool called py2nim to convert a 50k lines Python codebase to Nim in less than a month (and remove cruft for 3 months but that's another story). - Nim allows us to use a single language for research and production: the Python syntax, and the fast compilation speed are very helpful. In particular researchers found the Nim codebase easy to debug as the overhead vs the Python spec was quite low (and the Python spec is using types with mypy) - Nim has a easy C FFI and is one of the rare languages that can directly use C++ libraries, including header-only template heavy libraries. - Nim allows tight control over memory allocation, stack vs heap objects, has support for Android and iOS and very low-memory devices as well. - Nim also can be very high-level - Nim is as fast as C and can resort to inline C, inline C++ or inline assembly when needed. (inline javascript or Objective C are possible as well) - You can produce WASM code via clang, emscripten, binaryen, there is even a Nes emulator demo from 2015 running in Nim compiled to WASM here: https://hookrace.net/nimes/ https://hookrace.net/nimes/ - Nim has a strong type-system, including generics and type-level integers, boolean and enums. - Nim has probably the best compile-time capabilities of all languages. I'm writing a deep-learning compiler in Nim macros. Someone wrote a Cuda code generator in Nim macros, and the code generation is extremely nice to write a VM, an emulator or any kind of assemblers as you don't need to use an intermediate step to generate your opcode tables or generate your functions from that table. Now on a personal note, I use Nim to write a deep learning framework similar to PyTorch or Tensorflow. I think it's the best language to solve the 2-language problem, i.e. write research in Python, R or Matlab and production in C, C++ or Fortran. The operator overloading or even operator creation is very useful. The macros allow me to have a slicing syntax similar to Numpy, something impossible in C++. Compilation speed is very nice as a developer, I don't know how people deal with waiting for C++ CI. I reimplemented a matrix multiplication with performance similar to handwritten assembly BLAS from OpenBLAS and MKL in pure Nim so I'm not worried about performance as well. Now I'm onto refactoring the backend with a proper compiler (similar to Halide but since it will be macro-based, there won't be the 2-stage compilation issue)
- otabdeveloper2 7y ago
- orthoxerox 7y agoIt occupies more or less the same space as Go: it produces fast standalone binaries with garbage collection. However, unlike Go, it isn't shy to give more features to the programmer to play with. The cons are its lack of enterprise backing, its smaller community and its syntax, if you don't like either Pascal or Python.
- nimmer 7y agoNo: you can create system libraries in Nim, unlike Go. You can also entirely disable the GC or replace implementation. Nim can run without OS and on microcontrollers.
- _0ffh 7y agoFor me, personally, the biggest points for Nim are: - "Transpiled" to C, with some options regarding runtime library, which means you can target any uController out there - Good metaprogramming support - Static and _strong_ typing - Consequently, precise type aware function dispatch - Type inference - Good generics Also, more stuff like covariants and contravariants and... maybe you just have a look-see? ;-)
- nfrankel 7y agoI'm already quite invested in Kotlin, and having a look at Elixir... on top of my regular work. Time is a limiting factor :-)
- egeozcan 7y agoThere are "concepts" which are like generics but still experimental. Are there any other generic programming facilities in nim? https://nim-lang.org/docs/manual_experimental.html#concepts https://nim-lang.org/docs/manual_experimental.html#concepts
- narimiran 7y ago> Are there any other generic programming facilities in nim? https://nim-lang.org/docs/manual.html#generics https://nim-lang.org/docs/manual.html#generics
- egeozcan 7y agoWhat I wanted to write was something like type restricted generics, apparently I ended my comment prematurely. Without concepts (interfaces), I find it hard to call this system "good generics" but there might be something I'm missing.