The documentation on this web site is still being developed! Last updated: 2009-08-25
ECT was presented at the Erlang Workshop of ICFP 2009. Click here to download the slides. Thank you for the lot of useful comments!
ECT
The question of adding or not adding Object-Oriented Programming (OOP) to Erlang often attracts debate. We know that everything that can be done in OOP can be done in Erlang with its extensive support for polymorphism and late binding of function calls. OOP can be seen as a fixed pattern to use these things. As using patterns in software tend to be a good thing, ECT introduces the pattern of classes to Erlang.
We do not want to turn Erlang into a new Java or to force "everything to be a class". Patterns always have to be used with care. ECT just introduces the possibility of using classes and objects, the programmer decides where to do this. There already exist some OOP extensions for Erlang. The aim of ECT is to add OOP to Erlang as discretely as possible, so that classes fit well with existing Erlang concepts. For this reason, they are actually extended Erlang records. Their additional behavior comes into picture only when the programmer needs it. Because of this:
- Objects can be pattern-matched.
- There is no need to start a process for each new object. (But there is some support for the case it is required.)
Example
The killer feature of ECT is intended to be that classes are like extendable records. Assume that we have three classes:
- animal, which have the following fields: weight and color.
- giraffe, which is a subclass of animal and has an additional attribute height.
- bird, which is also a subclass of animal and has additional attributes wingspan and glide_ratio.
Joe = #giraffe{weight = 1500, color = green, height = 5.1},
Bill = #bird{weight = 8, color = red, wingspan = 3.5, glide_ratio = 23}Okay, we created two objects like records. After this, comes the trick:
X = Joe#animal.weight,
#animal{color = red, weight = Z} = Bill,
Johnny = Joe#animal{color = yellow}This can not be done with pure records: if we do not care about the specific features of specific animals, we can handle them in a common way by the use of their common superclass. These patterns and expressions can be used every place* where they can be used with records. Methods can also be defined for these objects.
*They can really be used any place in your code, but when object-matching patterns are used in clause heads, then the set of patterns that can be embedded into them is a bit limited.
Download and installation
Download: ect-0.2.tgz
Howtos: Installation README.TXT
Usage
After the Installation of ECT, you may try defining and compiling a class. Then you can also define an inherited class, or write some methods. If you want to use ECT classes without the ECT engine, knowing the internal data structure of classes might also be useful. Objects can also automaticaly put into processes, but this is in an even more beta stage than the rest of ECT.
Contact