Added section of object-orientation
This commit is contained in:
parent
8426f649e6
commit
724573688b
|
@ -18,17 +18,31 @@ http://nimrod-lang.org/manual.html
|
|||
|
||||
### At a glance
|
||||
|
||||
<table>
|
||||
<tr><th>Feature</th><th>C</th><th>Nimrod</th></tr>
|
||||
<tr><td>Memory Management</td><td>Manual (GC w/ libraries or obj-C)</td><td>Garbage-collected and manual</td></tr>
|
||||
<tr><td>Types</td><td>Static</td><td>Static</td></tr>
|
||||
<tr><td>Compilation</td><td>Machine code</td><td>Machine code via C <br>(other backends in progress/planned)</td></tr>
|
||||
<tr><td>Meta-programming</td><td>C Preprocessor</td><td>Nimrod (const/when/template/macro)</td></tr>
|
||||
<tr><td>Type inference</td><td>No (some w/ C++11)</td><td>Yes (extensive support)</td></tr>
|
||||
<tr><td>Closures</td><td>No (Yes w/ obj-C or C++11)</td><td>Yes</td></tr>
|
||||
<tr><td>Operator Overloading</td><td>No (Yes w/ C++)</td><td>Yes</td></tr>
|
||||
<tr><td>Custom Operators</td><td>No</td><td>Yes</td></tr>
|
||||
</table>
|
||||
Similarities and differences.
|
||||
|
||||
Feature | C | Nimrod
|
||||
---------------------|-----------------------------------|-----------------------------------------
|
||||
Compilation | Machine code | Machine code via C*
|
||||
Meta-programming | C Preprocessor | Nimrod (const/when/template/macro)
|
||||
Memory Management | Manual (GC w/ libraries or obj-C) | Garbage-collected and manual
|
||||
Types | Static | Static
|
||||
Dependent types | No | Partial support
|
||||
Generics | No (Templates w/ C++) | Yes
|
||||
int8/16/32/64 types | Yes | Yes
|
||||
Unsigned ints | Yes (by default) | Yes (not by default)
|
||||
Arrays | Yes | Yes
|
||||
Bounds-checking | No | Yes
|
||||
Type inference | No (some w/ C++11) | Yes (extensive support)
|
||||
Closures | No (Yes w/ obj-C or C++11) | Yes
|
||||
Operator Overloading | No (Yes w/ C++) | Yes (on any types)
|
||||
Custom Operators | No | Yes
|
||||
Object-Oriented | No (Yes w/C++ or obj-C) | Minimalistic**
|
||||
Methods | No (Yes w/C++) | Yes
|
||||
Multi-Methods | No | Yes
|
||||
Exceptions | No (Yes w/C++) | Yes
|
||||
|
||||
*Other backends supported and/or planned
|
||||
**See section below
|
||||
|
||||
### Philosophy
|
||||
|
||||
|
@ -81,6 +95,17 @@ Nimrod strongly discourages the use of unsigned integers, as it's considered unn
|
|||
|
||||
*See: http://critical.eschertech.com/2010/04/07/danger-unsigned-types-used-here/
|
||||
|
||||
|
||||
### Object-Orientation
|
||||
|
||||
Objects in Nimrod 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 Nimrod.
|
||||
|
||||
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.
|
||||
|
||||
Nimrod does not have an implicit _this_/_self_.
|
||||
|
||||
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 Nimrod. These are at the moment mostly work-in-progress.
|
||||
|
||||
### Structs - Tuples and Objects
|
||||
|
||||
Tuples and Objects in Nimrod are kind of like structs in C, but not really.
|
||||
|
|
Loading…
Reference in New Issue