[HN Gopher] Computer Programming with Nim
       ___________________________________________________________________
        
       Computer Programming with Nim
        
       Author : michaelsbradley
       Score  : 182 points
       Date   : 2022-02-27 11:57 UTC (11 hours ago)
        
 (HTM) web link (ssalewski.de)
 (TXT) w3m dump (ssalewski.de)
        
       | zanellia wrote:
       | Pretty cool. Would love to use Nim for scientific computing, but
       | I am not sure how mature are, e.g., Neo
       | (https://github.com/andreaferretti/neo) and alike. Any positive
       | feedback?
        
       | erwincoumans wrote:
       | At a glance, the writing is very friendly, fun and sincere.
       | Indeed, there is a lot of competition in computer languages, and
       | you need some strong supporters (such as games or corporate
       | sponsorship) to survive.
       | 
       | At the very least, the book looks like a good introduction to
       | computer programming in general (not just Nim).
       | 
       | My introduction long ago was the 'commodore 64 programmer
       | reference guide'. The mix of hardware, graphics, sid sound, BASIC
       | and assembly language was great for the curious, learning by
       | taking things/programs apart (and sometimes put them back
       | together) while small enough to fully grasp.
       | 
       | Then moved from basic to assembly, pascal, c, python, c++ (and
       | cuda). Wouldn't mind trying Nim or Rust next. Reading such nice
       | book makes it inviting.
        
       | brudgers wrote:
       | This is not bad:
       | 
       |  _In some other programming languages like Python or Ruby we can
       | define class methods or static methods which are bound to a class
       | or type and can be called as MyType.myProc. In Nim we can do
       | something similar by use of the typedesc proc parameter type:_
       | 
       | But the boil-the-ocean first chapter, e.g. "what is an
       | algorithm", should fall to the editor's pen. No good book is "for
       | everyone." The first chapter misleads new programmers into the
       | idea that the book is for them while they are beginners.
        
       | jonpalmisc wrote:
       | I'm always hesitant to start projects in less popular languages
       | without knowing if they will stick around, etc. I don't know much
       | about Nim, but I have tons of respect for people who create
       | excellent content like this that helps a language become more
       | popular and mainstream by making it more accessible.
        
         | ushakov wrote:
         | Nim is 14 years old
        
           | WesolyKubeczek wrote:
           | But still pretty much one-man work.
           | 
           | I admit, it's a true work of love.
           | 
           | However, its bus factor is 1. I would love to see some effort
           | to make sure it has a future beyond that.
           | 
           | Humans are volatile.
           | 
           | (What's up with projects maintained by the late Jorg
           | Schilling?)
        
             | auxym wrote:
             | A lot of previous contributors to Nim are currently working
             | on an experimental fork due to disagreements with the
             | development of the official compiler:
             | https://github.com/nim-works/nimskull
        
               | rpdillon wrote:
               | Was totally unaware of this. The Readme:
               | 
               | > For now it's closer to an alternative with most
               | deviations appearing in the standard library, mostly in
               | the form of deleting much of it.
               | 
               | Yikes. I've found that languages with a small standard
               | library have deep dependency trees for imported packages.
               | I hope this is a stepping stone to a different standard
               | library, rather than an end goal in-and-of itself.
        
               | haxscramper wrote:
               | Actually the phrasing in the readme is not correct - I
               | will change it later, but now I want to say that the
               | objective is not deleting "much" of it, but rather
               | cleaning up old and deprecated modules, or providing
               | alternative solutions (for things like os/json that
               | historically were a point of friction).
        
               | nimmer wrote:
               | > A lot of previous contributors
               | 
               | Not really. The fork looks pretty dormant.
        
               | haxscramper wrote:
               | I think better phrasing would indeed be something like
               | "several former core developers" - of course we can't
               | really measure up to the size of the original community,
               | and don't yet have any paid developers (like Araq and
               | narimiran [1] in the mainline - although since the end of
               | September there were not a lot of activity on their part
               | as well - [2] ~30 commits (~23 that are marked
               | `[backport]`) and even less [3] for narimiran)
               | 
               | [1] https://forum.nim-lang.org/t/8540#55418
               | 
               | [2] https://github.com/nim-
               | lang/Nim/commits/devel?author=Araq
               | 
               | [3] https://github.com/nim-
               | lang/Nim/commits/devel?author=narimir...
               | 
               | Right now, it seems like most of the work on the mainline
               | seems to be done by community members.
        
             | ushakov wrote:
             | there is one designer, but the same thing is true for Ruby,
             | Python and many other programming languages
        
               | monetus wrote:
               | yeah, definitely not the only one pushing the design as
               | well - dominick has had a pretty big impact I think
               | right? He's at least helped me.
        
         | StevePerkins wrote:
         | The Venn diagram of:
         | 
         | 1. strong financial backing, with open governance and broad
         | contributors, and
         | 
         | 2. cool
         | 
         | ... has only a thin sliver of overlap.
         | 
         | At some point, either you're motivated to tinker and explore,
         | or you aren't. I can't say what the future holds for Nim, but I
         | would wager that it's an order of magnitude more likely to be
         | around in 20 years than any personal side project app that one
         | of us writes.
        
       | squarefoot wrote:
       | Check also the guy's homepage as he's working on some interesting
       | software and hardware projects.
       | 
       | https://ssalewski.de/
       | 
       | edit:
       | 
       | He also wrote a GTK4 programming guide with Nim examples, which
       | was already submitted here in 2020.
       | 
       | https://ssalewski.de/gtkprogramming.html
       | 
       | Strangely, neither of those books is linked on his homepage.
        
       | talloaktrees wrote:
       | This is very exciting! I had no idea this book was being written.
        
       | sdmac99 wrote:
       | I really need to thoroughly read this. I have scanned sections
       | like the one on References and Pointers and found them useful,
       | but only scratched the surface.
       | 
       | Late last year I switched my work site from Go to Nim. Then this
       | year, with the help of the community and library nimterop, I was
       | able to wrap the duckdb C api and use it in my web app for really
       | fast analytic queries. I really like Nim syntax and the routes in
       | jester:                 routes:         get "/":           resp
       | "Wow, nice"
       | 
       | The false-positive virus issue affected my workstation as well,
       | but after consulting with our security team we were able to
       | resolve it.
       | 
       | I would love Nim to have more funding and support.
       | 
       | I like the batteries included approach, but certainly there are
       | some libraries that do things like json better.
        
       | nooorofe wrote:
       | I have mixed feeling about Nim. I've tried to learn it few years
       | ago. It was "sold" like a Python replacement, it looks like a
       | Python a bit, but when you write code it feels nothing like
       | python at all.
       | 
       | Few things made me confused a bit
       | 
       | * With objects, when I need to use ref and when not.
       | nim> type         ....   Node = ref object         ....      le,
       | ri: Node         ....      data: int         ....         ....
       | nim> var n = Node(data: 9)         nim> n.data         9 == type
       | int              nim> type         ....   NodeO = object
       | ....     lw, ri: ref Node         ....     data: int         ....
       | ....         nim> var no = NodeO(data: 9)         nim> no.data
       | 9 == type int         nim>
       | 
       | * Two ways to import modules, specifically the C style import. I
       | understand the need for it - applying macros and templates, but
       | that makes Nim very different from big family of "no magic"
       | languages. Ability to change syntax is very powerful and probably
       | a big selling point of the language, but in the same time makes
       | it hard to use Nim as casual language.
       | 
       | That time development/coding wasn't my full time job, Python was
       | the "to go" option of automating some tasks, sometimes Java. In
       | both cases there was no magic in the code - `module.something`
       | easy to track to the origin.
       | 
       | Nim's orientation to standard library is nice. I've started
       | checking Nim when I need a faster alternative for parsing big
       | json and csv (compressed and flat) files. I both cases to was
       | easy to archive, easier than Java (with Java I need to match
       | version and bring dependencies) and the speed was fantastic.
       | 
       | Probably the main reason I haven't continued with Nim, was the
       | company's antivirus at some point started to blocks nimble.exe
       | execution on Windows. Another reason is switching to work into
       | data engineering aria and there is no real need for fast compiled
       | program. IDE support wasn't great too, VScode suggested a lot of
       | irrelevant things, but I think it is kind of broken for any
       | language now (out of box).
        
         | zinclozenge wrote:
         | Nim never looked even close to Python for me, no matter how
         | hard I squinted.
        
           | cb321 wrote:
           | I think most confusions come from how divisive significant
           | white space can be and Python being the most popular among
           | that class of surface syntaxes. _I_ am aware (and maybe you
           | are, too) that there is a long list besides Nim:
           | https://en.wikipedia.org/wiki/Off-side_rule, but this does
           | not seem to be very common knowledge.
        
             | dzamo_norton wrote:
             | I think this is a big part of the aesthetic similarity.
             | Without curly, or ordinary, brackets delimiting code blocks
             | you get that nice clean look. Having used Python a lot for
             | a period (and having made one toy app in Nim) I now find
             | especially curly brackets visually noisy.
        
         | nimmer wrote:
         | Clearly you never tried converting existing Python to Nim. It's
         | quick, feels natural and you get idiomatic Nim.
         | 
         | You can even use objects named "self" to ease the transition.
         | 
         | https://github.com/nim-lang/Nim/wiki/Nim-for-Python-Programm...
        
         | amyjess wrote:
         | The best way I can describe Nim is that it marries Python
         | syntax with Modula-3 semantics. It's not just "static-typed,
         | compiled Python", it's the modern inheritor of the entire
         | Algol-Wirth superfamily of languages.
         | 
         | The syntactic differences between Modula-3 and Nim don't mean
         | much in the long run. It's just the fourth phase of this
         | particular superfamily's syntax. It's a bit of an
         | oversimplification, but the preceding syntactic phases can be
         | clumped into "Algol", "Pascal", and "Modula". All of them have
         | _significant_ syntactic differences between them but ultimately
         | come from the same heritage, and I see  "Nim" as just the next
         | phase of that.
         | 
         | (to elaborate a bit: when Wirth evolved Algol 60 into Algol W,
         | he only made small tweaks to the fundamental syntax. He then
         | siginificantly overhauled it when he evolved Algol W into
         | Pascal and then Pascal into Modula(-2). Borland/Embarcadero's
         | evolutions of Pascal are of the same category as Algol W in
         | that they made small tweaks while keeping the core syntax the
         | same. Wirth's further languages Oberon and Oberon-2 all kept
         | the same fundamental structure as Modula-2, despite various
         | small syntactic tweaks, as did Modula-3 which wasn't by Wirth
         | but had his blessing.)
        
       | chaxor wrote:
       | This is really fantastic. Nim is a beautiful language for getting
       | very performance code easily. Also, there's some really nice
       | projects that use Nim out there - I believe nitter.com and
       | teddit.com use Nim, which are much better than using the original
       | websites if you're not super keen on huge scripts dependencies
       | and everything you do being tracked.
        
       | amyjess wrote:
       | Nim just looks like a dream language to me. It's a fusion of
       | Python and Modula-3 with incredibly expressive macro support
       | (almost as capable as Lisp!) and nifty features like UFCS.
       | 
       | I just wish I had the opportunity to use it. Every time I start
       | working on a personal project, I always default to Python just
       | because I know it well and I know the ecosystem has every library
       | I could want. I need an excuse to write something in Nim.
        
         | ajusa wrote:
         | https://github.com/yglukhov/nimpy gives very, very solid access
         | to the Python ecosystem from Nim - I've copied code from Python
         | docs and have had it work with hardly any changes. Hopefully
         | that's a good enough excuse to try Nim out for a personal
         | project!
        
       | adenozine wrote:
       | Sidebar: I'm excited to see Nim get LLVM support via nlvm. I
       | haven't read this document yet but I just remembered that Nim is
       | an advancing language and checked GitHub for new developments.
       | 
       | It seems to be that Crystal has made some leaps and bounds in
       | picking up some of the Ruby slack, though I see Nim lagging
       | behind of taking up some Python users.
       | 
       | I'd feel 100000x more comfortable as a potential user if they had
       | a little more corporate support and some mainstream use cases.
       | 
       | I think I'll take this post as the wake up call to take Nim more
       | seriously in my own hobby programming. I've had my eye on it
       | since they changed the name and I discovered it; but I didn't
       | realize until today people were building such thorough resources.
        
         | michaelsbradley wrote:
         | Lots of exciting work also being done in libs, e.g. chronos[1]
         | (just _one_ example), which is an alternative to std
         | /asyncdispatch[2].
         | 
         | [1] https://forum.nim-lang.org/t/8950
         | 
         | [&] https://github.com/status-im/nim-chronos#readme
         | 
         | [2] https://nim-lang.org/docs/asyncdispatch.html
        
         | nimmer wrote:
         | Nim uses GCC and works very well. Nim is among the fastest
         | languages both in runtime and compilation time also thanks to
         | GCC.
         | 
         | GCC supports way more architectures than LLVM.
        
         | mathverse wrote:
         | Yeah they need at least one more big corporate sponsor besides
         | Status.
        
           | michaelsbradley wrote:
           | "One more" because, in your view, it's important to have 2+
           | or it's problematic to have Status as a/your-only sponsor?
           | Just curious.
        
             | _dain_ wrote:
             | The only big sponsor being a cryptocoin startup doesn't
             | inspire a lot of confidence.
        
               | michaelsbradley wrote:
               | On technical merits or.......?
               | 
               | We use Nim to prototype many things (though not all
               | things), and in many cases they go into production with
               | `-d:release` just fine:
               | 
               | https://github.com/orgs/status-im/repositories
               | 
               | A good example is nimbus-eth2, which is one of the (The?)
               | most energy-efficient Beacon Chain clients, with real
               | money at stake:
               | 
               | https://github.com/status-im/nimbus-eth2#readme
        
               | adenozine wrote:
               | Whether or not you agree with the many people who think
               | cryptocurrency is the biggest grifting scam to ever grace
               | the internet or not, the bottom line is that as long as
               | they think that and as long as Status is the sole
               | corporate interest behind Nim, then it faces real and
               | several difficulty in picking up steam.
               | 
               | The reality is that most people are not going to use
               | cryptocurrency anytime in the next 10 years. Landlords
               | won't take it, grocery stores won't take it, the whole
               | thing is a mind-boggling waste of time and energy.
               | 
               | Even still, while the tech Status is producing might be
               | cool, surely you can't be so naive as to overlook the
               | obvious tinge it places on other potential Nim adopters.
               | 
               | I'm a crotchedy 50+ yo fart, so pay me no mind if what I
               | say bothers you.
        
               | michaelsbradley wrote:
               | I'm a 45+ yo fart, and all my learning, experiences, and
               | talents have in many recent years been and are being
               | poured wholeheartedly into blockchain/crypto-related tech
               | (which is all Open Source software), no regrets on my
               | part whatsoever.                  you can't be so naive
               | as to overlook the obvious tinge it places on other
               | potential Nim adopters
               | 
               | I've done a lot of soul-searching on this front, and I
               | can't even conceive of a "tinge" on _rational_ potential
               | Nim adopters.
        
               | dzamo_norton wrote:
               | 41 yo fart. Rational at times. The tinge, in general,
               | comes from the huge number of crypto projects that are
               | indistinguishable from Ponzis, vehicles for what would be
               | a financial crime if done with regulated instruments, or
               | just the counterproductive inclusion of a blockchain. Nim
               | itself never felt tinged to me back when I tried (and
               | enjoyed) it. But I generally won't touch anything
               | "crypto".
        
               | michaelsbradley wrote:
               | Rational at times
               | 
               | I try to be, especially when on the clock :D
               | Nim itself never felt tinged to me back when I tried (and
               | enjoyed) it. But I generally won't touch anything
               | "crypto".
               | 
               | Fair enough (I guess). But if you work/play-with with Nim
               | these days, and the libs available from
               | https://nimble.directory/, do you feel you're "touching
               | crypto"? If so, why?                  huge number of
               | crypto projects that are indistinguishable from Ponzis,
               | vehicles for what would be a financial crime if done with
               | regulated instruments, or just the counterproductive
               | inclusion of a blockchain
               | 
               | Well... I feel I stand little chance of convincing you of
               | anything, but feel free to checkout the status-im GitHub
               | org I've linked to previously, and you're also very
               | welcome to ask Status core contributors the most
               | scorching questions you can think of via our
               | desktop/mobile app, or on our Discord server, or on
               | https://discuss.status.im/.
        
       | blondin wrote:
       | not sure if the author is reading, but i would love to buy a
       | paper copy of this book :)
        
       | chillerman12 wrote:
       | The new dydx competitor builds there central order book in nim:
       | 
       | https://twitter.com/jae_tacen/status/1497242050185498630
       | 
       | tacen.com
        
       | rajandatta wrote:
       | Impressive work. Seems very thorough.
        
       | jasfi wrote:
       | I'm writing a cross-platform UI toolkit: https://nexusdev.tools/
       | 
       | The first supported back-end is Nim, which I use in my own
       | projects. Python and other back-end languages will be easy enough
       | to add. The initial front-end is Flutter.
       | 
       | Nim is a great language, very easy to learn and write in. I was a
       | bit skeptical of using a non-OO language for large projects, but
       | it's been fine, and I actually prefer it now.
        
       | ajusa wrote:
       | This is a really fantastic resource for learning programming with
       | Nim. I've started recommending it to folks that are newer to
       | programming that want to try Nim out for various reasons. The
       | only downside is that it is written by a non-native english
       | speaker, so some of the phrasing feels awkward at times. Of
       | course, that's a non issue for this kind of technical material,
       | it's very understandable and useful! You can also view the source
       | of this material here:
       | https://github.com/StefanSalewski/NimProgrammingBook
       | 
       | For folks that are more experienced and learn by doing, the two
       | resources I would recommend are https://nim-by-example.github.io/
       | and https://xmonader.github.io/nimdays/. The first is a solid
       | overview of the basic language, while the second is a bunch of
       | example projects. Other good resources if anyone is interested:
       | 
       | Nim in Action (book)
       | 
       | https://narimiran.github.io/nim-basics/
       | 
       | https://scripter.co/notes/nim
       | 
       | The official Nim tutorial: https://nim-lang.org/docs/tut1.html
       | 
       | Nim also had a devroom at FOSDEM this year! You can find it at
       | https://fosdem.org/2022/schedule/track/nim_programming_langu....
       | 
       | My favorite talks were on Polymorph (a really fast compile time
       | ECS), Pararules (a super cool implementation of a rules engine)
       | and Nim Metaprogramming in the real world (very useful lesser
       | known patterns for using Nim's capabilities in a variety of
       | projects).
        
       | uncomputation wrote:
       | Wow, this clearly took a lot of work and time. Great to see
       | someone putting in that level of effort and teaching people
       | nonetheless!
        
       ___________________________________________________________________
       (page generated 2022-02-27 23:01 UTC)