My own spin:

1\. Object are allocated on the stack while ref objects are allocated on the 
heap by the garbage collector. `let a = foo` will copy the object in the first 
case but will copy the reference to the object in the second case, so `a` and 
`foo` are completely distinct for object but the same in the second case (i.e. 
a refrence to the same memory location stored in 2 variables)

2\. Nim is a statically typed language, meaning which proc to call must be 
known at compile-time. However in some cases (object-oriented) you might want 
to run on specialized type only known at runtime, for example you have 
something called an animal but you don't know if it will be a cat or a dog **at 
compile-time**. You want functions with a common name, but a different 
behaviour at runtime -- > use inheritance + methods. If everything is known at 
compile-time, just use Generics.

3\. Template = copy-pasting a block of code, a proc actually exists in the 
final binary, a template only exist at Nim level but not in the C/Javascript or 
Assembly produced.

4\. Importc for header only is tricky: have a look in the following libraries 
that wrap header only C and C++:

  * Using a C intermediate file that include the header: 
[https://github.com/define-private-public/stb_image-Nim](https://github.com/define-private-public/stb_image-Nim)
  * Using {.passC -I"fooPath".} to include the header path: 
[https://github.com/status-im/nim-ttmath/blob/master/src/ttmath.nim#L5](https://github.com/status-im/nim-ttmath/blob/master/src/ttmath.nim#L5)
  * Or the poor man solution, copy the headers in ./nimcache, Nim is actually 
looking there by default 


Reply via email to