Re: Nim in Action is now available!
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)
Re: Nim in Action is now available!
Hello @gneu and thank you for purchasing my book. I have made a conscious decision to omit some things from the book, Nim is a large language and space is limited. Unfortunately term rewriting macros/templates didn't make the cut. The reason is that I personally haven't used them much, as such I don't think they will be used much by other people either.
Re: Nim in Action is now available!
Well then let's see if we can re-evaluate their relevance when you're going to write the second edition... ;)
Re: Nim in Action is now available!
@dom96: I'm a proud owner of your book since just a few minutes ago. To be honest, I did not read through this whole thread, so I'm not sure if my following remark was already discussed: What I'm missing at first look into chapter 9 is the topic "term rewriting templates". As a novice to Nim (coming from C++, Python, C# and Java), the first things I'm interested in are the metaprogramming features, cause this is where Nim seems to shine in contrast to the languages I'm familiar with. As your book is intended for readers already skilled in other programming languages, I think the metaprogramming techniques are also the most interesting part for other people. At least I struggled with my first steps in testing term rewriting templates and so would appreciate a section on this topic.
Re: Nim in Action is now available!
> 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
Re: Nim in Action is now available!
@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.
Re: Nim in Action is now available!
@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.
Re: Nim in Action is now available!
In case anybody is still looking to purchase [the book](https://www.manning.com/books/nim-in-action?a_aid=niminaction_bid=78a27e81), code `wm103016lt` will get you half off today!
Re: Nim in Action is now available!
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.
Re: Nim in Action is now available!
> Which chapter was canceled? Chapter 10 Direct Hardware Control > I was going to buy it, but the chapter that I wanted is now cancelled. Sorry to hear that. Good news is that I am planning on writing a condensed version of it as an article.
Re: Nim in Action is now available!
Which chapter was canceled?
Re: Nim in Action is now available!
I was going to buy it, but the chapter that I wanted is now cancelled.
Re: Nim in Action is now available!
So my impression is that you have to do all the work yourself. And what is the manning contribution?
Re: Nim in Action is now available!
I just got version 9 of the meap. I was curious about the actual improvement work of the manning people. My early expectation was that they would not do much, indeed I think they can not do much, just because they do not understand the matter. So only a few grammar fixes remain to them, and I have the feeling that is what they did. But they still have not discovered that in the "Welcome" preface there are still 10 chapters mentioned, while we all know that only 9 are left. And in the first chapter this weak paragraph is still present: " One feature of the language makes it particularly well suited to systems programming. You will find that Nim is a compiled language, but the way in which it is compiled is special. When source code is compiled by the Nim compiler, it is first translated into C code. C is a pretty old but well supported systems programming language; because of this, more direct and easier access to the physical hardware of the machine is allowed. As such, Nim is very well suited to writing operating systems, compilers, device drivers, embedded system software, and more. ... Applications written in Nim are very fast, in many cases just as fast as applications written in C and more than 13 times faster than applications written in Python. " Of course that is not really wrong and most of us do know what Dom wants to express, but it is a very weak wording. And exactly 13 times -- funny. So I wonder what the Manning contribution to the books is?
Re: Nim in Action is now available!
Last chance to get 50% off Nim in Action! Use code `pbbutcherlt`: [https://manning.com/books/nim-in-action?a_aid=niminaction_bid=78a27e81](https://manning.com/books/nim-in-action?a_aid=niminaction_bid=78a27e81)
Re: Nim in Action is now available!
> Hi @dom96! > Just ordered the book. Thank you for the discount! Thank you for ordering it! > Because now to understand which methods for example the seq type supports the > fastest is to use Internet search. setLen is in system, some others are in > sequtils and etc.etc. Keep reading, i'm pretty sure I talk about seq in that level of detail somewhere. In fact it might even be in the second chapter.
Re: Nim in Action is now available!
A reference on collection makes no sense, but showing how to work with standard collections is a rather fundamental part of showing a programming language, in my opinion
Re: Nim in Action is now available!
Hi @Stefan_Salewski! > In a book that makes absolutely no sense. >... > For Nim -- use one of the > many editors with great nimsuggest support. I now consider Nim for writing fast server-side scripts. And we have a park of headless servers with ssh-only access. So you can imagine how uneasy is to work with Nim in this situation. :( Also regarding the `seq & co.` description: I mean not just to list methods but describe for example how memory buffer is pre-allocated for `seq` and etc.
Re: Nim in Action is now available!
> Probably it would be good to have in the book some short reference of Nim's > collections API. In a book that makes absolutely no sense. I have a few computer books where such type of references exists, a prominent example is the GTK Book of Mr Krause. These people had trouble to fill the remaining pages -- some insert useless pictures, some insert references. No one will really use a paper or pdf book is these days for such references, and such references are outdated very fast. For Nim -- use one of the many editors with great nimsuggest support. For NEd for example, type seq. and press Ctrl+Space. You get a list of all methods of sequence type. Scroll down in the list, press Enter. You get seq.setLen. Type ( and press Ctrl+P and you see on the bottom statusbar: system.setLen proc (s: var seq[T], newlen: Natural){.noSideEffect.} But a tool for documentation inspection would be nice. For GTK there is a tool called "devhelp" which makes browsing the documentation very fast and easy. Something similar would be nice for Nim.
Re: Nim in Action is now available!
Hi @dom96! Just ordered the book. Thank you for the discount! * * * Probably it would be good to have in the book some short reference of Nim's collections API. Because now to understand which methods for example the seq type supports the fastest is to use Internet search. `setLen` is in `system`, some others are in `sequtils` and etc.etc. I understand that the book is not a "Nim complete reference" but still...
Re: Nim in Action is now available!
Nim in Action is 50% off until the 25th of August using code `pbbutcherlt`: [https://manning.com/books/nim-in-action?a_aid=niminaction_bid=78a27e81](https://manning.com/books/nim-in-action?a_aid=niminaction_bid=78a27e81) Perfect opportunity to grab it if you haven't already. It's almost finished :)
Re: Nim in Action is now available!
Hi @dom96, I just purchased (pre-ordered) Nim in Action from my local Chapters bookstore and am pretty excited about getting the book. Do you know if it is possible for me to access the MEAP pdf's of the existing chapters on the Manning site with an in-store purchase? I don't know if I would have had to purchase it through Manning to do that instead. January seems like a long time to wait for the hard copy to be shipped! Thanks. jlindsay
Re: Nim in Action is now available!
I think I've answered my own question. I saw on the Manning webpage: > Q: Can I buy a MEAP anywhere else? > > No. Currently, MEAPs are available exclusively at manning.com. So looks like I'll have to wait until January. Oh well, it'll be a nice New Year surprise.
Re: Nim in Action is now available!
> Should we also have "Ben".cstring? You don't need to do it, because "Nim string values will be converted to C strings automatically" for `{.varargs.}`. [http://nim-lang.org/docs/manual.html#foreign-function-interface-varargs-pragma](http://forum.nim-lang.org///nim-lang.org/docs/manual.html#foreign-function-interface-varargs-pragma) > AFAIK the "c" in cstring, cint etc. means "compatible" so it makes some sense. We should point that out somewhere in the docs. It's easily misinterpreted as "string from the C language" or "int from the C language".
Re: Nim in Action is now available!
Thank you **@moigagoo** for your feedback! > 1\. In 8.1.3 Type compatibility, you point out that we can't use int and > string and should use cint and cstring instead. But instead of explaining the > differences, you state that cstring is actually similar to string (to the > point where string is implicitly converted to cstring) and cint is basically > int32. If the types are in fact so similar, why can't we use them? You're right, I will explain the differences more clearly. > [...] But when I'm trying to actually capture the return value and print it, > an error occurs [...] I wanted to keep the first example as simple as possible. But I will fix this by adding a `nodecl` pragma to it. > 3\. Usage of {.importc.} for JavaScript interfacing is confusing. Why are we > using the C pragma for JS? Why should every field be explicitly imported? > > 4\. Even more confusing is the usage of {.importcpp.}: “It instructs the > compiler to generate JavaScript code which calls the specified procedure as > if it was a member of the first argument’s object.” There's no obvious logic > in using C++ pragma in JS interfacing, let alone using it to achieve this > effect. I think **@Araq** will need to answer these questions.
Re: Nim in Action is now available!
AFAIK the "c" in `cstring`, `cint` etc. means "compatible" so it makes some sense.
Re: Nim in Action is now available!
@Stefan_Salewski > The %d should refer to a cint. Should we have to provide 30.cint for the > argument? Should we also have `"Ben".cstring`?
Re: Nim in Action is now available!
> About the {.importc.}, {.importcpp.}, cstring thing, they should really be > called {.importnp.}, {.importnoo.}, nstring, etc, where n means "native", np > means "native procedural style", noo means "native object-oriented style". Or > even better, {.import.}, {.importoo.}, and nstring accordingly. +1000. PRs welcome.
Re: Nim in Action is now available!
> But instead of explaining >From Araq's manual we know proc printf(format: cstring): cint {.importc, varargs, header: "".} var n: cint n = printf("My name is %s and I am %d years old!\n", "Ben", 30) echo n This works fine for me, but I still have to investigate why header pragma is necessary here.
Re: Nim in Action is now available!
About the `{.importc.}`, `{.importcpp.}`, `cstring` thing, they should really be called `{.importnp.}`, `{.importnoo.}`, `nstring`, etc, where `n` means "native", `np` means "native procedural style", `noo` means "native object-oriented style". Or even better, `{.import.}`, `{.importoo.}`, and `nstring` accordingly.
Re: Nim in Action is now available!
I just finished the new chapter and wanted to share some feedback. 1\. In 8.1.3 Type compatibility, you point out that we can't use int and string and should use cint and cstring instead. But instead of explaining the differences, you state that cstring is actually similar to string (to the point where string is implicitly converted to cstring) and cint is basically int32. If the types are in fact so similar, why can't we use them? 2\. `printf` returns the number of printed chars in a value of type `cint`. You suggest discarding the value and this works fine. But when I'm trying to actually capture the return value and print it, an error occurs: proc printf(format: cstring): cint {.importc, varargs.} let n = printf("My name is %s and I am %d years old!\n", "Ben", 30) echo n Error: execution of an external compiler program 'clang -c -w -I/Users/moigagoo/nim/lib -o /Users/moigagoo/Projects/nimcache/cffi.o /Users/moigagoo/Projects/nimcache/cffi.c' failed with exit code: 256 /Users/moigagoo/Projects/nimcache/cffi.c:21:16: error: conflicting types for 'printf' N_NIMCALL(int, printf)(NCSTRING format0, ...); ^ /usr/include/stdio.h:259:6: note: previous declaration is here int printf(const char * __restrict, ...) __printflike(1, 2); ^ 1 error generated. If `cint` is `int32`, why does this happen? The weird part is that the same error occurs even if I create a completely separate `cint` variable: proc printf(format: cstring): cint {.importc, varargs.} discard printf("My name is %s and I am %d years old!\n", "Ben", 30) let n:cint = 123 echo n 1. Usage of `{.importc.}` for JavaScript interfacing is confusing. Why are we using the C pragma for JS? Why should every field be explicitly imported? 2. Even more confusing is the usage of `{.importcpp.}`: “It instructs the compiler to generate JavaScript code which calls the specified procedure as if it was a member of the first argument’s object.” There's no obvious logic in using C++ pragma in JS interfacing, let alone using it to achieve this effect.
Re: Nim in Action is now available!
> I think fewer words with the same meaning are easier to understand. I agree, although @OderWat's suggestion is too succinct :) I will do my best to shorten that sentence. I'm fairly sure that Manning's proofreaders/copyeditors will also flag up these issues to me before the book goes to print.
Re: Nim in Action is now available!
I think that says the same thing more succinctly ... and I think fewer words with the same meaning are easier to understand.
Re: Nim in Action is now available!
Well I guess: > To (successfully) wrap the (required) procedures, you have to define four > types. would be enough. But my english isn't good either. So what do native speakers think about that?
Re: Nim in Action is now available!
> Before you can successfully wrap the required procedures, you are going to > have to first define four types. I don't see anything wrong with this sentence. > One of the biggest advantages that a language which can be translated to > JavaScript but also used for writing desktop applications is the ability to > share the same code between a client script and a server application. That sentence is indeed convoluted. I will fix it, thanks. > And please try to use the term Objective-C with the hyphen Will fix this as well, thank you.
Re: Nim in Action is now available!
It is not very easy to read for me as a non native speaker unfortunately... > Before you can successfully wrap the required procedures, you are going to > have to first define four types. > > One of the biggest advantages that a language which can be translated to > JavaScript but also used for writing desktop applications is the ability to > share the same code between a client script and a server application. I had to read both sentences twice -- in the second one there seems to be something wrong indeed. Or in other words, not really "perfect". :) > It is from the ePub, if that matters.
Re: Nim in Action is now available!
Looks like the deal is still available with the code `wm070216lt`.
Re: Nim in Action is now available!
For anybody still looking to buy Nim in Action, you can use code `wm070116lt` today to get 50% off [https://manning.com/books/nim-in-action?a_aid=niminaction_bid=78a27e81](https://manning.com/books/nim-in-action?a_aid=niminaction_bid=78a27e81)
Re: Nim in Action is now available!
**@moigagoo** thanks, will correct!