News for hackers. Stuff that matters.
Re:Learning Programming with Nim by germandiago on Thursday June 14, 2018 @11:29PM (#17317336)
> On the otherhand, the language has no personality that you get your head around

I do not get this point. I use D as a C++ improvement (which is what it was since the beginning) and I can do from functional, to OOP to structured or generic programming. No personality? You mean it does not favor any paradigm? That is another of the reasons why I chose it. By this measure, Nim is another non-personality language: the package offers the same things -> soft real-time gc, generic, structured and OOP (with Nim Style programming), metaprogramming. Should I say that Nim has no personality and conclude it is not useful? Nim is not useful due to "metaproblems" -> tools, maturity, worse interoperability than D. I do not say the language is not nice, I just say that it is more complicated to get things done with it from a perspective of someone looking for something that can work. Also, following Python makes it for very nice-looking code, but I am not sure it was the right decision from a social point of view (more people know C/C++ than know Python).

> For example, class-oriented programmers will get at least an intial shock, when they realise that private class members are public witin a module

I consider that a design mistake, but that does not preclude powerful metaprogramming or superior interoperability, which are far more important to my use case.

> Then, you have the issue of class instances being able to share mutable data.

I make primarily use of structs and all gc stuff and mutability problems disappear.

> I personally do not see the benefit for experienced programmers to switch from a well supported, well maintained, mainstream langauges, to D

The case for C++ is still very strong for me. But try to get good compile times and do something along the lines of static if (I do not mean only if constexpr in C++ with templates, try to avoid macros for config if you want and you will see, or add a conditional member to a class, or simulate something like version, or generate code without messing with macros)

> In the end, there is nothing in D that really changes the nature of programming.

That is a fair opinion, but I can say that in D there are these small nice things that I value in day-to-day programming like static if (a powerful one, not one that is in the middle between useful and full-featured), overloading opDispatch for forwarding, fast compile times and a module system. The faster compile-times are really, really something that makes more of an impact, maybe, than everything else.

I understand your point, D has nothing "revolutionary". D is not revolution, it is evolution. But D is targeted at doing and using techniques that have been useful for years (and not experimental) easier and convenient: from memory allocation control to gc-free programming, immutability or better interoperability (something that should not be underestimated when using older code bases). I really think that people that see nothing "new" in D should try and see how the full package works together. They will be surprised. And they will also be surprised at how much of the older techniques, in improved versions, they can use. Techniques that have been useful for decades, not experiments of the last FP trends or experiments for which drawbacks are not well known.

I used to think things along the lines you say. I still use C++ mainly, but, when I have another chance, I will insist on D a bit more. I think it is worth the time.

> It's all the stuff we already know, all wound up into one big monstrosity, that lacks any real supporting ecosphere.

That is precisely the strong point of it. It is evolution, not revolution. Did anyone discover lately a better general programming paradigm suddenly that makes all the other obsolete? Not AFAIK. Packaging things in familiar ways has real advantages of lowering the learning curve or figuring out more easily how to interoperate with older code bases. As I said before, that should not be underestimated if you really want to get things done and deliver stuff. If you are just toying around maybe you enjoy more something more revolutionary. But if I have to get things finished, I would bet on D rather than Nim or Go for most use cases.

Re:Learning Programming with Nim by dom96 on Friday June 15, 2018 @06:07AM (#17318653)
You keep repeating the line that D is far more interoperable than Nim. Did you miss my reply below? Or did you simply not believe me and downvote it?

Once again. Nim is superior to D in terms of interoperability with C, C++, and Objective C because Nim can compile to either of those languages. For C++ interoperability this is a huge benefit.

I'd love to hear why you disagree if you do disagree. Otherwise please give Nim a try and stop spreading this as a disadvantage of Nim.

Re:Learning Programming with Nim by germandiago on Sunday June 17, 2018 @12:03PM (#17332922)
> You keep repeating the line that D is far more interoperable than Nim. Did you miss my reply below? Or did you simply not believe me and downvote it?

I did not downvote anyone unless it was an accident :)

> Nim is superior to D in terms of interoperability with C, C++, and Objective C because Nim can compile to either of those languages.

I did not try myself. Well, I did not try Nim to the level I tried D, starting bc I know C++ better than D, though I also know quite a bit of Python (my "second" language).

I have a question, though, about interoperability: you can output Nim code to C++, and mix it. Fair point. But that would be useful to integrate my Nim code into C++ (C++ being the "driver" app). What about the other direction where I can consume C++ from Nim? I have no idea and I ask this question with the best of the intentions :) You thought very bad about me and the downvotes before.

Re:Learning Programming with Nim by dom96 on Sunday June 17, 2018 @01:18PM (#17333255)
> I have a question, though, about interoperability: you can output Nim code to C++, and mix it. Fair point. But that would be useful to integrate my Nim code into C++ (C++ being the "driver" app). What about the other direction where I can consume C++ from Nim? I have no idea and I ask this question with the best of the intentions :)

I was actually talking about it from that direction, i.e. using C++ libraries in Nim. You can wrap pretty much any C++ feature in Nim: destructors, namespaces, you name it. Because Nim compiles to C++ it can interface with it incredibly well.

Happy to answer any more questions in case I'm not clear.

> You thought very bad about me and the downvotes before.

Apologies. I just saw you reiterating the line I challenged without replying to me and was wondering what happened. Was just asking, not blaming :)

Re:Learning Programming with Nim by germandiago on Sunday June 17, 2018 @11:56PM (#17335938)
Yes, I am genuinely interested. So I am going to ask a bit more. I am open to new and better tools :)

> I was actually talking about it from that direction, i.e. using C++ libraries in Nim. You can wrap pretty much any C++ feature in Nim: destructors, namespaces, you name it.

Is there any documentation about how to wrap my C++ code into Nim? I do get I can generate C++ from Nim, but I am not sure how it would look to use C++ from Nim. In D for me it is quite clear (with extern (C++) and there is a clear mapping for interfaces and other things. I do not need anything spectacularly fancy, just smooth. Y' know, I am a person who likes to finish things without getting too lost on the details.

You also mentioned many people consider Nim "production-ready". My question here is, if I start to try it, how many breakages can I expect? 4-5, in the tens? Until version 1.0 I mean.

And my last question: how does it compare to D if I have to:

- use a well-mantained GUI library in at least one system (multiplatform would be a big plus)

- how mature is the standard (and other libraries also if that is easy to add) library for: json handling, binary serialization, algorithmic code (a la range-v3 or ranges in D. Something along the lines of python iterators, functools, comprehensions and itertools also ok).

- would I be able to use Nim in embedded if I do a port of some software? Namely, would I be able to remove the GC?

One thing that worries me is that I am much more familiar with metaprogramming in C++ and D's metaprogramming is much closer than Nim's I guess. If you could refer me to good (as in up-to-date) Nim style I would highly appreciate it, specially in the areas of how to manage runtime polymorphism and metaprogramming with an eye on generative programming (basically I want to generate a bunch of things from 3 or 4 basic building blocks in arbitrary combinations).

Thanks for your time!

> Apologies. I just saw you reiterating the line I challenged without replying to me and was wondering what happened. Was just asking, not blaming :)

No problem, I just did not mean to make anyone offended :)

Re:Learning Programming with Nim by dom96 on Tuesday June 19, 2018 @06:02AM (#17345175)
> Is there any documentation about how to wrap my C++ code into Nim?

Here is some docs: https://nim-lang.org/docs/manual.html#implementation-specifi...

> My question here is, if I start to try it, how many breakages can I expect? 4-5, in the tens? Until version 1.0 I mean.

Depends which features you are using. The newer features (concepts for example) will likely have more breakages than the rest of the language. We already have a lot of code written in Nim and a book published (which we are committed to keep compatible with 1.0) so breakages should be minimal (unforeseen circumstances of course may happen).

> how does it compare to D if I have to: > > - use a well-mantained GUI library in at least one system (multiplatform would be a big plus)

I'm not sure about the status of GUI support for D. Nim has bindings to GTK/QML/libui and some other more experimental GUIs rendered using pure OpenGL (nimx). They are all cross-platform (although GTK on macOS is a PITA).

> - how mature is the standard (and other libraries also if that is easy to add) library for: json handling, binary serialization, algorithmic code (a la range-v3 or ranges in D. Something along the lines of python iterators, functools, comprehensions and itertools also ok).

JSON handling is very mature.

I don't think we have binary serialisation in the stdlib.

Algorithmic code - sequtils is what you're after I guess: http://nim-lang.org/docs/sequtils.html

> - would I be able to use Nim in embedded if I do a port of some software? Namely, would I be able to remove the GC?

Sure, but you won't be able to use a lot of the stdlib.

> One thing that worries me is that I am much more familiar with metaprogramming in C++ and D's metaprogramming

I suppose Nim by Example is a good place to look, it has some good metaprogramming examples: https://nim-by-example.github.io/

Also my book has a chapter on metaprogramming :) https://book.picheta.me/

Hope that answers your questions!

Re:Learning Programming with Nim by germandiago on Thursday June 21, 2018 @01:45PM (#17367481)
I must say that, even if unfamiliar to me, I am quite impressed about the C++ interoperability :)
Re:Learning Programming with Nim by germandiago on Thursday June 21, 2018 @01:41PM (#17367424)
Thanks for all the info! Really grateful :)