Good news guys!
I have been writing a book about Nim titled Nim in Action for the past couple of months, it's still not finished, but it is now available through Manning's Early Access Program.
https://www.manning.com/books/nim-in-action
The first chapter is available for free. If you purchase the eBook, you will receive the first three chapters as well as the other chapters as they become available. You can also purchase the printed book together with the eBook and you will then receive the printed book once it is released (current estimate: Summer 2016).
If you do read the book, even if it just the first chapter, then please share any comments, suggestions and questions here or in Manning's own Author Online forum! I will truly appreciate you taking the time to do so, as any comments are extremely valuable in the development process.
I hope you guys are just as excited about this book as I am! Happy reading! :)
Edit: For a limited time you can get a 50% discount using the code: mlpicheta
This is awesome! I'm definitely going to get this when it comes out, maybe even before through the EAP.
Nice work @dom96!
Also congratulation for the great work.
I very much appreciate the way you create the book. This is a winner winner game for you and the readers as the input of the readers makes the book better, and the escort by the readers makes the learning experience for the readers much better (it is very motivating when readers have a chance to influence things to the better, or what they believe is better).
Thank you guys so much for the feedback, and a special thank you to all those that bought the book!
Now let me reply to your feedback individually:
@andrea:
I haven't yet read the first chapter, but my suggestion would be to emphasize metaprogramming earlier.
Metaprogramming is mentioned in the first chapter. The mention of metaprogramming is brief but it does emphasize that it is a core feature of Nim. It's under the subsection 1.1.1 Core features, please take a look and let me know if that is what you had in mind.
It is quite central to how Nim works, and it seems weird to relegate it to the advanced section
I do believe that templates and in particular AST macros are advanced topics. Templates probably could have been introduced earlier, but I'm not sure where I could fit them.
It would also help to represent other languages fairly. In the table 1.2, the GC for Java should read "Yes, multiple", and C++ certainly has (at least partial) support for metaprogramming through templates. Also, in Python you can walk and modify the AST using the ast module
Thank you, I will fix this! Please let me know if you see any other errors like this.
@yglukhov
Twice you state that Nim is not great for just anything, but give no concrete example of such cases. So I wonder, what Nim is not good at?
Could you point me to the location in the chapter where I state that?
To answer your question. I can't actually think of any concrete examples. Nim has been designed to be good for just about anything, and in most cases it is. The only obstacle it faces is lack of Nim libraries which implement specific functionality. So when you have an application in mind which needs to use the Twitter API for example, if you're using Python you just search for "python twitter api" and the second result gives you something you can use immediately: https://github.com/bear/python-twitter, but if you're using Nim... well, in this case there actually is something you can use immediately: https://github.com/kubo39/twitter.nim. But the fact is that this isn't always the case, there are times when you will need to write this library yourself. The good news is that this obstacle will be overcome with time, and for those of us that love reinventing the wheel it's not even an obstacle, it's only an obstacle to those of us that want to get stuff done ASAP.
You state that JS backend lacks something. So I wonder again =). Thats almost personal, you know...
Hehe. I'm sorry. Keep in mind that I wrote this chapter around 6 months ago, so maybe it's time to soften my statement. (Please point me to it again if you can, although this one I can probably find on my own easily). My point is simply that the JS backend is not as mature as the C one. Please don't take what I wrote personally, my point was simply that the JS backend is not as mature as the C one. I'm fairly sure that it still does not support all of Nim. I would also love to see a library which makes working with the JS DOM much easier (ala JQuery), something which might perhaps make it into the stdlib someday. That brings me back to my point above though.
Hope this answers your questions!
Well, writing books in a foreign language is not easy...
You may have noted that this remark from chapter 2 is still not very nice
Order of procedures It is important to note that the order of procedures and procedure calls matters. When calling a procedure, it must be defined above the call site like in the example above. This will likely be changed in a future version of Nim.
So I tried for fun to rewrite it. I also mention a proc forward declaration -- I can not remember if you mention it at all:
Order of procedure definitions and invocations Before a procedure can be called, the compiler has to be aware of it. That means that it has to be defined in advance -- at a position in the source file above the first use, or in an already imported module. When it is necessary to call a procedure before it can be defined, you may use a forward declaration: You specify only the procedure header (without the equal sign and the procedure body) before the first use of the procedure, and give the full definition at a later location. This restriction and the need for forward declarations may be relaxed in a future version of Nim.
There is one more sentence which I saw when scrolling through chapter 2 which you should not really like:
In the case where the last expression of a procedure has a non-void value associated with it, that expression will be implicitly returned from that procedure.
Of course that is not really correct. It is true only when the end of the proc is really reached! Unfortunately I have no idea for a better wording in only one sentence. OK, I try:
When the end of a proc is reached and the last expression has a non-void value associated with it, that value will be implicitly returned from that procedure.
Indeed I think a value is returned, not an expression. Personally, an expression with a void value is a bit strange for me. Maybe that is really the correct term in Nim, but I can not remember that from other languages. In some books it may have been called statement, I am not sure.
And as a last remark, at least for now :-)
In Araqs tutorial there is this remark, which I can not remember from your text, maybe you can copy and paste when it is indeed missing:
A return statement with no expression is a shorthand for return result.
[EDIT]
Unfortunately there is some more stiil....
In chapter 2 you wrote at multiple locations, for example in section about "Anonymous procedures"
Assertion to show the output.
One can not really feel happy when reading that, thre is no "show" and no "output" involved. I would write:
Assertion to verify the result
Close to this location is this sentence:
Procedure overloading is the ability to define different implementations of procedures with the same name.
I wonder if the term implementations is the best here. May it be better to say "different signature" or "different formal parameters"? You may know, implementation can be reffered to the proc body, two procs with same formal parameters and maybe even same task can have different implementation.
Still close to this location:
Default parameters can be used to ask for arguments which can be optionally specified at the call site. Default parameters are introduced by assigning a value to a parameter using the equals character, the type can also be omitted in that case:
Not a very nice phrase, and it makes understanding not as easy as it should be. Maybe this?
Procedure parameters can be made optional by assigning default values in the procedure parameter list. In this case the parameter type can be omitted, as it can be inferred from the default value.
You write about sequences:
The items themselves will not be initialized, and you may still...
That is very missleading. The string items are initialized to the well defined value nil.
@StefanSalewski My editor assured me that the book will be copyedited thoroughly by Manning. I am currently looking for factual issues or misleading sentences. You mentioned some of those, but unfortunately I disagree with most of them.
I will consider improving the explanation of forward declarations in chapter 2 if the other chapters don't teach it sufficiently well.
@Stefan_Salewski
IMO your rewording of the explanation of forward declaration also leaves something to be desired. I'd immediately introduce the distinction between declaration and definition, and then introduce Nim's rules, hint at why they make sense, and mention the possibilty that they may be relaxed in the future. In your explanation you contradict yourself by first saying
it has to be defined in advance
when really it has to be at least declared in advance, and then saying
When it is necessary to call a procedure before it can be defined
after you've just declared (ha!) that that can't be done. By making the distinction clear at the outset I think the explanation is simpler and more accurate.
BTW, I don't see in todo.txt any mention of the relaxation of forward declaration rules. One of the off-putting aspects of Nim's development model IMO is the lack of visibility into the priorities and future plans. Following forum posts and IRC chats is not a realistic option; it would be great if the book could point to a place where all of these future issues are discussed.
Looking forward to holding the physical book in my hands (yeah I'm old fashioned) and seeing Nim reach a 1.0 milestone soon.
IMO your rewording of the explanation of forward declaration also leaves something to be desired.
Yes, it is difficult to explain, for me, in english. I just tried, as only complaining is sometime too easy.
For the forward declaration, I think there is already a secret pragma to make it unnecessary, I once tried it, was working, but have never really used it. Relaxing forward declarations was mentioned a few times, some people would really love it. Recently someone in IRC talked about new problems when forward declarations would be relaxed, I think it was related to templates or macros and their order
Hi @dom96,
I bought Nim In Action a few monthes ago (it was still MEAP v.8), a few days after install Nim.
I didn't yet find the needed time to study it inside out — too many project to finish to dedicate myself full time to Nim — but from a first reading I have to say that the book is really great. And I really advice everyone interested in Nim to go ahead and get it.
Hopefully, now I'm getting a few projects out of the way and I shall dedicate myself to seriously explore Nim.
Can't really imagine doing it without Nim In Action though!
Best regards,
Tristano (Italy)