This is a guide for people with experience in C or a similar language. The guide assumes some intermediate knowledge, for instance of how stacks and heaps works.
The key to understanding Nim is that Nim was designed to be as fast as C, but to be much safer. Many of the design-decisions are based on making it harder to shoot yourself in the foot. For example, in C you are required to use a pointer for most of your everyday programming needs. While Nim does give you pointers, Nim gives you other, safer tools for your everyday needs, while pointers are mostly reserved for interfacing with C and doing low-level system programming. In other words, C gives you a combined hammer and gun, while Nim gives you a separate gun and hammer.
The other important thing to know is that while C uses a separate language to do meta-programming (the preprocessor), Nim meta-programming is done with the Nim language itself. That means that most Nim code can be executed at compile time, and Nim's ability to generate Nim-code at compile time is much more sophisticated.
In C an array is more or less syntactic sugar for pointers. In Nim, arrays are much more strict and safe to use. They are pass-by-value (meaning they're copied at assignment). When passing an array to a proc in Nim, the argument is a read-only reference, meaning it can't be assigned to. Take the following example:
The C-code will compile, it may or may not crash. The Nim code will not compile. If you mean to change the array that was passed to the procedure, you can change the the signature of the procedure to ```proc foobar(z: var array[0..3, int])```. Now you will only get index out of bounds error. If you change the index in both lines to 1, the code will compile. If the index is a variable, Nim will include run-time checks on the bounds of the array.
In C, you can pass an ``int[3]`` to the foobar function, and the compiler will not complain. In this case Nim would not compile. You can use an openarray to accept an array of any size, and you can use low(z) and high(z) to query the bounds of the array.
Nim arrays can also be indexed from any number. That is, ``z: array[1..4, int]`` is an array of int indexed from 1 to 4. Trying to access ``z[0]`` would throw an index out bounds error.
In C, there's nothing that stops you from keeping a pointer to a stack-allocated array after the function that declared it has returned (and the stack is invalidated). In Nim, this is true as well, but you are strongly discouraged from using pointers in Nim, and you can accomplish almost everything you'd otherwise use pointers for with normal arguments, "var" arguments, variables, and "ref".
Nim strongly discourages the use of unsigned integers, as it's considered unnecessary and somewhat unsafe* for most applications. The unsigned types uint, uint8/16/32/64 are available by default, but the arithmetic and binary functions are not defined. If you do need to do arithmetic on unsigned integers, you need to import the **unsigned** module.
Objects in Nim have more features than structs in C, but behave quite differently from classes in C++. Objects support inheritance (not multiple inheritance). But otherwise most of the features that apply to objects simply apply to all types in Nim.
You can call a proc on objects with the ```anObject.foobar()```, but you can do that on any type (e.g. ints and arrays) as well. You can have methods on object, but you can have methods on any types, and for all the arguments, not just the first (in C++, implicit) one.
It is possible to implement object-orientation features from other languages (like C++,Java,etc. or Smalltalk,Obj-C,Ruby,etc.) through libraries, thanks to the extensive meta-programming features of Nim. These are at the moment mostly work-in-progress.
<td><b>Define variable</b>. y2 uses type inference. z is single-assignment. In Nim, uninitialized variables is initialized to 0/nil or similar defaults.</i>
<td><b>Newlines and chars</b>. In nim you can't use ``\n`` as a character literal, because on the Windows platform it expands to CR+LR. So you need to specify which char to use.</i>
<td><b>Modulo operator</b>. <i>%% treats its argument as unsigned numbers. <ahref="http://nim-lang.org/manual.html#pre-defined-integer-types">See</a></i></i>
<td><b>Dereference.</b><i>In C, only the pointer to the strings in the struct is copied. In Nim, the string is also copied, but refs are not deep-copied.</i></td>