Live data from Hacker News

Patten Matching in Nim

nim-lang.org

41–50 of 54 posts

Re: Patten Matching in Nim

#41

NIM seems like this unicorn of a language of having great performance, amazing balance between being both high-level and low-level, extremely approachable due to syntax ... yet very few have actual discovered and use NIM. I wonder why.

I'm jumping in as soon as a robust 3D game engine uses it as a first class language.

Re: Patten Matching in Nim

#42
post #36

Earlier quoted context omitted.

thats not a different way of doing same thing, its doing different thing. this not even an argument, if language can provide multiple memory management strategies, in what world is that a bad thing? and if you somehow confused about choice (of gc), you should stick to default. also, there is no such thing as "There is Only One Way to Do It" languages. your entire argument is just a circlejerk point.

Is Nim garbage collected? There is no simple answer to that. When it is garbage collected, how is it garbage collected? There is no simple answer to that. As stated in my original comment, I prefer languages which are more opinionated than that. Nim is a Swiss Army knife; some people like that, but I prefer choosing a fixed-blade knife to suit my current purpose.

> Is Nim garbage collected? There is no simple answer to that.

Yes, Nim v1 is a garbage collected language. It also shipped with custom destructors support https://nim-lang.github.io/Nim/destructors.html.

Nim v2, which is hopefully two releases away, will ship with a memory management scheme called "orc" https://nim-lang.org/blog/2020/12/08/introducing-orc.html

However right now, it is recommended that all new code is written with the `--gc:orc` switch.

Re: Patten Matching in Nim

#43

I played with Nim a little bit, loving it for a while, and I quickly ran into the same issue I had with Julia, which was that I had trouble staying in the basic language . Both Nim and Julia's documentation, and many modules/imports/includes/whatever of those languages, immediately jump to "holy shit we have macros! Importing this module changes the syntax! Isn't that awesome?!" And I'm like, no, it's not awesome. Ne…

...except that macros don't change the syntax of the language!

They just offer convenience on top of it, most common example is the `=>` lambda operator from the `sugar` module. I do agree, that the pattern matching macro presented in the article is a bit hard to get used to, but you don't have to, if you don't like pattern matching. And of course there are plenty of alternatives available as well, the simplest one imo is https://github.com/andreaferretti/patty

Re: Patten Matching in Nim

#44
post #27

NIM seems like this unicorn of a language of having great performance, amazing balance between being both high-level and low-level, extremely approachable due to syntax ... yet very few have actual discovered and use NIM. I wonder why.

I tried out Nim. My first reaction was that I absolutely loved it. Second reaction was when I needed to look up how to do something and I realised that the docs aren't amazing. Third reaction was when I first ran into a problem I couldn't find anything on Google, and had to post on the Nim forums. The forums were great but there's an inevitable time lag between posting and getting a response. Then I started looking a…

> I ended up appreciating the guardrails it provides around safety that Nim doesn't...

fwiw this is plain wrong, a garbage collected language in general is memory safe, just with a different scheme (a garbage collector) than rust's memory model. Both are better options from one that is unmanaged.

I hate to attract negative attention from rust fanboys. But none likes Rust's borrow checker and hopefully language developers can come up with a better design.

Re: Patten Matching in Nim

#45
post #36

Earlier quoted context omitted.

thats not a different way of doing same thing, its doing different thing. this not even an argument, if language can provide multiple memory management strategies, in what world is that a bad thing? and if you somehow confused about choice (of gc), you should stick to default. also, there is no such thing as "There is Only One Way to Do It" languages. your entire argument is just a circlejerk point.

Is Nim garbage collected? There is no simple answer to that. When it is garbage collected, how is it garbage collected? There is no simple answer to that. As stated in my original comment, I prefer languages which are more opinionated than that. Nim is a Swiss Army knife; some people like that, but I prefer choosing a fixed-blade knife to suit my current purpose.

Is C garbage collected? There is no simple answer to that. Link with Boehm (or something similar) and it is. These things are often (with almost any language) aspects of the implementation & deployment, and most mature languages have multiple answers as well. Is Python "compiled"? Well, with Pypy or Cython or etc. it is. (Or maybe it's always at least "compiled" to byte codes run by a slow byte code interpreter.) Etc., etc. I think your standards for "simplicity" or univalence may be, as @SolitudeSF alluded to, unsatisfied by even prog.lang's you like (which you gave no concrete examples of).

Re: Patten Matching in Nim

#46
post #13
post #9

The amount of power that Nim has is absolutely obscene. I don't really have a good use-case for it right now, but it's a language that I know I'd enjoy if I got into it.

Does Nim solve the "what color is your function" problem?

Nim attempts to at least partially resolve this via the {.multisync.} pragma. It's functionally equivalent to {.async.} but means that the compiler also generates code for synchronous IO, this is what enables the stdlib to implement an HttpClient and AsyncHttpClient with little to no duplication.

Of course, the downside is that it relies on library authors to use this mechanism.

Re: Patten Matching in Nim

#47

I played with Nim a little bit, loving it for a while, and I quickly ran into the same issue I had with Julia, which was that I had trouble staying in the basic language . Both Nim and Julia's documentation, and many modules/imports/includes/whatever of those languages, immediately jump to "holy shit we have macros! Importing this module changes the syntax! Isn't that awesome?!" And I'm like, no, it's not awesome. Ne…

In all non-trivial codebases you have to learn how other people implemented something. It can be easy or take time depending on the how well it's written.

Macros are not different than functions: one can create readable or crazy spaghetti code in any language.

If you find a codebase full of unreadable macros it's not different than any other type of bad code: stay away from it or simplify it.

Personally, I'm yet to find a macro that makes the code less readable or more difficult to understand.

Re: Patten Matching in Nim

#48
post #27

Earlier quoted context omitted.

I tried out Nim. My first reaction was that I absolutely loved it. Second reaction was when I needed to look up how to do something and I realised that the docs aren't amazing. Third reaction was when I first ran into a problem I couldn't find anything on Google, and had to post on the Nim forums. The forums were great but there's an inevitable time lag between posting and getting a response. Then I started looking a…

> I ended up appreciating the guardrails it provides around safety that Nim doesn't... fwiw this is plain wrong, a garbage collected language in general is memory safe, just with a different scheme (a garbage collector) than rust's memory model. Both are better options from one that is unmanaged. I hate to attract negative attention from rust fanboys. But none likes Rust's borrow checker and hopefully language develo…

[deleted]

Re: Patten Matching in Nim

#49
post #27

Earlier quoted context omitted.

I tried out Nim. My first reaction was that I absolutely loved it. Second reaction was when I needed to look up how to do something and I realised that the docs aren't amazing. Third reaction was when I first ran into a problem I couldn't find anything on Google, and had to post on the Nim forums. The forums were great but there's an inevitable time lag between posting and getting a response. Then I started looking a…

What exactly is wrong with Nim's docs, in your opinion? They seem fine after perusing the ones at the following link a bit just now: https://nim-lang.org/documentation.html

IMO, while the descriptive department is passable, the docs seriously lack on the prescriptive side. What I found extremely helpful when dabbling with Rust, is that every module in STD docs has a pretty comprehensive general description and usage suggestions, often accompanied by some examples. It really works great lifting the curse of knowledge for the uninitiated and it doesn't get in the way when the reader already knows what he's after as thse introductions are easily skippable.

Re: Patten Matching in Nim

#50

Earlier quoted context omitted.

One of my knocks against it is using white space for scoping/blocks a la Python. While it may be great for beginners or for short scripts, over time it becomes a real pain when refactoring. Editors mess up indentation all the time when copying and pasting. You only have to inadvertently make a statement either incorrectly part of, or not part of an if a few times, before you become leery of that choice.

I've been coding for 14 years and I've never had a "whitespace" problem. This just seems like a nitpick from nitpickers. Coded in C#, python, go, ruby, elixir, nim, rust, javascript, typescript. Not once felt this.

I run into this a lot with Python, where when I manually cut/paste some block, I have to go up and double check all the lines are in the right place, etc. because an autoformatter can't do it correctly and obviously like it can in C++, e.g.
Post reply on HN