19 votes

Nim: A Programming Language Underdog

29 comments

  1. [11]
    MacDolanFarms
    (edited )
    Link
    Nim seems cool, but the one thing I can't get past is the choice of rather than just making spaces the recommended indentation style, they have made it a syntax error to indent with tabs, which is...

    Nim seems cool, but the one thing I can't get past is the choice of rather than just making spaces the recommended indentation style, they have made it a syntax error to indent with tabs, which is absolutely ridiculous. While this is a relatively minor issue I can't stand to use a project that thinks their stylistic choice is the only correct option and anything else is a syntax error.

    Python, Ruby, and Go all have standard styles that pretty much everyone follows, without even forcing them to. You could easily solve it in other ways without going that route:

    • Make a standard code style document, like PEP 8, or just heavily encourage the use of four spaces. Python and Ruby both allow tabs but practically everyone uses 4 and 2 spaces respectively, because it is the standard.
    • Make a code-reformatter like gofmt that reindents with spaces. Go does this and almost everything follows the official style (tabs).

    Tabs vs. spaces is an ages-old argument. Using spaces is fine, and using tabs it fine, but don't force people to use tabs, and don't force people to use spaces. Your stylistic choices are just stylistic choices.

    18 votes
    1. [5]
      SleepyGary
      Link Parent
      Gofmt makes it an error to not follow stylistic rules (tabs not spaces BTW). Personally I am in favour of strict rules it elimates cognitive overhead and wasted hours debating style with teams. I...

      Gofmt makes it an error to not follow stylistic rules (tabs not spaces BTW). Personally I am in favour of strict rules it elimates cognitive overhead and wasted hours debating style with teams. I don't care what the style is as long as it is consistent.

      9 votes
      1. [4]
        MacDolanFarms
        (edited )
        Link Parent
        I know. It is an error with gofmt, but not with Go itself. Go can be indented with spaces no problem, but gofmt will not accept that. That's fine; here not following the style is an error for the...

        I know. It is an error with gofmt, but not with Go itself. Go can be indented with spaces no problem, but gofmt will not accept that. That's fine; here not following the style is an error for the formatter, but not the compiler.

        For Nim on the other hand, the compiler will refuse to compile any code that uses tabs for indentation.

        I think having consistent code is great, and I gave three examples of languages with universally accepted styles (Python, Ruby, Go), that manage to do so without forcing you. If those three can manage to do so without forcing you in the slightest, I don't see why Nim cannot as well. For example Crystal (another fairly new language) has a style guide that everyone follows.

        5 votes
        1. SleepyGary
          Link Parent
          If everyone is using it, why that would be a problem if it's forced or not? Personally I would welcome python, ruby and go, any/all language for that matter, to make it a syntax error, if everyone...

          If everyone is using it, why that would be a problem if it's forced or not?

          Personally I would welcome python, ruby and go, any/all language for that matter, to make it a syntax error, if everyone is already following it, why not codify it and remove all doubt. Rather than needing tools like .editorconfig and stylistic rules in linters, IDEs and editors could just detect the language, adjust accordingly and be able to inform developers at write time they have made a mistake.

          5 votes
        2. [2]
          kaushalmodi
          Link Parent
          I find that amusing.. how would you know that everyone follows an unenforced style guide? :) I agree with @SleepyGary that once you have the compiler through an error, you need to straighten up...

          For example Crystal (another fairly new language) has a style guide that everyone follows.

          I find that amusing.. how would you know that everyone follows an unenforced style guide? :)

          I agree with @SleepyGary that once you have the compiler through an error, you need to straighten up your editor config or whatever to prevent that error in future. I have yet to see that Nim compiler error because of tab chars :)

          5 votes
          1. MacDolanFarms
            Link Parent
            Of course that's hyperbole. I don't know that, and there's no way for me to know that, but in practice I've never seen Crystal code that didn't follow the standard indentation. It is possible to...

            I find that amusing.. how would you know that everyone follows an unenforced style guide? :)

            Of course that's hyperbole. I don't know that, and there's no way for me to know that, but in practice I've never seen Crystal code that didn't follow the standard indentation. It is possible to enforce things entirely by convention.

            2 votes
    2. [4]
      kaushalmodi
      Link Parent
      This awesome, though polarizing, decision by the Nim team is one of the cherry on the top Nim features why I love it. Consistency + sanity. I have been through countless files (an example) where...

      just making spaces the recommended indentation style, they have made it a syntax error to indent with tabs, which is absolutely ridiculous.

      This awesome, though polarizing, decision by the Nim team is one of the cherry on the top Nim features why I love it.

      While this is a relatively minor issue I can't stand to use a project that thinks their stylistic choice is the only correct option

      Consistency + sanity. I have been through countless files (an example) where colleagues using tabs (mostly unknowingly) make reading code a horrible experience.

      Spaces are nice.. a space will always a space char wide whether or not the colleagues understand tabs vs spaces.

      (We can go back and forth on this forever.. tabs vs spaces is one of the eternal wars.)

      don't force people to use spaces. Your stylistic choices are just stylistic choices.

      If someone can get past this as an "issue", they might discover the beauty of this language.

      8 votes
      1. MacDolanFarms
        Link Parent
        I only found this issue because I was looking into Nim. It seemed great, but this one thing completely turned me off from it, and here's why: I'm not going to use a language where it seems the...

        don't force people to use spaces. Your stylistic choices are just stylistic choices.

        If someone can get past this as an "issue", they might discover the beauty of this language.

        I only found this issue because I was looking into Nim. It seemed great, but this one thing completely turned me off from it, and here's why:

        I'm not going to use a language where it seems the developers are going to be antagonistic to people who think slightly differently. It just feels like you're doing it wrong, here, we'll show you the right way.

        I'm not going to use software that thinks its users are dumb and need to be babysat, pushed towards the correct choices and restricted of all other options. And honestly, that philosophy can fuck right off.

        7 votes
      2. Emerald_Knight
        Link Parent
        I've never had anything but trouble with spaces. I find that usually they're used sloppily, leading to mixed-width indentation. I've modified files that had 2, 3, 4, and 5 space indentation all at...

        I've never had anything but trouble with spaces. I find that usually they're used sloppily, leading to mixed-width indentation. I've modified files that had 2, 3, 4, and 5 space indentation all at once. If a standard isn't strictly enforced within a project, you could find that different files have different indentation widths, depending on the default settings of the IDE of the person who created the file.

        I generally prefer tabs for this reason. No matter what editor you're using, you can set your preferred width and not worry about a thing; you don't deal with the differing widths issue; and it's usually pretty clear when your indentation is off. Spaces are reserved for alignment of items.

        Although, I would never force someone else to use my preferred standard unless it was already established as the standard for a given project. Consistency trumps personal preference every single time. When you're working on an existing project, you configure your editor to conform to the project's standards, period. Your merge request isn't being accepted otherwise.

        So personally, I would consider Nim to be far too authoritarian for my tastes. Forcing you to use certain constructs is one thing, but forcing you to conform to a specific style based purely on the language maintainers' personal preference leaves a bad taste in my mouth.

        With that being said, I do see some value in enforcing consistency at the language level, e.g. in the way Python enforces one type of indentation (but doesn't make any particular one a failing error!). I don't mind built-in linting as long as you can select the standard that you want, rather than being forced to follow someone else's.

        3 votes
      3. [2]
        Comment deleted by author
        Link Parent
        1. MacDolanFarms
          Link Parent
          Exactly. My issue has nothing to do with spaces themselves, but that it is so authoritarian as to force me to use spaces. I use spaces all the time, because I follow the standard of whatever...

          Exactly. My issue has nothing to do with spaces themselves, but that it is so authoritarian as to force me to use spaces. I use spaces all the time, because I follow the standard of whatever project I'm working on.

    3. Diff
      Link Parent
      This is JSLint all over again.

      This is JSLint all over again.

      2 votes
  2. Eva
    Link
    nim is wonderful. Highly recommend trying a small (or large!) project in it.

    nim is wonderful. Highly recommend trying a small (or large!) project in it.

    7 votes
  3. [10]
    unknown user
    Link
    It's been a while since I stopped pursuing becoming a professional programmer, and only write code when it's necessary for myself in general, but I'll still share my opinion about this language,...

    It's been a while since I stopped pursuing becoming a professional programmer, and only write code when it's necessary for myself in general, but I'll still share my opinion about this language, which admittedly I don't use or have used. The big, glaring con for me is the fact that it has significant indentation. Apart from agreeing @MacDolanFarms, I personally just can not handle dealing with significant indentation. Many times when working with Python I've had very hard to find bugs that blocked me for hours caused by moving a code into the wrong indentation level when moving code around. I also find it harder to tell where I'm at in the code, and hate having to indent things perfectly when editing fast.

    My favourite language is Emacs Lisp, and Lisp in general, because they just have the perfect syntax, and having something like Paredit means that you almost never fail when moving bits of code around. Sexps are just easy and good, I don't understand why more languages use them. They are better even when just used as syntax like braces and w/o homoiconicity. If not, just have C braces. They make the life easier.

    7 votes
    1. [2]
      kaushalmodi
      (edited )
      Link Parent
      This is Nim; it is a statically typed compiled language. It's hard to imagine that you could arbitrarily move a block to any indentation and still have the code even compile. So much +1 this. I...

      Many times when working with Python I've had very hard to find bugs that blocked me for hours caused by moving a code into the wrong indentation level

      This is Nim; it is a statically typed compiled language. It's hard to imagine that you could arbitrarily move a block to any indentation and still have the code even compile.

      My favourite language is Emacs Lisp, and Lisp in general, because they just have the perfect syntax, and having something like Paredit means that you almost never fail when moving bits of code around. Sexps are just easy and good, I don't understand why more languages use them.

      So much +1 this. I love Emacs Lisp too, and I never get the "fear of parentheses". But if you put the indentation vs lisp preference aside, this language is worth exploring.

      They are better even when just used as syntax like braces and w/o homoiconicity. If not, just have C braces. They make the life easier.

      This is another polarizing preference (first one that I referred to another comment is this thread is tabs vs spaces). I like Lisp because all the closing parens pack up the end of the last form.

      With C/Perl type parens, the code becomes too ugly (IMO) too quickly as everyone has a different style of where to put the parens and they are not so good. With indentation-based blocks, Python solved this major problem, and I am glad Nim took it up.

      Another reason why I love Nim is the composability that I enjoy so much in Emacs Lisp.

      Here's an example (in Nim):

      let
        idxString = if withIndex:
                      fmt"{idx:>4}. "
                    else:
                      "  "
      

      Full Source

      Looks a bit familiar? (see psuedo equivalent version of this below, in Emacs Lisp) :)

      (let ((idxString (if withIndex
                           (fmt"{idx:>4}. ")
                         "  ")))
        ;; use idxString
        )
      
      3 votes
      1. unknown user
        Link Parent
        If I be totally honest, that Nim example seems quite disagreeable to me, and yet I do like how Haskell and other ML programs are laid out. Maybe that's because I'm unfamiliar with the language. I...

        If I be totally honest, that Nim example seems quite disagreeable to me, and yet I do like how Haskell and other ML programs are laid out. Maybe that's because I'm unfamiliar with the language. I brought up Python because it's the other indentation-based language I'm actually familiar with. For me, I really dislike that the following is a syntax error:

        if True:
            print 'true'
           print 'indeed'
        

        because I generally work in the REPL and that sort of code easily happens when editing a definition here and there. Having to fix formatting before checking if the code is valid interferes with my concentration (I don't think I have ADHD, but I'm very bad at concentrating). And that's a REPL situation, I'd really dislike it in a edit-compile type of experience (which seemingly what Nim has).

        But when it comes to building something concrete, all of this becomes taste and detail. If I had to do something with C, Nim seems like a strong candidate to use instead of using C directly. I guess it competes with languages like D, but has a different approach to interop with C. It's a bit similar to Vala which compiles to C with GObject. I'm not sure if such appoach is a good one, but I lack the expertise to tell if it is or not.

        Edit: wait, I actually like how code is laid out in that program of yours you linked. I does look quite a bit like OCaml to me, without the awkard ;;.

        2 votes
    2. [7]
      mrbig
      Link Parent
      I have been using Emacs for 6 months and I cannot understand Elisp. It’s just not a language I can learn by doing, like I did with Vimscript. I have to actually study and I don’t have the time. I...

      I have been using Emacs for 6 months and I cannot understand Elisp. It’s just not a language I can learn by doing, like I did with Vimscript. I have to actually study and I don’t have the time. I have my configurations in General and use-package, which helps a lot. Maybe someday.

      1 vote
      1. [6]
        kaushalmodi
        Link Parent
        This is a really good reference to help kickstart learning Elisp, as you don't need to devote too much time to finish it.. may be ½ hour or may be 1 (or something around that). Learn X in Y...

        This is a really good reference to help kickstart learning Elisp, as you don't need to devote too much time to finish it.. may be ½ hour or may be 1 (or something around that).

        Learn X in Y minutes - Emacs Lisp

        And then just keep on tinkering with your Emacs config, study published Emacs packages, passively follow Emacs help mailing list, (and/or the /r/Emacs subreddit, emacs.stackexchange.com).

        4 votes
        1. [5]
          mrbig
          Link Parent
          I tried this one before. I didn’t finish but I think it’s good. www.lisperati.com/casting-spels-emacs/html/casting-spels-emacs-1.html

          I tried this one before. I didn’t finish but I think it’s good. www.lisperati.com/casting-spels-emacs/html/casting-spels-emacs-1.html

          1 vote
          1. [4]
            kaushalmodi
            Link Parent
            I didn't know Dr. Conrad Barski (of Land of Lisp fame) had this comic book for Emacs Lisp! Thanks for linking it. Skimming through it, I think that it's not designed to serve as Emacs Lisp 101. I...

            I didn't know Dr. Conrad Barski (of Land of Lisp fame) had this comic book for Emacs Lisp! Thanks for linking it.

            Skimming through it, I think that it's not designed to serve as Emacs Lisp 101. I think that the jump from here to here is too big for someone completely new to Emacs Lisp or Lisp in general.

            Based on my brief skimming through that site, I think that someone already with mild introduction to a Lisp dialect will surely enjoy it (I plan to through it in entirely this week).


            PS: The website is not very responsive (doesn't look good on mobile devices).. I wonder if I can convert that to a responsive version using Org mode + Hugo and ping the author about it..

            2 votes
            1. [3]
              mrbig
              (edited )
              Link Parent
              I actually have the book "Land of Lisp", what do you think of it?

              I actually have the book "Land of Lisp", what do you think of it?

              1. [2]
                kaushalmodi
                Link Parent
                I haven't finished the book. I started reading it a while back and finished only a tiny bit of it (Section I: first 3 chapters). The reading experience was nice. It mainly corroborated what I...

                I haven't finished the book. I started reading it a while back and finished only a tiny bit of it (Section I: first 3 chapters). The reading experience was nice. It mainly corroborated what I already learned about Lisps in general by using Emacs Lisp.

                I think it's a good "Introduction to Lisp" book.. helps people familiarize with everything is a list concept, car, cdr, etc. (from what I read in the first 3 chapters).

                Now I need to find time to finish that book. At the moment, I am reading this awesome book on the history of some of the not-so-known typographical characters: Shady Characters.

                1 vote
                1. mrbig
                  Link Parent
                  Ohhh... this book makes me think you're a smart person! hehehe :P

                  Ohhh... this book makes me think you're a smart person! hehehe :P

  4. [3]
    bme
    Link
    wadler's law in full effect here.

    wadler's law in full effect here.

    4 votes
    1. [2]
      kaushalmodi
      Link Parent
      I couldn't agree more! It looks like the people don't understand or want to understand the real language features, and so gang up on trivial things like tabs and spaces. Just accept that TABs are...

      I couldn't agree more! It looks like the people don't understand or want to understand the real language features, and so gang up on trivial things like tabs and spaces.

      Just accept that TABs are illegal characters in Nim and don't use them, or configure your editor to replace those, and move along.

      2 votes
      1. Jidairo
        Link Parent
        It look's to me like people are going "I don't quite like this," and moving on from the thought of trying it out. You're obviously investing in it, so why? Not "[list of features]," what do you...

        Just accept TABS are illegal characters in Nim and don't use them, or configure your editor to replace them, and move along.

        It look's to me like people are going "I don't quite like this," and moving on from the thought of trying it out. You're obviously investing in it, so why? Not "[list of features]," what do you like about it? Why do you want people to try it out and possibly start using it more often? What benefit does it bring?

        Perhaps another angle, here's a language that doesn't compile when indented with spaces (I neither know of one, or how it would be possible to implement, it's just a hypothetical). Opinions? Thoughts? Would you try it out?

        2 votes
  5. NeoTheFox
    Link
    I've recently noticed that Nim exists because pakku, my new personal favorite AUR wrapper is written with Nim, and ever since I've switched to it I wanted to try out the language itself someday. I...

    I've recently noticed that Nim exists because pakku, my new personal favorite AUR wrapper is written with Nim, and ever since I've switched to it I wanted to try out the language itself someday. I guess I should treat this Tildes post as a sign.

    3 votes
  6. [3]
    kaushalmodi
    (edited )
    Link
    While replying to a comment by @Jidairo, I'm also making this a top level comment for more visibility. Why I like the Nim language I started using Nim a few months back. I actually wanted to start...

    While replying to a comment by @Jidairo, I'm also making this a top level comment for more visibility.


    Why I like the Nim language

    I started using Nim a few months back. I actually wanted to start using it about two years back, but it never happened. But my return to Nim was a good step; this time I might be here for a while as I have started to understand the nitty-gritty details of the language, and starting collecting my notes on it.

    Here's why I think Nim is an awesome language:

    1. Syntax: It's beautiful. If you like Python syntax, you'll like this. In fact, it's much more concise, but not at the cost of readability.

    2. Static type check, with a sprinkle of type inference (only when assigning the initial value).

    3. Proc/operator overloading: Have procedures (functions) with the exact same identifiers handle different data types in their own way.. and the same with operators.

    4. Generics: You can use generics in procs, iterators, etc.

    5. Cross Platform: While I don't use Windows or macOS, I have known Nim applications to compile on those OSes too, in addition to GNU/Linux type OSes plus a few more like Raspberry Pi and types.

    6. .so object export: Nim can compile the code to binaries, but they can be compiled to just libraries (.so objects) too. Here's my experiment on how I write code in Nim to talk to Emacs (v25.1+) via the Emacs Module support. That allows me to run Nim-written code from Emacs Lisp (and even executing Emacs Lisp code from Nim). How awesome is that‽

    7. Support: Great support over Gitter, GitHub issues, Nim Forum, etc. Great devs! (though, I incorrectly thought earlier that that wasn't the case :))

    8. Makes me feel at home: Hacking/coding in Nim comes the closest to coding in Emacs Lisp. In Emacs, if I want to understand what a function does, I look at its source code. I can do the same in Nim (look at the source, hack it, tweak it, submit PR).

    9. Editor support: The nim-mode Emacs major mode and ob-nim Org Babel package are awesome!

    10. Documentation: Check out the Nim the index.html to search anything. There are also Devdocs for Nim.

    11. Whitespace: Tab not allowed, yay! (I know that many folks don't like that.)

    12. Package distribution: The nimble tool (equivalent of pip) works great for building/distributing Nim projects.

    .. and much more! Computer science experts can talk about more benefits of Nim from systems programming point of view (GC, etc.).

    As for my use case, I use Nim as Python/Bash replacement, CLI utility development, and it looks excellent so far!

    In plain terms, coding in Nim is pure joy :)

    3 votes
    1. [2]
      dangersalad
      Link Parent
      Do you have any examples to share of the “bash replacement” use case? I frequently make bash scripts to automate my work, as it is in a sense self documenting a CLI procedure. I’d be interested to...

      Do you have any examples to share of the “bash replacement” use case? I frequently make bash scripts to automate my work, as it is in a sense self documenting a CLI procedure.

      I’d be interested to see what some of your nim “bash scripts” look like.

      2 votes
      1. kaushalmodi
        (edited )
        Link Parent
        Some of my Nim projects are public; you can find them here. nbuild — This is a bash-script port. I am playing with adding TOML config file companion file to this script to streamline my local...

        Some of my Nim projects are public; you can find them here.

        • nbuild — This is a bash-script port. I am playing with adding TOML config file companion file to this script to streamline my local package builds. This is a rough translation of this bash script. At the moment, I have a separate bash script for dozens of apps that I install locally (it's not as simple as make && make install for all apps as I am on an old OS RHEL 6.8 without sudo rights). Plan is to have just this one nbuild binary do building for all the packages, while picking package-specific CFLAGS/LDFLAGS, build using make/go/cargoetc., whatever from that TOML config file.
        • noxhugo — Had I not known of Nim, I would have used bash for this one. This is what it does.
        • ntodo — I would have written this one in Python if I hadn't known of Nim. This is my latest project in Nim. If someone is using Todoist, and wants to try compiling a Nim project to see how to access their Todoist tasks from CLI, this is a good project :). The project is stable, but WIP i.e. I added API support for all Todoist project actions, and most task actions.
        2 votes