8 votes

My random notes for Nim lang

-> Nim notes <-


Some background

I am learning a new programming language Nim. As many would do, I also take my own notes as I am learning it, running little example by myself, etc.

    .. but I doing that a bit differently.

  • I take notes in Emacs Org mode. Org mode has a feature set called Org Babel. That allows one to document the code snippets, and also run them directly in that document, and insert their output results below them -- Notes in Org

    This also helps me document regression of the language behavior between different Nim versions of any, as the exact outputs are documented too. After each major Nim update, I press a single binding (C-v C-v b) in Emacs, and all the output blocks get recalculated.

  • But not everyone uses Emacs and Org mode. So to be able to share them to a wider audience, I need to export (Org term) that to a format like HTML, PDF, or Markdown..

  • Hugo is a really fast static site generator that uses Markdown as one of the primary content formats. It parses that to HTML using a Go Markdown library called Blackfriday.

  • As my notes are in Org mode, and converting them to HTML via Hugo needs them to be in Blackfriday compatible Markdown (which is almost like GitHub flavored Markdown), I starting working on an Emacs Org mode package ox-hugo about a year back. Using that, this Markdown file is generated. Hugo natively supports a subset of Org, but I needed to write this package to use the full power of Org mode.

  • Hugo then takes that Markdown and generates the final Nim notes page in HTML.


In the end, I have something that ties together all things of my interest: Nim, Emacs, Org mode and Hugo :)

11 comments

  1. [2]
    planNine
    Link
    I've heard of Nim before, but never really looked at it. The idea of using the same language for both systems software and web development (if I'm understanding it correctly) is kinda cool, as...

    I've heard of Nim before, but never really looked at it. The idea of using the same language for both systems software and web development (if I'm understanding it correctly) is kinda cool, as much as I dislike web development.

    I guess Nim will go on my never-ending list of programming languages that I'd like to take a closer look at, and at that point I might peruse your notes. :)

    P.S. I think I've seen you on the emacs-dev mailing list or am I wrong?

    2 votes
    1. kaushalmodi
      Link Parent
      You're right. I am active there too.. active in the sense that I at least try to read all the threads there that I can understand. I'm a bit more active on the Org Emacs ML :)

      P.S. I think I've seen you on the emacs-dev mailing list or am I wrong?

      You're right. I am active there too.. active in the sense that I at least try to read all the threads there that I can understand. I'm a bit more active on the Org Emacs ML :)

      1 vote
  2. [9]
    jgb
    Link
    I like the look of Nim, it's something I've considered learning a few times. Crystal has also caught my eye. I want something that's fast and preferably compiled, but also high-level and...

    I like the look of Nim, it's something I've considered learning a few times. Crystal has also caught my eye. I want something that's fast and preferably compiled, but also high-level and expressive, with static typing. Rust is good for some stuff, but it's a sledgehammer for a nut in a lot of scripting applications.

    P.S. you need to comma-seperate your tags :)

    1 vote
    1. [7]
      planNine
      Link Parent
      This is kinda off-topic. What about Haskell, doesn't it fit the description? From what I'm to understand it can be pretty fast too.

      This is kinda off-topic. What about Haskell, doesn't it fit the description? From what I'm to understand it can be pretty fast too.

      1 vote
      1. [6]
        jgb
        Link Parent
        Haskell certainly interests me, but I'm not sure it's the right choice for scripting - I want something that I can use to hack together programs in the same way that I would in Python, and I'm not...

        Haskell certainly interests me, but I'm not sure it's the right choice for scripting - I want something that I can use to hack together programs in the same way that I would in Python, and I'm not sure I'm smart enough to be able to do that in Haskell, at least not without a very large time investment indeed.

        1. [5]
          planNine
          Link Parent
          Then obviously the right choice would be Bash!

          Then obviously the right choice would be Bash!

          1 vote
          1. [4]
            jgb
            Link Parent
            Even in my hackier programs I'd like to have static typing, classes, and expressive stuff like pattern matching and list comprehensions. Bash isn't really the right fit.

            Even in my hackier programs I'd like to have static typing, classes, and expressive stuff like pattern matching and list comprehensions. Bash isn't really the right fit.

            1. [3]
              planNine
              Link Parent
              Sorry, I guess I should have been clearer. It was a joke :). I would only use Bash for a 3-line script, for anything longer Python is better imo.

              Sorry, I guess I should have been clearer. It was a joke :). I would only use Bash for a 3-line script, for anything longer Python is better imo.

              1. [2]
                jgb
                Link Parent
                Ah - I did get that impression but given the crazy stuff some people manage to do in shell scripts I couldn't be sure!

                Ah - I did get that impression but given the crazy stuff some people manage to do in shell scripts I couldn't be sure!

                1 vote
                1. planNine
                  Link Parent
                  Oh yeah, totally get that. I've seen some really complex pieces of software written in Bash and I don't know whether to applaud the author or just shake my head.

                  Oh yeah, totally get that. I've seen some really complex pieces of software written in Bash and I don't know whether to applaud the author or just shake my head.

                  2 votes
    2. kaushalmodi
      (edited )
      Link Parent
      If you like Python, switching to Nim is fairly straightforward (at least for the type of stuff I do, mainly writing small scripts). Additionally little things like the language not allowing tabs,...

      I like the look of Nim

      If you like Python, switching to Nim is fairly straightforward (at least for the type of stuff I do, mainly writing small scripts). Additionally little things like the language not allowing tabs, suggestion to keep line lengths within 80 chars, and big things like static typing with auto type inference at few places (I think, only when declaring variables and assigning them values at the same time) appeal me a lot.

      I want something ..

      It sounded like you were describing Nim :)

      I wrote my first non-example-trying Nim code last week (nbuild.nim <- that's a hyperlink. At least on mobile, it doesn't look like one.), mainly in an effort to convert an existing Bash script to Nim, and I was successful + added features like reading stuff from config.toml to that script. Have a look at it; I believe it's fairly readable even for folks who don't know Nim.

      P.S. you need to comma-seperate your tags :)

      Thanks, I just fixed that; should have already read that it said that tags are comma separated.

      1 vote