13 ms·
Learning Programming with Nim
- PMunch 8y agoI've been meaning to try this tutorial out on some non-programming friends of mine. But time is unfortunately a limited resource, so I haven't gotten around to it. I helped proof read the texts and clear up some stuff, so if you have any questions about it feel free to ask and I'll try to answer as much as I can! But it hasn't been "battle tested" yet and it might be updated should we find things people struggle with, both with Nim and programming in general.
- _bxg1 8y agoI used to get excited about new-language posts on here, but I've gotten weary of them over time. So many are just slight variations on standard syntaxes that meet their creator's preferences. It's rare to see anything that's radical, and therefore truly interesting.
- LyndsySimon 8y agoI see Nim as inhabiting an interesting space between Lisp and Python/Ruby/Perl. I wouldn't say Nim is "radical", but it is interesting in that it combines ideas in a way that I've not seen in other languages. Whether or not it really takes off, it's a good thing that it's around - if nothing else, it's a slightly easier way for devs who work primarily in higher-level languages like Python and Ruby to encounter concepts they might not otherwise encounter, like macros and a complex type system.
- a012 8y agoCan you share some works one can do with Nim?
- jblindsay 8y agoI used Nim a little while back to write a small CLI program that performs a feature-preserving smoothing of digital terrain data (see https://github.com/jblindsay/fp_denoise https://github.com/jblindsay/fp_denoise). I could have used, and have used, several of languages for this type of application. But I was interested in learning Nim and getting a feel for how well it lends itself to spatial analysis. I was quite pleased with the experience overall. The language feels a lot like a high-level language with the speed of a systems language. The one thing that I didn't find particularly easy was concurrency. I still haven't managed to figure that out but that is more a comment on my limitations than the language. Nonetheless, I can certainly see Nim taking off for data science once it hits v1.0.
- PMunch 8y agoNot 100% sure what you mean by works, but Nim has been used to create various things. For one the entire Nim forum: https://forum.nim-lang.org/ https://forum.nim-lang.org/ is written in Nim (both back-end and front-end), the game "Reel Valley" has been written in Nim, there is a company doing Ethereum blockchain using Nim: https://status.im/ https://status.im/, and many more.
- a012 8y agoThat's impressive. I'm curious whether I can use Nim in sysadmin job.
- kaushalmodi 8y agoI am dabbling in Nim, and plan to replace bash/Python scripts with Nim. So far it looks really promising! Few projects: nbuild[1], ntangle[2]. I wouldn't say that these are exemplary projects.. but they just show that Nim can replace bash/Python for command line utilities. [1]: https://github.com/kaushalmodi/nbuild/ https://github.com/kaushalmodi/nbuild/ [2]: https://github.com/kaushalmodi/ntangle/ https://github.com/kaushalmodi/ntangle/
- sigzero 8y agoI'd say "it depends". If I was a solo sysadmin or a small team, I would probably use it. Big teams are harder to get "buy in" for a new language.
- gtrs 8y agoTotally feasible, I ported Python code to Nim and it was super easy and I got a huge performance boost. If performance isn't a big deal, the other thing I've noticed is that compilation guarantees a much higher quality of code compared to interpretation. At least compared to Python, I have been hit by bad code which didn't get caught because there was no test for it. I've not faced that with Nim yet. No doubt you can still have issues but it's one less thing to worry about.
- kungtotte 8y ago
- PMunch 8y agoThis tutorial obviously only scratches the surface of what is possible in Nim. If you want to dig deeper I recommend reading through the learnxinyminutes entry, along with maybe https://xmonader.github.io/nimdays https://xmonader.github.io/nimdays to see some examples. Then of course the official tutorials. Or if you just want to dig into the crazy stuff to see what is possible https://hookrace.net/blog/introduction-to-metaprogramming-in-nim/ https://hookrace.net/blog/introduction-to-metaprogramming-in...
- drcongo 8y agoNim isn't a new language, it's been around a while.
- ofrzeta 8y agoGiven "the compiler is in development and some important features are still missing" (quote from the FAQ) it would surely qualify as new.
- TylerE 8y agoIt was first posted to HN in 2013. https://news.ycombinator.com/item?id=6820474 https://news.ycombinator.com/item?id=6820474
- reacharavindh 8y agoThere's something about not hitting 1.0. It instills doubt on adoption that things will change in a breaking way soon, and that you're going to need to rewrite your stuff in potentially non-trivial way. I liked playing with Nim in spare time. But, I don't think I'll use it for anything I care about to maintain for a long time.
- gtrs 8y agoEvery language has faced challenges with change, nothing specific to Nim. And 1.0 is a distraction, if the language version has all the features you want, you can use it as long as you want. The code is also open and an unbearable bug can be easily backported. If you do want the new cooler features, then ya, you may need to port your code but that's the case with any compiler update - you need to run a full regression at the very least.
- kjeetgill 8y ago1.0 _may be_ a distraction but I think it's a fair one. It's a common enough convention that pre-1.0 versions are the developer's way of saying, "please please please don't treat this as ready and production quality. We're still figuring some things out and haven't settled on some key choices." If that's not what the developers are trying to communicate with a pre-1.0 version I do wonder what they're gating 1.0 on. What needs finalization? Documentation?
- simias 8y agoNim is definitively niche but it's not really new, Wikipedia tells me that it's 10 years old (older than Rust [2010] or Go [2009] for instance). It just never got enough traction to really find its place in the ecosystem.
- dom96 8y ago> It just never got enough traction to really find its place in the ecosystem. Probably a bigger factor is that Nim doesn't have a well-known organisation such as Google/Mozilla behind it.
- jamiek88 8y agoThat is the clearest, most succinct explanation of variables, types and mutability I’ve ever read. I’m not deep into this yet but I dig the ‘voice’ being used. It’s difficult to break ‘obvious’ things down to those without background while staying concise.
- PMunch 8y agoYeah Narimiran did a good job of breaking it down. I prompted him to add details here and there, but he was quick to rein me in when I wanted to dig too deep.
- narimiran 8y ago> That is the clearest, most succinct explanation of variables, types and mutability I’ve ever read. Thank you very much! It means a lot to see this kind of feedback. > It’s difficult to break ‘obvious’ things down to those without background while staying concise. After writing this tutorial, I can only nod and agree with this statement - it took me much more time than I originally thought it would.
- drcongo 8y agoI really like the look of Nim and would love to see it gain some traction. Just wish I had the time to play with it more.
- sullyj3 8y ago>Nim is a statically typed programming language, meaning that the type of an assignment needs to be declared before using the value. This is not strictly true, in languages with type inference (which are becoming increasingly common)
- PMunch 8y agoNim has type inference as well, but the type still has to be known before we can use a value. From the tutorial: > Nim also has type inference ability — the compiler can automatically detect the type of a name assignment from its value, without explicitly stating the type.
- MaxBarraclough 8y agoWell that's exactly the point. It's statically typed, so of course types have to be known at compile-time, but it can use type inference rather than explicitly expressing type in declarations. Static typing with type inference is still static typing. Vaguely related: many people also confuse 'dynamically typed' and 'untyped', despite that they're not even close.
- jerf 8y agoI've seen that called "type deduction" to distinguish it from "type inference". It's a much simpler feature. Arguably it's more of a convenience, whereas "type inference" tends to have real effects on the idiomatic way to design solutions in the language. A nice one though; I wouldn't care to go back to a language where I'm double-specifying types all the time like that.
- gtycomb 8y ago'Nim in Action' from Manning is well written and solid, I found recently. Nim is surprisingly robust, I'd mention. The book has a chapter on using Jester for a web framework. This is adequate for some things. If anyone is at the point of using Nim as a server for React clients, doing something beyond a hello world (interacting with forms), I would love some pointers. I haven't yet thought through what may be done with Nim's capability to compile Nim code to javascript in situations like this.
- dom96 8y agoYou should check out the newly redesigned NimForum[1][2]. It is written 100% in Nim using Jester and Karax (a Nim framework similar to React). Karax itself has a number of examples in its repo[3], we're also always happy to help you out if you want to pop into IRC or post questions on the forum :) P.S. Thank you for the kind words about Nim in Action! 1 - https://forum.nim-lang.org/ https://forum.nim-lang.org/ 2 - https://github.com/nim-lang/nimforum https://github.com/nim-lang/nimforum 3 - https://github.com/pragmagic/karax/tree/master/examples https://github.com/pragmagic/karax/tree/master/examples
- dual_basis 8y agoDoes Nim in Action still apply to Nim 0.18?
- dom96 8y agoIt does. It's our aim to keep all the examples working for the 1.0 release (some deprecation warnings may appear though).
- curioussavage 8y agoThere is already a nim react package. There is also the web framework karax you could use instead. Zero docs for that though
- Tharkun 8y agoSignificant whitespace and case- and underscore insensitivity. That's pushing too many of my buttons for one language. That being said, this is a very well written tutorial. Might be a nice format to use in other basic language tutorials.
- ivoras 8y agoFor example, what do you think of Go? It's case-sensitive and whitespace-insensitive, but almost everyone formats their code with gofmt, which next to eliminates "creativity" with whitespace, letter case and braces (but makes the code uniform and readable across authors).
- deleted 8y ago[deleted]
- gameswithgo 8y agoit isn't entirely case insensitive, just to clarify.
- jessaustin 8y agoIf anything this clarification makes Nim seem less appealing. I hope Nim has a very good reason to make its case sensitivity "case-dependent", because it sounds quite confusing...
- dom96 8y agoThe first character of an identifier is case sensitive and by convention used to determine whether the identifier is a type or not. As for style insensitivity: it allows you to keep your code base consistent. Ever had to use a library that used snake_case in your own camelCase codebase? Well, with Nim you can just use camelCase everywhere.
- kungtotte 8y agoI also don't see the issue with it. You can have a uniform style in your project, regardless of dependencies you use. And what's the flipside? People want to use more than one identifier named the same thing only with different case? Is that really desirable? I posit that if you have a codebase that breaks if fooBar and foobar refer to the same variable, it's already broken!
- MaxBarraclough 8y agoAnyone here qualified to compare Nim to the D programming language?
- jblindsay 8y agoThere have been insightful comparisons in both communities: Nim: https://forum.nim-lang.org/t/1779 https://forum.nim-lang.org/t/1779 D: https://forum.dlang.org/thread/mailman.1427.1428691340.3111.digitalmars-d@puremagic.com https://forum.dlang.org/thread/mailman.1427.1428691340.3111.... And the following is probably one of the most extensive comparisons of the two languages: https://github.com/timotheecour/D_vs_nim/ https://github.com/timotheecour/D_vs_nim/
- squarefoot 8y agoI'll take the chance of suggesting also Dominik's book (1) both because it's good and because so I can politely ask the publisher next time please do use bigger or darker fonts for code:) The print is perfect, but I'm a glass wearing old fart with some difficulties with thin fonts when they're not dark enough. As an example, I can read perfectly HN fonts though they appear even smaller than the book ones. The white paper background could also be a factor though, I in fact like a lot more non 100% white backgrounds. (1) https://www.manning.com/books/nim-in-action https://www.manning.com/books/nim-in-action
- dom96 8y ago> I'll take the chance of suggesting also Dominik's book (1) both because it's good Thank you :) > I can politely ask the publisher next time please do use bigger or darker fonts for code I think it's unlikely the publisher will see your message here. You might have better luck Tweeting at them or emailing them.
- camelCaseOfBeer 8y agoI've been looking into teaching a programming class to kids in Juvinile detention, who are likely starting at ground zero. I feel like this is a great first lesson to precede what I've prepared! I don't think I've ever seen a cleaner explanation of variables and static typing.
- dual_basis 8y agoI've got a systems level project I want to play around with, however GC is not a deal breaker for me. The languages I've been considering are Rust, Nim, Crystal, and Zig. I've started writing it in Rust but the syntax is unnecessarily noisy for my taste and there are too many times I have to do similar things in a slightly different syntactic way due to some inherent idiosyncrasies, which makes the code much harder to read. In addition, it seems like there are often too many ways to do the same thing, which increases the surface area of the language. I like Nim syntax the best, and Crystal and Zim are tied for second. I don't mind a small library / ecosystem. The main things I'm interested in are: - I want to write once and run on Windows / Linux / Mac. (I'm not writing a GUI.) - Concurrency and async capabilities - Safety guarantees (both types and threads) - Speed I'd be interested in people's recommendations, or links to comparisons between these languages.
- audunw 8y agoIf you don't mind GC I would go for Nim (although I don't have much experience with Rust or Crystal). I've always enjoyed programming in Nim when I've had the chance. It doesn't fit all kinds of projects, but it sounds like it'll fit yours. Zig is too young to build anything significant with it. But to me, it's the most promising language for embedded and low-level development, and where you need good control of memory management. I've played around with it a lot recently and looking forward to use it more in the future.
- lilactown 8y agoYou might also consider OCaml. If the syntax offends you, ReasonML might not be a bad option.
- dual_basis 8y agoI used OCaml in a programming languages class and didn't hate the syntax, but I found the tooling relatively clunky compared to modern toolchains (for example, cargo).
- lilactown 8y ago
- narimiran 8y agoAuthor of the tutorial here. I didn't expect that somebody else might post a link to it - it seems I might be too late for the party. If anybody has any questions regarding Nim or suggestions how to make the tutorial better - let me know.
- airstrike 8y agoIf I may be so bold as to comment on form rather than function, I wanted to say I am not particularly fond of the typography / design choices for the tutorial. I know this is dangerously close to bikeshedding territory, but if I may, I wanted to point you to a similar resource that I recall being particularly pleasing to read way back when I was getting started in Python / Django: https://web.archive.org/web/20080730140551/http://www.djangobook.com:80/en/1.0/chapter09/ https://web.archive.org/web/20080730140551/http://www.django... That content has been retired from djangobook.com, and the website's design has followed suit, hence the archive.org link. I suggest also perusing the table of contents and making note of small design hints such as the use of color, whitespace, "Note" callouts, etc. At the very least, I hope you'll find this inspirational if you decide to take a moment to rethink typography, typesetting and the overall design of the website and PDF.
- narimiran 8y ago> I hope you'll find this inspirational if you decide to take a moment to rethink typography, typesetting and the overall design of the website and PDF. Thanks for the feedback! I would very much like to improve the looks of the website and PDF. The current situation is this: I have zero experience with html/css, so I just took some css template and tweaked some values (lots of trial and error) until it looked okayish (There is probably some unneeded stuff in there too). And PDF is created by using the default style of asciidoc-pdf - I guess this can also be customized, but haven't looked into it yet. Having said that, if somebody with more web-experience would like to improve my style.css [0], PRs are welcome. [0] https://github.com/narimiran/nim-basics/blob/master/style.css https://github.com/narimiran/nim-basics/blob/master/style.cs...
- ModernMech 8y ago
- happy-go-lucky 8y ago> Who is this for? > People with minimal previous programming experience > People with some programming experience in other programming languages Both mean the same.
- acehreli 8y agoBecause this is about learning programming with a language, here is a shameless plug for learning with D: http://ddili.org/ders/d.en/index.html http://ddili.org/ders/d.en/index.html
- j1elo 8y agoLooks like this time Nim is only receiving good comments and praises! It is very interesting and I've been following the language from some time already, since when it was still named "Nimrod". In the past I already mentally classified it as a not very well defined language, with a not very well done feature set analysis. A comment in HN described it in a way that seems to fit: (...) a hodgepodge of stuff thrown together, a lack of language design with a surplus of features (from this thread: https://news.ycombinator.com/item?id=11960814 https://news.ycombinator.com/item?id=11960814) It's not the only time when the language's (arguably) unnecessary breath has been critiziced: from having a suprisingly huge feature set (https://news.ycombinator.com/item?id=13312205 https://news.ycombinator.com/item?id=13312205) to implementing everything but the kitchen (sink) and having a lack of engaged contributers, leading to many bugs, little documentation, and a very messy standard library (https://news.ycombinator.com/item?id=13355579 https://news.ycombinator.com/item?id=13355579). Have those comments (which admittely only represent the personal opinions of their owners) been rendered outdated by now? I'd argue that for an absolute zero-knowledge starting point, Rust would be more valuable to start learning, given that both would have a big (or "huge") surface but very different levels of apparent polish and structural design choices behind them. But of course, it's all a matter of taste.