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
|
### At a glance
|
||||||
|
|
||||||
<table>
|
Similarities and differences.
|
||||||
<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>
|
Feature | C | Nimrod
|
||||||
<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>
|
Compilation | Machine code | Machine code via C*
|
||||||
<tr><td>Meta-programming</td><td>C Preprocessor</td><td>Nimrod (const/when/template/macro)</td></tr>
|
Meta-programming | C Preprocessor | Nimrod (const/when/template/macro)
|
||||||
<tr><td>Type inference</td><td>No (some w/ C++11)</td><td>Yes (extensive support)</td></tr>
|
Memory Management | Manual (GC w/ libraries or obj-C) | Garbage-collected and manual
|
||||||
<tr><td>Closures</td><td>No (Yes w/ obj-C or C++11)</td><td>Yes</td></tr>
|
Types | Static | Static
|
||||||
<tr><td>Operator Overloading</td><td>No (Yes w/ C++)</td><td>Yes</td></tr>
|
Dependent types | No | Partial support
|
||||||
<tr><td>Custom Operators</td><td>No</td><td>Yes</td></tr>
|
Generics | No (Templates w/ C++) | Yes
|
||||||
</table>
|
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
|
### 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/
|
*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
|
### Structs - Tuples and Objects
|
||||||
|
|
||||||
Tuples and Objects in Nimrod are kind of like structs in C, but not really.
|
Tuples and Objects in Nimrod are kind of like structs in C, but not really.
|
||||||
|
|
Loading…
Reference in New Issue