News for hackers. Stuff that matters.
Re:Advent of Nim by rijoja on Thursday November 29, 2018 @07:03AM (#18559593)
Even though I haven't taken it out for a spin just yet, I've gotten a good impression of nim. Anybody out there who has tested that can say if my hunch is right or not?
Re:Advent of Nim by narimiran on Thursday November 29, 2018 @07:22AM (#18559663)
> I've gotten a good impression of nim. Anybody out there who has tested that can say if my hunch is right or not?

I've started using Nim couple of months before last year's Advent of Code, after I've been reading about Nim both here and on Reddit.

As a Python user, I was immediately drawn to Nim's elegant syntax, which looked to me like "ok, just copy-paste my Python code, and declare some variables, and voila: 10-100x faster Python!", which is 80% true. The remaining 20% were "this works in Python, why doesn't work in Nim?" questions, which were promptly answered by the great Nim IRC community. I soon realized that those differences are what makes Nim great, and I began to really like the language.

I decided to solve AoC 2017 in both Python and Nim [0] so I could directly compare my solutions. This was a great experience for me, and I've learnt a lot.

In the past year I started using/liking Nim more and more (I have used Nim even at my work (numerical calculations, before done in Numpy)). This year I'm gonna solve AoC solely in Nim.

From my experience, your hunch is right.

If you have any Nim questions, let me know.

[0] https://github.com/narimiran/AdventOfCode2017

Re:Advent of Nim by baldfat on Thursday November 29, 2018 @10:52AM (#18561046)
Thank you. That is the best answer to comparing languages I have seen by looking at your two codes. I never really thought of Nim as being that close to Python in syntax but seeing the two codes together I saw how you were able to achieve that and it was really insightful.
Re:Advent of Nim by alexeiz on Friday November 30, 2018 @04:49PM (#18573007)
For me, Nim feels closer to Pascal than Python. They even say so on the "features" page: "Pascal-inspired type sections for leaner definitions."
Re:Advent of Nim by aepiepaey on Thursday November 29, 2018 @08:33AM (#18560018)
Last time I was going to try it, I got sidetracked reading up on rules for identifier equality, prompted by noticing that the nim package bundled its own grep (nimgrep).

Basically, Nim ignores case (except for the first character) and underscores in identifier names, so the following is a valid Nim program and all those names refer to the same variable:

    var myVar = 1
    my_var = 2
    mYVAR = 3
    echo(myVAR)
Most people wouldn't actually write code like that, but I personally found it to be a turn-off.

More on this: https://nim-lang.org/docs/manual.html#lexical-analysis-ident...

Re:Advent of Nim by narimiran on Thursday November 29, 2018 @09:01AM (#18560164)
> I personally found it to be a turn-off.

I feel like this is mentioned (by the people who just glance over Nim) every time there is some discussion about Nim, and IMO it is blown way out of proportion.

In my cca year and half of using Nim, I not even once had a problem with the style insensitivity.

IMO, you (general you) shouldn't use `my_foo` and `myFoo` for different things, regardless if a language allows for it or not.

Re:Advent of Nim by JoeAltmaier on Thursday November 29, 2018 @09:04AM (#18560182)
I had an operating system with a parameter of a scalar process id, which in our parlance was spelled pidTarget. The documentation folk 'corrected' it in the manual to pIdTarget, which would mean a pointer to a target id.

Not hard to make up any number of examples where spacing or capitalization matter for good reason. They matter to humans; its just silly to make them not matter to the compiler.

Re:Advent of Nim by PMunch on Thursday November 29, 2018 @09:36AM (#18560406)
This is a reasonable concern, but after having used Nim for a couple of years I have never run into this as an actual issue. The benefit of being able to keep your entire program in one casing style outweighs these concerns. For that is the purpose of this style insensitivity, to allow you to use a library using snake_case in a project using camelCase and the other way around. And after having used Python with mixed case libraries I must say it is a good solution.

Now back to your concern of identifiers being read in different ways meaning different things. Once you know that this will be an issue you tend to think about it when naming your variables, and so it tends to not really be an issue. The thing is that once you get used to it you know that `pidTarget` and `pIdTarget` is the same thing, so you either relax you expectations, or you don't construct your names with this ambiguity. And besides, a "pointer to a target id" and a "scalar process id" probably don't share the same type, so the compiler should be catching that anyways if you ever used it wrong.

Re:Advent of Nim by tcoff91 on Thursday November 29, 2018 @11:05AM (#18561175)
The big issue for me is it interferes with code search tools. I like being able to use ripgrep to find all uses of an identifier. That becomes hard with style insensitivity.
Re:Advent of Nim by PMunch on Thursday November 29, 2018 @11:38AM (#18561479)
That is also a valid concern, with nimsuggest (and soon nimlsp) you will be able to easily find every instance in your editor (as well as rename them). For searching through files however nimgrep is probably your best bet, but that might break up your workflow. In my experience this hasn't been that much of an issue. Typically you write all your identifiers in the same style always, so most of the time you'll find what you need with just a simple grep.
Re:Advent of Nim by beagle3 on Thursday November 29, 2018 @11:20AM (#18561315)
well, yes, that's why nimgrep exists.

grep -i solves the case issue, and grep/ripgrep probably _should_ have a feature to ignore _ ; in which case you will be able to use them - but until then, nimgrep will do that work.

Re:Advent of Nim by tcoff91 on Thursday November 29, 2018 @06:04PM (#18565007)
It seems crazy to me that people are so annoyed that their libraries have different style that we have to have additional tooling to make code search simple for the end-user.
Re:Advent of Nim by dom96 on Thursday November 29, 2018 @07:46PM (#18565635)
You don't _need_ additional tooling. You can get by with just searching as normal, it's not as if people's code bases are filled with random conventions or random case variations...
Re:Advent of Nim by tcoff91 on Friday November 30, 2018 @01:07PM (#18571039)
style insensitivity WILL lead to typos that don't get caught. Someone will change the casing somewhere. Therefore you must always search with style insensitivity in mind.
Re:Advent of Nim by nimmer on Friday November 30, 2018 @02:15PM (#18571749)
Most people use completion anyways and it prevents this problem. Also, you can lint the code.
Re:Advent of Nim by beagle3 on Friday November 30, 2018 @09:36AM (#18569362)
Styles are religions, including - in some organizations - the threat of excommunication if you don’t practice the one style.

I don’t know how atheistic style looks, but Nim is style agnostic - everyone can practice their religion and they all get along. C, Python, and the real world - not so much.

Re:Advent of Nim by nickpsecurity on Thursday November 29, 2018 @02:16PM (#18562972)
"Not hard to make up any number of examples where spacing or capitalization matter for good reason. They matter to humans; its just silly to make them not matter to the compiler."

This one point is always worth considering when deciding on user-facing portions of technology.

Re:Advent of Nim by mratsim on Thursday November 29, 2018 @09:49AM (#18560522)
That's bad naming, if those had the same type, that would lead to subtle hard to track bug because a dev used one pid instead of pId.
Re:Advent of Nim by JoeAltmaier on Thursday November 29, 2018 @10:05AM (#18560662)
Not in any typed language. Its instantly called out as an error.
Re:Advent of Nim by alehander42 on Thursday November 29, 2018 @10:17AM (#18560776)
But it's so hard to read: I admit a good IDE might help, but maybe it's not bad to prevent this on lang level.
Re:Advent of Nim by mratsim on Thursday November 29, 2018 @10:31AM (#18560890)
that's why I said if those had the same type ;)
Re:Advent of Nim by weavie on Thursday November 29, 2018 @09:29AM (#18560353)
Common lisp also ignores case (sort of..it's a little bit more complicated). I've never found it to be a problem - apart from the compiler always uppercases my symbols when it reports to me, it feels a bit like being shouted at.
Re:Advent of Nim by weavie on Thursday November 29, 2018 @09:32AM (#18560377)
Forgot to add.. in common lisp everything is kebab-cased which makes case a lot less significant. Not sure what happens in Nim?
Re:Advent of Nim by mratsim on Thursday November 29, 2018 @09:47AM (#18560504)
kebab-case? Is that even a thing?
Re:Advent of Nim by fao_ on Thursday November 29, 2018 @10:21AM (#18560811)
It's actually easier on the hands than using `_`. As on a standard (us, uk, chinese, etc.) keyboard underscore requires a shift-press whereas minus/hyphen requires a single press. It's a small change but you'd be surprised how much of a difference it makes, given that tokens are a significant amount of all writing when programming.

Not to mention, in my opinion it's more aesthetically pleasing, but that's just me :)

Re:Advent of Nim by klibertp on Thursday November 29, 2018 @10:14AM (#18560748)
Sure, Lisps allow many more characters in the identifiers, including all traditional operators (makes sense, since the "operators" are just functions and they had to be defined somehow in the first place...) You get functions named like add-message! create-response/text bytes->string/utf-8 and so on. Kebab case refers to identifiers with words separated with minus sign, like some-class-member-doing-something etc. Some infix languages borrowed this, like Dylan and LiveScript, among others.
Re:Advent of Nim by Jach on Thursday November 29, 2018 @02:11PM (#18562929)
Common Lisp actually lets you use any string for an identifier if you wrap it in pipes, though you have to be a bit careful of casing in that case. Still for so many characters on the keyboard it's not needed to wrap which is so convenient as you illustrate.

    (let ((|hello world| 3)
          (|HELLO world| 4)
          (|こんにちは (jp)| 5)
          (|pi\|pe| 'piped)
          (|newlines
            work
            too| 6))
      (list |hello world| |HELLO world|
            |こんにちは (jp)| |pi\|pe|
            |newlines
            work
            too|))
    
    ; --> (3 4 5 PIPED 6)
Re:Advent of Nim by mhd on Thursday November 29, 2018 @10:04AM (#18560651)
Not as common, as it clashes with using '-' for subtraction, but as that's never been a problem for Lisp, it's quite common there. Perl6 went that way, too, despite having infix syntax. But hey, it's Perl, we're used to syntactical warts.
Re:Advent of Nim by weavie on Thursday November 29, 2018 @11:18AM (#18561299)
Ah.. I had wondered why it wasn't used in most other languages. Now, of course it seems obvious.
Re:Advent of Nim by mikepurvis on Thursday November 29, 2018 @10:27AM (#18560861)
Re:Advent of Nim by vram22 on Thursday November 29, 2018 @10:16AM (#18560766)
Sure it is. Think of what it looks like, and think of a skewer with kebabs on it ...

Search HN (box at bottom of page) for Perl6 and you will find many articles with references to kebab-case.

As mhd said, it's used in Lisp too.

Re:Advent of Nim by rbonvall on Thursday November 29, 2018 @11:30AM (#18561406)
I have written code to traverse matrices in which I use indices `I` and `J` to iterate over submatrices and indices `i` and `j` to iterate over individual values in a submatrix. Upper/lower case add a new dimension to name things that are related but different.

But is not a deal breaker for me. If the language doesn't let me I can use `ii` or `i2` or whatever.

Re:Advent of Nim by narimiran on Thursday November 29, 2018 @11:36AM (#18561454)
> I have written code to traverse matrices in which I use indices `I` and `J` to iterate over submatrices and indices `i` and `j` to iterate over individual values in a submatrix.

Please notice that the first letter in Nim is case-sensitive, so `I` != `i`, and you can continue use your conventions.

And before some new comment starts bashing that, I think this is a must so you can differentiate your types, written in PascalCase, from your variables, written in camelCase.

Re:Advent of Nim by mictlan_ on Thursday November 29, 2018 @02:58PM (#18563392)
A better rule would be a unique definition of: - "myVar" - "myvar" - "my_var" - etc inside a scope, once you define the first.
Re:Advent of Nim by anentropic on Thursday November 29, 2018 @11:18AM (#18561293)
yeah but if you do that and the language lets you get away with it... ugh

I did not know this about Nim and does also seem quite a big turn off and a bit of a WTF decision

I have never coded any Nim, just read about it though :)

Re:Advent of Nim by mclehman on Thursday November 29, 2018 @08:20PM (#18565802)
I've never used Nim either (mostly C/Perl6/Clojure), but all I hear when this gets brought up is that I would finally be able to use a consistent style for all code I write, regardless of whether or not I personally implemented everything I'm using.
Re:Advent of Nim by anentropic on Friday December 07, 2018 @10:57AM (#18628682)
thinking more about it...

I guess the intention is NOT to let you carelessly use Myvar, MyVar and myvar willy-nilly in your code, as I had first imagined

I assume the intention is to PREVENT you from deliberately defining those names as different vars, which would be confusing

So, on reflection, maybe it is not such a WTF

Re:Advent of Nim by ziotom78 on Thursday November 29, 2018 @10:33AM (#18560902)
OTOH, because of the same rule, the following abomination is legal in C++, but its analogous in Nim would trigger a compilation error:

    int main() {
        int myVar = 1;
        int my_var = 2;
        int mYVAR = 3;
        int myVAR = 4;
        // ...
    }
I have seen a few codes in my life where complex routines with multiple nest levels had variables with names "x", "X", "_x", etc.
Re:Advent of Nim by nimmer on Friday November 30, 2018 @02:19PM (#18571786)
Yes, and not being able to have two different variables in the same code named "cryptotoken" and "crypto_token" is a feature.

It saved me few bugs already.

Re:Advent of Nim by mtinkerhess on Thursday November 29, 2018 @02:16PM (#18562970)
A lot of people are replying saying this isn't a big deal in practice. I believe them but I'll chime in and say this is also a dealbreaker for me.

I would love to find a language for game / engine development that's as performant as C++ and as easy to use as C# or Python, but this issue scares me. If I search for a variable using any of my existing plain text search tools, I expect to find the variable. It makes me think that this isn't a language that's meant to be used by large teams on large, long-lived codebases.

Re:Advent of Nim by dom96 on Thursday November 29, 2018 @07:54PM (#18565676)
> If I search for a variable using any of my existing plain text search tools, I expect to find the variable.

I think you are over-estimating how inconsistent Nim code typically is. I have been coding in Nim for a very long time and I personally just use case insensitive search (which I use for all languages anyway).

It's easy to tell from context what the identifier will be. If the code base is snake_case then I search for `foo_bar` if not then I search for `fooBar`. I cannot remember a single time this has failed me, and even if it does then the worst case is you'll need to search for the other alternative. There is really no trouble here and I feel like a lot of people, when they see this feature, worry too much because it's so different. Please please please reconsider, I know it's a strange feature and it doesn't feel worth it, but it really isn't a problem at all.

Re:Advent of Nim by mtinkerhess on Thursday November 29, 2018 @09:30PM (#18566116)
I totally hear you that this is not a huge inconvenience in practice. Part of me is worried that it becomes more and more of a problem the bigger the project gets.

But mostly, it just seems like a really weird call to make for the language. There are real disadvantages to it -- I can't really rely on my search tools. So that... when you're using a library you can refer to its identifiers using a different capitalization convention if you want to--why is that important?

I don't know, it just seems like a really weird call to make, and if that's one of the first things I've learned about the language it makes me think there are probably plenty of other weird things like it.

Re:Advent of Nim by dom96 on Friday November 30, 2018 @05:39AM (#18568133)
> Part of me is worried that it becomes more and more of a problem the bigger the project gets.

But why? I personally haven't experienced this having worked in a big Nim project. I'm really curious why you think a bigger project could become burdened by this.

> There are real disadvantages to it -- I can't really rely on my search tools.

I disagree. You can rely on your search tools, as I've demonstrated in my previous reply. I feel like you're thinking of the worst case scenario and convincing yourself that it's very common. It simply isn't, people don't create crazy identifiers, why would they?

> So that... when you're using a library you can refer to its identifiers using a different capitalization convention if you want to--why is that important?

It's important for consistencies sake. In the real world developers prefer different conventions, so you undoubtedly run into a library which uses a convention that is different to your own. It's nice to be able to call that libraries functions in the same convention as your own.

I agree that it's not a huge advantage, which is why I created this thread on the Nim forum recently: https://forum.nim-lang.org/t/4388. My main reason to consider getting rid of it though is people like yourself who dismiss the whole language because of this small feature :(

Re:Advent of Nim by Recurecur on Wednesday December 05, 2018 @02:09PM (#18611395)
I'd take a long, hard look at Julia if I were you.

It has a lot in common with Nim, but is backed by a much larger community. Its FFI interface for C functions is faster than...C.

If Julia doesn't fit your use case(s), Rust might also be worth a look. What worries me about Rust is that it looks to me to have an awful lot of boilerplate that detracts from readability.

Re:Advent of Nim by alehander42 on Thursday November 29, 2018 @03:02PM (#18563419)
You aren't supposed to use different styles in the same codebase: Nim is going to have a tool that can enforce this soon.
Re:Advent of Nim by pelario on Thursday November 29, 2018 @08:46AM (#18560082)
Can somebody explain why would anyone consider this a good idea? I'm honestly puzzled.
Re:Advent of Nim by dymk on Thursday November 29, 2018 @09:30AM (#18560355)
The goal was to make it so library authors could write Nim in their own "style" - some prefer snake_case, others prefer camelCase, maybe PascalCase.

If you had your own preference one way or the other, you could call a library's `snake_case(foo)` function as `snakeCase(foo)` instead, and pretend that the library matched your own personal style.

Of course, this isn't very useful in practice, and makes simple things like grepping for identifiers or Googling a function that much harder. Tools for refactoring also suffer.

What's better is having a single style guide enforced by ordained tooling; e.g. PEP 8 for Python, Prettier for JavaScript, or gofmt for Go.

Re:Advent of Nim by PMunch on Thursday November 29, 2018 @09:44AM (#18560481)
In a perfect world, yes. But having worked with Python I must say not all Python libraries are PEP 8, and I've more than once ended up with a strange mix of styles.

Nim on the other hand takes a different approach, don't trust anyone else to keep things the way you like it, but rather allow you to use it however you want. This means that if some inexperienced Nim programmer who didn't care to look at the NEP 1 style guide (yes Nim also has a style guide, which says Nim prefers camelCase), but nonetheless wrote an interesting library could still see his library used by others.

Re:Advent of Nim by dom96 on Thursday November 29, 2018 @09:48AM (#18560512)
Something else to keep in mind is that Nim also has it's own version of gofmt in development, it's called nimpretty.

If everyone is using this tool anyway then style insensitivity will not be a problem, and for those cases where some library uses snake_case instead the code formatter will still be able to format your code completely consistently even if you're using that library. There is no way that gofmt or any other language's code formatter can do that.

Re:Advent of Nim by dymk on Thursday November 29, 2018 @10:46AM (#18560984)
Even if somebody deviates from a style guide, the library is still usable. The consumer might just need to use a casing convention they're not using elsewhere.

This is such an incredibly small inconvenience, I have no idea why the Nim language would choose to make identifiers case/_ insensitive. Basic refactoring tools become unnecessarily more complicated.

Just searching for an identifier is a complex regex instead of what should just be ctrl+f.

Re:Advent of Nim by beagle3 on Thursday November 29, 2018 @11:27AM (#18561388)
Nim's roots are firmly in Pascal and Ada, which are both case insensitive; Every editor supports case insensitive search so I don't understand what your problem is with case insensitive identifiers.

"Basic refactoring tools" would just need to replace the case sensitive search with insensitive. Every editor knows how to do that.

If you're talking about the underscore and first letter rules - yes, they're different, and that's why nim includes nimgrep, and support was added for just about every editor under the sun already (Emacs, VSCode, Vim, Sublime, TextMate at the very least). It's still Ctrl+F

Re:Advent of Nim by PMunch on Thursday November 29, 2018 @11:42AM (#18561511)
I find it a big nuisance to use different casings in my code, but obviously people are different. Most of the type you won't be using the style insensitivity though, so for the most part a simple case-sensitive search will give you exactly what you are expecting. For more complicated things though you have nimgrep, and also nimsuggest (and soon nimlsp) which gives you editor support for finding and renaming identifiers. It really is a much smaller issue than people think it is.
Re:Advent of Nim by mikepurvis on Thursday November 29, 2018 @10:30AM (#18560880)
Prior to Py3, not even the entire _standard library_ was PEP8:

https://docs.python.org/2/library/queue.html

Before 2.6, the situation was even worse, with camel-case methods in the threading module:

https://docs.python.org/2/library/threading.html

Re:Advent of Nim by ansible on Thursday November 29, 2018 @11:46AM (#18561551)
> The goal was to make it so library authors could write Nim in their own "style" - some prefer snake_case, others prefer camelCase, maybe PascalCase.

That's something that would have appealed to me years ago, but now not so much.

In 2018, I want all the libraries, and all the code I ever look at in a language to follow the same style and naming conventions. If you adapt yourself to that, my belief is that will aid comprehension in the long term.

So I appreciate the language communities which have strong conventions which are followed by the majority, and are encouraged / enforced by the tooling. All hail gofmt and rustfmt!

Re:Advent of Nim by citycide on Thursday November 29, 2018 @11:32AM (#18561420)
> Last time I was going to try it, I got sidetracked reading up on rules for identifier equality

It's way too easy to ignore (or even embrace) the identifier equality rules in Nim to make this the hill you die on. My story's very similar to other responses - I've been using Nim for quite a while and these identifier rules have never been an issue.

I strongly suggest anyone hung up on this monster under the bed try Nim anyway as it's really pleasant to use. It's sad that all Nim's benefits are sometimes drowned by mostly unfounded hangups on this identifier thing.

Re:Advent of Nim by aepiepaey on Tuesday December 04, 2018 @01:59PM (#18602525)
Considering how common it seems to be, it wouldn't be fair to call it "unfounded".

Anyway, don't worry: I didn't die on that hill. I've had the opportunity to spend some more time on Nim since.

There was a set amount of time available to spend on Nim at that point, and all that time went into finding out why nimgrep exists in the first place, then reading up on the background.

It didn't help that all nimgrep's documentation had to say on the matter was "Nimgrep has particularly good support for Nim's eccentric style insensitivity", which doesn't really tell you anything unless you already know about Nim's style insensitivity.

Re:Advent of Nim by BoppreH on Thursday November 29, 2018 @08:45AM (#18560079)
I personally think it's a great idea. Much better than having a code base with mixed camelCase and snake_case because a library didn't follow the language convention.

I've seen people write wrappers just to fix casing.

Re:Advent of Nim by joelthelion on Thursday November 29, 2018 @08:47AM (#18560092)
A much better solution is to have a language-wide style guide, with a tool such as "go fmt" to enforce it.
Re:Advent of Nim by alehander42 on Thursday November 29, 2018 @08:55AM (#18560125)
Interop with C/JS: you can't control all identifiers, because you can reuse a rich ecosystem of other language libs: you can't force their names to change

EDIT: you can still change them in importc pragmas, but this still seems less nice to me.

Still, you can reuse Nim libs even if they don't follow nep1: one can still use nimpretty/gofmt for his own codebase.

Re:Advent of Nim by nimmer on Thursday November 29, 2018 @10:16AM (#18560760)
I've been using Nim for years and never ran into a collision between different variables due to style insensitivity.

Using name completion in my editor is enough to keep the naming consistent. Try the language for a month before deciding.

Also, the survey indicates that very few people are turned off by this feature:

https://nim-lang.org/blog/2018/10/27/community-survey-result...

Re:Advent of Nim by h1d on Thursday November 29, 2018 @12:00PM (#18561672)
Maybe because only enthusiasts are currently using it?
Re:Advent of Nim by thatsaguy on Thursday November 29, 2018 @07:18AM (#18559652)
Nim is actually great. The syntax is streamlined and you can pick it up in a few hours if you have some basic experience with python.

Because it's effectively a transpiler and it's way less opinionated than (say) Rust, I managed to use nim in embedded controllers without any special support from the compiler.

Nim suffers because it doesn't have the big push of a corporation such as Mozilla behind.

Re:Advent of Nim by rijoja on Thursday November 29, 2018 @07:23AM (#18559668)
Cool! I'm working on a project that uses javascript and a C backend so it actually might be a good fit for me.
Re:Advent of Nim by mratsim on Thursday November 29, 2018 @08:03AM (#18559857)
Here is an example of such for neural network training[1]:

- Nim JS for browser display

- Nim C as a backend

[1]: https://github.com/Vindaar/NeuralNetworkLiveDemo

Re:Advent of Nim by alehander42 on Thursday November 29, 2018 @08:13AM (#18559908)
It might be indeed: e.g. I've implemented validation for game moves before for a web game, and reusing everything on the backend and frontend was nice
Re:Advent of Nim by vram22 on Thursday November 29, 2018 @10:21AM (#18560816)
In what ways is it less opinionated than Rust?
Re:Advent of Nim by jibal on Thursday November 29, 2018 @08:10AM (#18559890)
" A source-to-source compiler translates between programming languages that operate at approximately the same level of abstraction, while a traditional compiler translates from a higher level programming language to a lower level programming language."

In other words, Nim is not a transpiler, it's a compiler that outputs C or Javascript. But the difference is just in terms of the readability and modifiability of the output. For the purpose of using it in embedded controllers, the difference doesn't matter, it's the fact that it generates C code that is of value. And yes, Nim is vastly less "opinionated" than Rust, thank goodness.

Re:Advent of Nim by dom96 on Thursday November 29, 2018 @08:33AM (#18560019)
It really depends on whether you think Nim and C are on the same level of abstraction. If they aren't then yes, Nim is a compiler.

I personally believe that they aren't. But I know of a lot of people who disagree.

Re:Advent of Nim by jibal on Friday November 30, 2018 @03:43AM (#18567662)
It depends on whether the C code generated by Nim is at the same abstraction level as the Nim source code ... clearly that's not the case, because Nim is using C as an assembly language. People acting in bad faith can down vote me all they want (I know that wasn't you, Dominik; you're a great guy) but that's what "transpiler" means. Coffeescript is a transpiler; Nim is not at all ... it does a vastly more complex transformation of the Nim source in order to generate that C code ... as you, Dominik, are especially well aware.

And there are people who will disagree about just about anything, because they are ill informed or have poor judgment or are dishonest (looking at you, White House) ... the mere fact that there are people who disagree about something is not of significance.

Re:Advent of Nim by dom96 on Friday November 30, 2018 @05:48AM (#18568170)
> I know that wasn't you, Dominik; you're a great guy

Of course not :)

Yeah, to me Nim is a compiler. However, I can see why people might refer to it as "transpilation" if we are talking Nim->JS. But yeah, please don't call Nim a transpiler, it makes us Nimians all sad.

Re:Advent of Nim by rohansingh on Thursday November 29, 2018 @10:03AM (#18560644)
I tried to use Nim in an embedded context (ESP32). Since one of the bullet points is that it "compiles to C", I thought it'd be a good option.

In practice, even once I was able to compile basic Nim, there were a lot of glibc and other POSIX dependencies for any of Nim's standard libraries, some of which weren't available in ESP-IDF.

That's totally fair, but many of those dependencies aren't available when compiling to JS either, though, so I was surprised. In the end, delving into the code I found that a lot of stuff was gated behind the equivalent of "platform=JS" switches throughout the stdlib. It seemed like adding support for another platform would be a major pain.

This was all preliminary investigation and I didn't reach out to the Nim community, so perhaps I missed something. Maybe this kind of portability isn't even a goal for Nim. It would definitely be nice to have, though.

Re:Advent of Nim by mratsim on Thursday November 29, 2018 @10:36AM (#18560924)
You need to pass --gc:none when compiling so that the compiler warns you when you try to use a garbage collected type and instead of the stdlib, use the SDK facilities.

Here are some libraries for embedded you can get inspiration from[1]:

- msp430f5510 - Run Nim on MSP430f5510 micro-controller (6KB of RAM).[2]

- stm32f3 - Run Nim on STM32F3 micro-controller (16KB of RAM).[3]

- ardunimo - Nim wrapper for Arduino + LinkIt ONE SDK by Mediatek.[4]

- ardunimesp - Nim wrapper for Arduino ESP8266 framework + A tool for flash, compile and make the nim project into an Arduino project.[5]

[1] https://github.com/VPashkov/awesome-nim#embedded

[2] https://gitlab.com/jalexander8717/msp430f5510-nim

[3] https://github.com/mwbrown/nim_stm32f3

[4] https://github.com/gokr/ardunimo

[5] https://gitlab.com/NetaLabTek/Arduimesp

Also, yes abstracting a platform is a lot of pain but Nim accepts PR even for niche platforms like Haiku, Genode and Nintendo Switch.

Also with the upcoming destructors, the standard library will be GC-free so much more will be usable on embedded.

Re:Advent of Nim by rohansingh on Thursday November 29, 2018 @11:55AM (#18561638)
Yeah, I tried --gc:none. After some playing around, I ended up with:

  --gc:stack
  --header:"nim.h"
  --os:standalone
  --noMain
  --genDeps
In the end I got Nim code to run and was able to do a "hello world". As a hack I also used -d:android to trigger some conditionals that reduced the reliance on various dependencies. But it wasn't enough to be usable, and it was a bit unfortunate to have to do that.

Looking at those projects you linked though, clearly I didn't try hard enough! Great to see that people have had success.

Re:Advent of Nim by dancek on Thursday November 29, 2018 @01:08PM (#18562286)
Thanks for sharing your experience. I read another comment about Nim being nice on microcontrollers because it compiles/transpiles to C, and my first thought was ESP32. I've written Rust for STM32 and MSP430 and it's awesome. ESP32, OTOH, seems like a nice platform but doesn't have LLVM support so C and MicroPython are pretty much the only options.
Re:Advent of Nim by rohansingh on Friday November 30, 2018 @08:22AM (#18568846)
Rumor is that Espressif is actually working on LLVM support.
Re:Advent of Nim by dancek on Friday November 30, 2018 @12:15PM (#18570568)
At least they were recruiting with that angle some months ago. I'm assuming it'll take a while even if all goes well, though.
Re:Advent of Nim by curioussavage on Thursday November 29, 2018 @04:29PM (#18564214)
I really enjoy nim. Using it in two projects now. I write Python and typescript at work so nim gives me the syntax I like from python with the type safety I miss from typescript plus cool stuff like macros.
Re:Advent of Nim by qaq on Thursday November 29, 2018 @07:17AM (#18559648)
played with it a bit the lang is really nice but lib support for things I needed was lacking. e.g. async PostgreSQL driver. Has good c interop though.
Re:Advent of Nim by tokai on Thursday November 29, 2018 @07:20AM (#18559657)
Re:Advent of Nim by qaq on Thursday November 29, 2018 @07:31AM (#18559711)
you seriously proposing to use a db driver in prod that has 1 contributor and was abandoned more than a year ago?
Re:Advent of Nim by mratsim on Thursday November 29, 2018 @07:50AM (#18559798)
Please note that cheatfate is one of the most prolific Nim contributors and is also working in Nim as a full-time job at Status[1]. He is also the main author of an asyncdispatch hardfork[2]. I.e. any issue you might have with the lib can be raised and addressed fast.

Disclaimer: he is also my colleague.

[1]: https://github.com/status-im?utf8=&q=&type=&language=nim

[2]: https://github.com/status-im/nim-asyncdispatch2

Re:Advent of Nim by qaq on Thursday November 29, 2018 @07:55AM (#18559817)
Good to know this prob a workable option for non-critical path tools then.
Re:Advent of Nim by tokai on Thursday November 29, 2018 @07:39AM (#18559750)
I wasn't proposing anything. I dropped a link with relevant content to your post. It was as much aimed at readers of your comment as it was aimed at you. Please turn down your scorn.
Re:Advent of Nim by jamespo on Thursday November 29, 2018 @07:44AM (#18559777)
Maybe you could contribute to it
Re:Advent of Nim by qaq on Thursday November 29, 2018 @07:52AM (#18559808)
Pretty far from my area of expertise. BTW. I have 0 expectation that someone has to solve my problem but when looking at a lang to me the minimum req. are good PG support and decent http lib which is obviously not the requirements people actively working on Nim have.
Re:Advent of Nim by mratsim on Thursday November 29, 2018 @08:21AM (#18559956)
Nim forum is written in pure Nim[1] and is using httpbeast[2] as a backend.

[1]: https://github.com/nim-lang/nimforum

[2]: https://github.com/dom96/httpbeast

In terms of features it's powerful enough to build a Discourse-like forum enough. In terms of performance it's very well performing in the TechEmpower benchmarks[3] it is competing in. It even grabbed first place on JSON serialization on Cloud hardware.

[3]: https://www.techempower.com/benchmarks/#section=data-r17&hw=... and https://forum.nim-lang.org/t/1152#27100

Re:Advent of Nim by qaq on Thursday November 29, 2018 @10:13AM (#18560736)
OK english is not my native lang so maybe I am not formulating things clearly I did not try to suggest that nim does not have good http lib. I was just saying my 2 core requirements good http lib and high quality mature PostgreSQL driver. Nim has good Http lib Nim does not have async PG driver that I would feel confident using in prod.
Re:Advent of Nim by vram22 on Thursday November 29, 2018 @10:24AM (#18560839)
The D forum is also written in D (it's called DFeed, IIRC), and it's fast (anecdotally).
Re:Advent of Nim by Boxxed on Thursday November 29, 2018 @08:01AM (#18559847)
I found the same thing. There are oddities in the non-async library too -- for example, rows are returned as a tuple without any column metadata, so you can't do a "select *" because you don't know the column order. I think all types get stringified too, which is weird.

The core language is interesting, but like the standard library has an odd edge here and there.

Re:Advent of Nim by qaq on Thursday November 29, 2018 @10:14AM (#18560753)
I am sure it will be addressed as ecosystem matures. In general lang is very elegant and I would love to use it when it matures.
Re:Advent of Nim by gameswithgo on Thursday November 29, 2018 @07:44AM (#18559776)
I enjoyed it quite a bit while playing with it about a year ago. The compiler had some bugs and the language spec had some rough edges that turned me off a bit, but I've also noticed in the year since that most (all?) of the issues I ran into got fixed. So that is promising! They have gotten a bunch of funding since then too so progress may accelerate.