With this video, i start a new video series on Nim's Metaprogramming capabilities. In this video i go trough all of Nim's Metaprogramming capabilities and demonstrate them in a beginner friendly manner.
Feedback is appreciated.
I'm someone new to nim and I've never read anything about the metaprogramming side of Nim. I dunno if you want feed from a beginner, and I dunno if I'm too late, but here it is just in case...
This video was really good and interesting. I loved how I could copy & paste from your code file you linked to, to try things out myself (maybe it's a good idea to mention that file at the beginning). I'm glad I watched the video - thank you! I liked how you said at the end that simpler is better, and that the complex stuff shouldn't be used (just because it can) when a simpler way can be used, and so it should be approached in this order: normal procs generic procs templates macros (again maybe this should have been mentioned at the start)
For Generics, I'm left a bit confused as why this the more complicated form is used: proc sumGenericConstrainedT: int | float: T = ... instead of the simpler way I saw somewhere: proc sumGenericConstrained(a, b: int | float) =
For Templates, you said they're good for making it easie then you show that a bunch of if-statements can be broken down into four template calls, but I'm left wondering why four proc calls can't be called instead. You mentioned something about templates not having a local scope in the same way procs do, and that templates inject code (so I'm wondering if the compiler puts the code inline instead of leaving it in the template, and maybe it doesn't do that for procs?). It wasn't clear to me why this is a good thing ... does it speed things up vs using procs? I'm left wondering if it's contradicting your simplicity rules.
Keep up the great work!
written is easier to track while learning.
I hope some of you noticed that the kids book has a section for macros and meta programming as well since a few months. Not really new stuff, with some citations of Mr. Arne Doering, but I still have the impression that it is better than all the other tutorials. I only wrote it while I was not satisfied with all the other available tutorials.
http://ssalewski.de/nimprogramming.html#_part_iv_some_programming_tasks
Send comments please to the github issue tracker: https://github.com/StefanSalewski/NimProgrammingBook
I think i have had the intention of mentioning that i provide the code link and the video's script link at the beginning but then i forgot about it, so it's still being only mentioned at the end.
The script is usually about 70-95% the same as what you see in the video(sometimes i improvise), i should start mentioning it at the beginning for all of you who prefer an offline version(no pictures though, i used to use OneNote to write the script of my videos but now i just use Visual Studio Code, because copying between the two is a nightmare(invisible spaces/tabs etc)).
On the template part that you could use a proc to get rid of all the if statements: Yes you could do that, but your proc would have to have 2 arguments for coordinates instead of 1, or vastly more in a more complex example. The first template shown takes "coord" as it's argument instead of x and y which is what a proc would have to take, and then it simply puts the name you give it which after the identifier insertion(all template, macro etc pass is done), evaluates player.x, player.y depending on the identifier provided(x, y).
Just in case if you were wondering, if you wanted to pass the template something else than the "x" and "y" for it's "coord" argument, you would have to obviously add that in the "player" object's definition.
For the generic constrained vs proc:
sumGenericConstrained[T: int | float](a, b: T): T =
sumGenericConstrained(a, b: int | float): int | float =
One of the differences is that the first line of code is a "generic" proc while the second is NOT. That said the compiler will generate 2 versions of the same proc, one for "int" and one for "float", while the non-generic proc will NOT. On a quick glance the generic version is heavier on compile-time speed while the second non-generic is heavier on the runtime speed. So that being said, if you need a proc that will work with MANY types and be complex, it will be better to use the generic over the non-generic.
For any other differences you will have to get an answer from someone else, i don't know more on this, as i haven't had the need for anything more complex yet.
One of the differences is that the first line of code is a "generic" proc while the second is NOT.
No, they are both generic procs and the second is almost a shortcut for the first (the return types are different).
One of the differences is that the first line of code is a "generic" proc while the second is NOT. That said the compiler will generate 2 versions of the same proc, one for "int" and one for "float", while the non-generic proc will NOT. On a quick glance the generic version is heavier on compile-time speed while the second non-generic is heavier on the runtime speed. So that being said, if you need a proc that will work with MANY types and be complex, it will be better to use the generic over the non-generic.
As I told you, better learn some Nim before making the next video. Such nonsense is really not good advertisement for Nim. How can you come to the idea that the second proc is none generic? As Nim is statically typed, int and float have no inheritance relation, and you are talking about procs, not about methods. Well I know some kids though the same, that was the reason why I wrote the kids book.
As I told you, better learn some Nim before making the next video. Such nonsense is really not good advertisement for Nim.
Oh but of course your book is good advertisement for Nim -- you never digress into the irrelevant ("Nim's macros are a PITA like learning C++") or make subtle accusations ("Maybe the Nim core devs will lose interest in async and replace it by CPS, so better not document it here").
Oh but of course your book is good advertisement
My books was never intended to do Nim advertisement, although some people told me that I would praise Nim too much.
The book had the intention to allow kids and unskilled people to start with Nim programming on its own. Currently there seems to be not many of them, but some years ago we had a few. That people had a hard time with Nim -- I told some of them to better start with plain C or Python. Now I can tell them to start directly with Nim, as there exists enough learning resources now, including my book.
For the few points where I do not praise you and the Nim languages: Well I just try to be honest. I always would like to get error reports for the book or get pointed to parts where my explanations are bad. The advantage of a book is that we can fix such erors easily, which is difficult for videos.
Sorry, I really tried stop writing more in this thread -- I have really hijacked the thread :-(
@dom96 >So what @Stefan_Salewski really wanted to say was "Nim in Action has a different target audience, I wanted a book that targets those who have never touched programming before?"
Yes of course, that should be obvious, at least after all our discussions, or after having a short look at the book. And that is why I generally call it "the kids book". Beginner book would be really too misleading, as Nim beginners coming from C++, Rust, Haskell definitely do not need this book. Here in Germany such books are often called "Python for Dummies" I think, maybe spelled Dummys, can not remember, you may do a Amazon research for the exact term. I don't like it.
@carterza Your video critics are very precise hitting the points! I am glad that you are still part of the Nim community, hope you will be seen more often in the forum or elsewhere. Maybe a bright blog post? Now that we know that Araq has reviewed the videos and even paid Mr. Kiloneie, I really wonder why he did not tell him how to improve them. But indeed the videos are not bad, they reminds me to lessions of some of our teachers in school. Sometimes it was hard to stay awake -- and maybe the teachers did not understand the stuff they presented well too. Today some people are not able to read longer text segments, and I think for these people the videos of Mr. Kiloneie are really helpful to learn some Nim.
@geohuz Yes, but I generally write only about the stuff that I know, and which I have practiced. For macros and metaprogramming I hesitated for a long time, as compared to some core devs including TimotheCour I am a moron in that area. But I read all available macro tutorials and the manual section multiple times, and wrote some ugly macros myself for the gintro package. That is why I dared to add the macro and metaprogramming section some months ago.
For async I have still to learn much. I read the async section in Doms book, I think in 2016 as a preprint, but was never really interested in async myself. I heard that Mr. Munch recently wrote a short async blog, and I think that Dom's book has good sections about async, as he wrote Nim's async modules.
And finally, for the license of the book and co-authros, please see my reply in github issue tracker: https://github.com/StefanSalewski/NimProgrammingBook/issues/10
Now that we know that Araq has reviewed the videos and even paid Mr. Kiloneie, I really wonder why he did not tell him how to improve them.
I didn't review all of them nor did we pay for all of them, only the more recent ones. And I keep telling him to change the format and what to watch for inspiration. This is a process, he is supposed to improve with every video.
Yes of course, that should be obvious, at least after all our discussions, or after having a short look at the book.
It might be obvious to some, but not all. Words matter, don't assume people will just be able to guess what you mean.
@carterza Your video critics are very precise hitting the points! I am glad that you are still part of the Nim community, hope you will be seen more often in the forum or elsewhere. Maybe a bright blog post?
Nope. Please don't skip over what I have written above: https://forum.nim-lang.org/t/8543#55521. It's important we as a community give constructive and courteous feedback.
I've read both books and I liked them both, even from someone who was programmer before starting. There's no need to point out that the target is different, it's quite obvious no matter the previous experience.
I think that there's no need to discourage the author putting personal views into the book. It's not a journal article where the source needs to be protected, or a manual that pretends to be a reference. It's a book and it contains the work of one or multiple authors, and given the fact that's not officially supported by Nim I only give bonus points for sharing it's view.
Readers might be unexperienced programmers, but probably not on their first book and surely not on their first possibly biased read. That's why I think we need both books, and also a new one called "Advanced Nim" all containing personal opinions from authors.
I would never insult someones writing or speaking ability in a non native language - as long as the meaning is conveyed then it's a success as far as i'm concerned, and especially in this case given that Stefan's English is far superior to what my German will ever be.
That said, I do find it ironic that he is adamant on becoming an expert before doing something, considering he wrote a book in English without having high level comprehension. Every other sentence is structurally incorrect and littered with errors. I know in German the order of certain words can be changed and its fine, but that's not the case in English.
Nim In Action on the other hand is extremely well written, and given the stage of Nim as an emerging language, I think it targets exactly the right level. A Nim book today should assume general knowledge in programming. The book hits the sweet spot of catering to relative beginners quite succinctly while also covering more high level topics.
You will struggle to find a better book for any other language and I think Dom and Nim should be proud of it. There is plenty of excellent content already in existence to teach programming fundamentals, its not a high priority of Nim to add to that at this point. Maybe in the distant future Nim could be used to teach programming, although I would argue that C should always be the first step of anyone who is serious about it.
So, the not-so-subtle message of SunnyCorleone's post is to compare two books people took special care to acknowledge being different in both intents and execution, declare one better than the other, define Nim (and wider Nim content) priorities and discuss author's command of English. All in the topic for discussing other person's video. Well done.
Speaking strictly in hypotheticals (not hinting on anyone), a useful and insightful book written with deficient language might be more useful than its opposite.
Also, NIA was published by Manning and probably had at least a surface-level editorial support (I may be wrong there, but that would only speak poorly of Manning). CPwNPL is self-published and isn't even considered done.
Nim in Action:
This is by no means a beginner’s book.
Computer Programming with the Nim Programming Language:
A gentle Introduction
🤷
Instead of just pointing that Stefan's harsh reception wasn't appropriate the thread quickly devolved into a back-and-forth "but of course your book...". I don't think this is good for the morale, especially when some core team members are involved.
I agree with @Zoom: it is not fair to compare a book that went through an extensive review process with a self-made book. (Disclaimer: I am the technical reviewer of Manning's «Modern Fortran» and know how careful and long is this process.)
I add that IMHO it would be best to remove this thread from the forum, as it conveys a bad image of the Nim community. One annoying thing that nobody but me seems to have noticed is another thing that should be added to the list of indelicacies shown here: stating that Stefan wrote Nim is not popular now, probably will never be popular and I had a depression when I wrote the book is wrong, wrong, wrong, and in fact I flagged that post by @Araq for removal.
I would propose to hide this thread, or at least lock it and ask people not to resume the discussion about which book is the best. Comparing apples with oranges is meaningless and is not the original purpose of the OP; moreover, it seems to bring the worst out of people.