
ect
News
Uploaded MSc Thesis about ECT: Hot class swapping in Erlang
2011-10-09
ECT v0.3 packed
2010-01-17
ECT v0.3 is available for download here: ect-0.3.tgz. See README.TXT for installation, and browse the classes in tests/feature_tests to see usage examples. New features include:
- Private fields, aka data hiding.
- Better support for hot class swapping.
ECT v0.3 released
2009-12-06
SVN checkout is possible in the Source tab, or it can be directly browsed here. Currently comments are beeing added to the source code.
Erlang workshop
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 wiki
The documentation on this web site is still being developed! Last updated: 2009-08-25 Note that all documentation corresponds to ECT v0.2.
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.) Another aspect of discretion is low overhead: it is in O(1) for any instruction and it is lower than for the other OOP Erlang extension that we have seen so far. But it still exists.
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
.
If they are defined properly, the following things can be done.
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
Project Information
- License: GNU GPL v3
- 10 stars
- svn-based source control
Labels:
erlang
oop
parsetransformation