16 ms·
Nim 0.19
- nepeckman 8y ago> func is now an alias for proc {.noSideEffect.} So excited for this addition! I like to program Nim in a functional lite style, and this is some nice sugar to write functional procedures. Its also nice that the language reserved the function keyword for procedures that are _actually_ functions.
- treeform 8y agoI want to use the func keword more. I think many of my procs can be funcs instead. In my programs i like having a simple imperative middle, but fuctional no side effects edges.
- narimiran 8y ago> So excited for this addition! I've been using it for a while in the devel version (Nim v0.18.1), and it is great — I like it very much and I completely understand your excitement! Before I didn't bother with {.noSideEffect.} pragma, and now with `func` here — my code is much more clear (at least to me ;)), and I can immediately tell which of my procs are 'pure'.
- k__ 8y agoWhat does it do?
- tyingq 8y agoIt does some static enforcement of "no side effects[1]". [1]https://en.m.wikipedia.org/wiki/Side_effect_(computer_science) https://en.m.wikipedia.org/wiki/Side_effect_(computer_scienc...
- Buttons840 8y agoHow? Even Haskell, who makes a big deal out of separating pure vs impure code, can't do it perfectly.
- tyingq 8y agoI don't think they claim they do it perfectly. You can find bugs related to that, false negatives and positives.
- Buttons840 8y agohttps://nim-lang.org/docs/manual.html#pragmas-nosideeffect-pragma https://nim-lang.org/docs/manual.html#pragmas-nosideeffect-p... It looks really impressive.
- emmelaich 8y ago"Haskell is the world’s best imperative programming language"
- gameswithgo 8y agocan someone expound on what this does exactly and how it works? Will the compiler try to statically verify that it is actually pure and error if it can't? Does it unlock optimizations or other features?
- nepeckman 8y agoYes and yes. From the manual: > If none of its parameters have the type var T or ref T or ptr T this means no locations are modified. It is a static error to mark a proc/iterator to have no side effect if the compiler cannot verify this. I'm not sure how many compiler optimizations are possible, but I do know that procs marked with no side effect are automatically considered thread safe.
- e12e 8y agoWhat if your func iamsafe calls the proc imodifyglobals? More generally, can a "func" call a proc and remain a func?
- nepeckman 8y agoI'm not really a Nim expert, but I did a quick test on the scenario you laid out with these results: iamsafe could not call imodifyglobals, but could call a proc with no side effects. I'd guess that a func can call out to any proc that the compiler knows is side effect free, with the compiler erring on the side of caution.
- dom96 8y agoYep, AFAIK the compiler will do its best to infer the effects and most of the time it does a pretty good job.
- PMunch 8y agoNope, it can only call other side-effect free things. Note however if you call a procedure from a function the function will try to see if the proc is actually side effect free, just not marked as such. So you can still call a proc, but only if it could've been a func.
- da02 8y agoNintendo Switch was added as a new platform target. See the compiler user guide for more info.
- steveklabnik 8y agoVery intriguing! I'll have to look into how this works; my understanding is that you can't do this without signing NDAs, and only distributing to people who have also signed NDAs...
- da02 8y agoSigning an NDA is required just to write apps to run on the Switch? What are your thoughts on this practice?
- steveklabnik 8y agoIt’s unfortunate but that’s the reality.
- da02 8y agoThat's messed up. Sony and Nintendo have the opportunity to build something great and useful beyond entertainment, but they always find a way to take a step-backwards in time.
- pjmlp 8y agoiOS, Android and Windows stores are the proof what happens when there isn't an high bar to quality control. The games industry learned from the 1983 crash, hence the access gates.
- jyapayne 8y agoI wrote the implementation of the Nintendo Switch support. It currently uses the publicly available open source library Libnx and Devkitpro. See https://github.com/switchbrew/libnx https://github.com/switchbrew/libnx and my wrapper around that library (it has all functions exposed using nimgen, a C wrapping library, but the Nim-friendly wrapper is a WIP) https://github.com/jyapayne/nim-libnx https://github.com/jyapayne/nim-libnx In order to use this, you must have a homebrew enabled Switch. Google is your friend!
- sephware 8y agoNim is fantastic, I especially like that it takes a pragmatic approach to all its features, so that it doesn't get bogged down in theory but lets you get productive with it right away. One example is that even though it says it's a systems (and application) language, it has GC (ref counting + cycle detection), which means you don't have to worry about memory management and can focus on the core of your application. Honestly I think Nim is comparable to Go, so if you're thinking of adopting Go, look into Nim, you might like what you find.
- OskarS 8y agoThe realtime support for the GC is really fucking cool. In many game-dev situations, you would happily give up a millisecond per frame for GC deterministically instead of the GC occassionally taking 20-40 milliseconds.
- enitihas 8y agoI too was enthusiastic about using Nim, as it is clearly a much superior language to go. However, the ecosystems are not at all comparable. Even without considering the huge amount of 3rd party packages for go, the go stdlib itself is too good and has almost all batteries included. For Nim, if you are going to develop any non trivial program, it is going to be really difficult to find the relevant libraries.
- treeform 8y agoI thought so too about Nim, but then I realized how easy it is to call c libs from nim. There is infinate amount of c and c++ libs out there.
- jhasse 8y agoDoes calling C++ libs work in the latest version of Nim though? I mean real C++ interfaces, not C ones that just happen to use C++ in their implementation.
- 8y ago
- treeform 8y agoI am switching all my work to him now. It's a super fast python with types. The non nil string and sequence in this version are cleaver.
- androidgirl 8y agoI started playing with Nim last weekend, after the article on here about Nim. I absolutely love it! I'm looking for an opportunity to use it at work for something minor, and I have been porting a few of my (small) Rust applications to Nim in my free time. Such a pleasure to work with and so intuitive.
- narimiran 8y ago> I'm looking for an opportunity to use it at work for something minor Recently I've been using Nim at my work as a Python+Numpy replacement for a numerical simulation of multi-body contacts. (Just two hours ago I had a small talk at a conference where I showed the results of it) I'm sure there are lots of opportunities to 'throw in some Nim' wherever you work ;)
- _zachs 8y agoMay I ask what the nature of the Rust apps you're porting is? I'm currently learning Rust and would be interested in knowing why you're moving away from it.
- 3rdAccount 8y agoNot parent post, but to me, Nim is very easy to write coming from Python. For virtually zero effort, I can get near C speeds in a tiny self-contained executable. Rust is probably more mature (more users) but requires me learning a lot of low level concepts. If you already know Python and just want fast code and easy deployment, Nim might be a better choice. Crystal is similar for Ruby users.
- thejvexperience 8y agoI'm feeling old. This is really at the top of a HN thread? Since you self-describe as "coming from Python," you maybe haven't yet really gotten that deep into the internals of computers and what kind of stuff you might wanna do that isn't well supported by higher-level languages. This is especially relevant when we get to talking about performance guarantees, wherein very little can get "guaranteed" about a garbage-collected system, by definition. So while it is a pain to deal with "low-level concepts" like in Rust, it is also well worth it depending on what kind of tech you need to make.
- Kip9000 8y agoIs GRPC available for Nim?
- zinclozenge 8y agoI don't believe so.
- dom96 8y agoSadly no, but sounds like a fun project :)
- Serow225 8y ago:)
- hikarudo 8y agoI'm considering using Nim for an embedded project, because Nim can generate C or C++ code, and a C and C++ compiler is all there is for my target platform (a DSP). I would like to use C++11, but the manufacturer only supports C++03, and will never add support for C++11 because it's a legacy DSP.
- dom96 8y agoSounds like Nim would be perfect for your use case. Happy to help out if you run into any problems.
- hikarudo 8y agoThanks! How would I go about wrapping OpenCV's C++ API?
- dom96 8y agoHere is a C++ wrapper for SFML that I made, you can use it as an example: https://github.com/dom96/nim-in-action-code/tree/master/Chapter8/sfml https://github.com/dom96/nim-in-action-code/tree/master/Chap... You can also try using `c2nim`'s cpp mode.
- rhodysurf 8y agoOh wow. That looks so frictionless, thanks for sharing the example!
- eaurouge 8y agoI bought your book with the hopes that you would include a chapter on embedded programming, but was disappointed to find it barely got a mention in the book. I remember an earlier discussion here where you were considering and it seemed like a real possibility. Unfortunately, I haven't been able to find recent (ideally official) documentation/discussion on embedded programming. Contrast this with Rust where there's a significant focus on embedded bare metal, particularly for Cortex-M MCUs. With the recently announced support from Status, are there any plans to provide more support for embedded bare metal?
- iffycan 8y agoI've really been enjoying using Nim for one-off data processing projects here at work. I'm also excited to see where nimx [1] goes (a cross-platform UI library). [1] https://github.com/yglukhov/nimx https://github.com/yglukhov/nimx
- narimiran 8y agoI'll mention another great library from the same author: https://github.com/yglukhov/nimpy https://github.com/yglukhov/nimpy A library which allows you to connect Python and Nim so you could, for example, use Nim (instead of Cython) for speeding up some parts of your code, compile it, and call it from your Python program.
- sergiotapia 8y agoI'm thinking about rewriting a very popular open source project of mine in a language that can spit out a simple binary people can double click or have it run in a terminal window to serve API requests. Does Nim have true single-binary deploys like Go has? My original project is written in Elixir and even with Distillery it still seems a little convoluted for what I'm trying to deliver to end users. I want a real, download this and run it boom, go to localhost:1234 for some cool stuff.
- kaushalmodi 8y agoIt's certainly possible! You just need to know which compiler to use. For example, I used musl-gcc to compile a static binary that can run on any 64-bit GNU/Linux type OS. See my recent post https://scripter.co/nim-deploying-static-binaries/ https://scripter.co/nim-deploying-static-binaries/. Download and run binary to try: https://github.com/kaushalmodi/hello_musl/releases https://github.com/kaushalmodi/hello_musl/releases (prints just "Hello, world!"). I plan to release similar binary for my ntodo[0] project, that will make API calls to fetch/set tasks in Todoist. [0]: https://github.com/kaushalmodi/ntodo https://github.com/kaushalmodi/ntodo
- dom96 8y agoYes, Nim has this. There is a caveat though, but AFAIK Go has the same problem. Certain Nim modules/packages might wrap a C library. If you use those then your binary will typically depend on a DLL for that C library. With some effort you can statically link against those libraries, but I wouldn't call that easy. This is in particular a problem when you're using regex or SSL, the former depends on PCRE and the latter on OpenSSL/LibreSSl. Go benefits from having native implementations of those written in Go. We also now have a regex engine[1] implemented in Nim but it hasn't made its way into the stdlib yet (that is planned though). But you can use it pretty easily as a package if you want to avoid the dependency on PCRE. 1 - https://github.com/nitely/nim-regex https://github.com/nitely/nim-regex
- FraaJad 8y agoNot exactly what you asked for, but for shipping the same app on multiple platforms, this may prove useful - https://hookrace.net/blog/writing-a-2d-platform-game-in-nim-with-sdl2/ https://hookrace.net/blog/writing-a-2d-platform-game-in-nim-...
- planetis 8y agoI see Nim lately made some cleanup in the macros module. Thats great. Macros now are much more easy to wrap my head around and I have already produced my first usable macro: https://github.com/b3liever/protocoled https://github.com/b3liever/protocoled. Also others are trying to use the new caseStmt macros: https://github.com/alehander42/gara https://github.com/alehander42/gara. Great stuff!
- ospohngellert 8y agoDoes anyone know any good learning resources for this language aside from the tutorial. Just tried jumping in and got weird compile errors when trying to work with lists.
- FraaJad 8y agoThere is a book "Nim in Action" https://www.manning.com/books/nim-in-action https://www.manning.com/books/nim-in-action by @dom96
- dom96 8y agoAuthor here :) I understand that it might suck to be buying a book to learn a language, so just in case you don't want to commit to that there are two chapters of the book which are free. You can find them listed in the link above or here: https://book.picheta.me/ https://book.picheta.me/
- ospohngellert 8y agoThanks so much! Want to get started with it before I decide to buy a book on it, but seems like a great language to program functionally in without all the hurdles :)
- Kihashi 8y agoAlso worth noting that Manning has sales quite frequently.
- dom96 8y agoJoin our IRC/Gitter or our forum, we're always happy to help: https://nim-lang.org/community.html https://nim-lang.org/community.html.
- narimiran 8y agoIt depends on your background. If you would like to go from the very beginning (no or minimal programming experience): https://narimiran.github.io/nim-basics/ https://narimiran.github.io/nim-basics/ (disclamer: I'm the author of that tutorial) If you are more experienced, and you want to explore all the possibilities that Nim provides, check the language manual: https://nim-lang.org/docs/manual.html https://nim-lang.org/docs/manual.html If you need any help with getting started, join Nim channel on IRC/Gitter and ask the questions. The community is very friendly and helpful! (It is one of the main reasons I kept using Nim in my Nim beginnings)
- vvpan 8y agoThere is now an Ethereum 2.0 client being written in nim: https://github.com/status-im/nimbus https://github.com/status-im/nimbus
- chris_mc 8y agoI've been waiting for this for a while! I never could get `develop` to run.
- MR4D 8y agoHas anybody thought to submit some benchmarks to the Benchmarks Game? I know that benchmarks aren't perfect, but would be nice to at least have an idea of how it stacks up against some of the other languages. [0] https://benchmarksgame-team.pages.debian.net/benchmarksgame/ https://benchmarksgame-team.pages.debian.net/benchmarksgame/
- mratsim 8y agoI don't think they accept new languages anymore.
- dom96 8y agoIndeed. They even specifically named Nim in their FAQ[1]: > Why don't you include language X? > Because I know it will take more time than I choose. Been there; done that. > Measurements of "proggit popular" programming language implementations like Crystal and Nim and Julia will quickly attract attention and be the basis of yet another successful website (unlike more Fortran or Ada or Pascal or Lisp). 1 - https://benchmarksgame-team.pages.debian.net/benchmarksgame/play.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
- igouy 8y agoAs-always they choose some and not others.
- def- 8y agohttps://github.com/def-/nim-benchmarksgame https://github.com/def-/nim-benchmarksgame
- igouy 8y agofwiw A couple of those task names are for older tasks which have been replaced by: fannkuch-redux, regex-redux: and there are other changes which don't seem to have been mirrored.
- vesak 8y agoDoes Nim have (or plan to have) (non-)nullable types?
- hathawsh 8y agoPointers in Nim can have the "not nil" annotation. The annotation is checked by the compiler.
- PMunch 8y agoWith version 0.19.0 Nim also moved away from nilable seqs and strings, so they are much safer to use. An empty string and a nil string is now the same, and a nil seq and a seq without elements is the same. Saves you from that one missing nil check that crashes your entire program. If you want the behaviour of nilable seqs and strings you can use the options module.
- uvtc 8y agoNim appears to be quite similar to Haxe, though Haxe compiles to numerous additional targets. Aside from that, and the syntax, what are the main differences between Nim and Haxe?
- lasagnaphil 8y agoI think the one downside of Haxe (which is also is strength) is that it doesn’t only support compiling to C/C++, but to every major language possible (Java, C#, PHP, Javascript), so the language ends up being too complex. You constantly have to think about how the languages features will map to your target language if you care about performance, which can be pretty unintuitive. And the C++ target (hxcpp) is quite heavyweight and takes a lot of time to compile (at least the last time I checked out). Also C interop doesn’t seem that convenient. On the other had Nim only transpiles to C, so the language is simpler and easier to reason about performance. (And it probably has faster compile times). It is also explicitly designed to interop with C, so you can easily use all those C libraries in the wild... But I still have some hope on Haxe, because the main developer is working on Hashlink, which can run Haxe code on a virtual machine but can also transpile it to C for production builds... It seems a more simple and “focused” Haxe target that doesn’t have all the warts of hxcpp... https://hashlink.haxe.org https://hashlink.haxe.org
- isr 8y ago> On the other had Nim only transpiles to C Nim also compiles to javascript too, right?
- dom96 8y agoYep. C/C++/obj c and JS
- uvtc 8y ago> I think the one downside of Haxe (which is also is strength) is that it doesn’t only support compiling to C/C++, but to every major language possible (Java, C#, PHP, Javascript), so the language ends up being too complex. I don't understand --- I would think it's quite the opposite. Implementing too many unique target-language -specific features in Haxe would mean lots more compilation acrobatics to make those features work across every target language, correct? > the main developer is working on Hashlink, which can run Haxe code on a virtual machine but can also transpile it to C for production builds Yes, very excited about HashLink!
- Serow225 8y agoIs there IDE debugging support for Nim yet (language server?). Or a REPL, Online or off? Thanks
- nepeckman 8y agoBoth in progress. Language server: https://github.com/nim-lang/langserver https://github.com/nim-lang/langserver https://github.com/nim-lang/langserver/issues/1 https://github.com/nim-lang/langserver/issues/1 As for a REPL, there is already `nim secret`, but there is work being done to create a better interactive environment. https://github.com/nim-lang/Nim/issues/8927 https://github.com/nim-lang/Nim/issues/8927
- Serow225 8y agoThanks!
- kaushalmodi 8y agoI use Org Babel in Emacs as a "REPL", and an Org Babel package for Nim exists: ob-nim[0], and it's awesome. For folks uninitiated about Org Babel, it allows one to write small code snippets and quickly evaluate the results and have them inserted below. I keep a nim-scratch.org handy to quickly try out new snippets. Unlike traditional REPL's, this approach allows me to keep on saving new snippets and their results too! Here's how it looks: https://i.imgtc.com/FAnay93.png https://i.imgtc.com/FAnay93.png Here's another example: https://i.imgtc.com/xLfiR6p.png https://i.imgtc.com/xLfiR6p.png. The beauty of this approach is that then I can simply export that my blog[1] (you can correlate 1-1 how that screenshot matches with the content on that blog) :). [0]: https://github.com/Lompik/ob-nim https://github.com/Lompik/ob-nim [1]: https://scripter.co/notes/nim/#nim-help https://scripter.co/notes/nim/#nim-help
- Serow225 8y agoThanks.
- arc776 8y agoLanguage server is in construction, but you can use gdb with VSCode quite well within the editor.
- Serow225 8y agoHow is Nim's package manager, given the love for Cargo and churn with golang it seems like a thing people really care about.
- nathancahill 8y agoNimble is quite nice. It's still beta so occasionally rough around the edges (maybe mostly so in the docs).
- mrath 8y agoI have been learning Rust recently. Nim looks interesting, is there a quick comparison page with Rust somewhere? I just skimmed through the doc, and looks like the language is huge. Is it expected to have a big learning curve? also could not find any info on Async and threading is there any documentation around it? And the GC, is it optional or more like compiler determines it using set of rules?
- timClicks 8y agoNim's a great language. Its heritage is Pascal, so that might explain some of the cognitive dissonance you could be experiencing about it.
- ilaksh 8y agoThere are quite a few features but to me you can get pretty far learning somewhat gradually. Threading is in the manual which is linked on the documentation page. Async stuff is documented in modules like https://nim-lang.org/docs/asyncdispatch.html https://nim-lang.org/docs/asyncdispatch.html
- chris_mc 8y agoI found it was easy to write Nim coming from Python and doing a few tutorials I found around the web and some programming puzzles. The advanced features like macros, tempates, generics, etc. are harder to learn, but I haven't needed them yet so far. I did have to dig into the actual library source code several times because the documentation is quite sparse, and for things like async and parallel programming there aren't many examples to pull from at all. However, I find it's way easier to program in Nim with static typing and the applications I write are much faster than Python, even without the crutches of numpy operations, pandas dataframes, and the huge Python ecosystem.
- edflsafoiewq 8y agoIn particular, how does it compare in compile time, binary size, and total build size if those values for Rust are "slow", "large", and "enormous"?
- haarts 8y agoWho is funding the development of Nim?
- dom96 8y agoThis shows who is sponsoring us currently: https://nim-lang.org/sponsors.html https://nim-lang.org/sponsors.html Status has recently become a large sponsor, but over the past years it was all donations from our users (who were and continue to be incredibly generous!)
- haarts 8y agoI'm glad to see that ICO money is put to good use! I'm genuinely excited for the future of Nim. Keep it up!
- h3rald 8y agoGreat news! I have been using Nim almost exclusively for my open source projects for years now, since when it was called Nimrod... It is simply amazing to see how it evolved and improved over time. I love the fact that it runs seamlessly on several different platform, that is so fast and so syntactically expressive and elegant. Way to go guys, Araq, dom, and everyone who made Nim possible! Really glad you are finally getting the momentum and the attention that you deserve. Keep it up!