Some attributes
bearophile
bearophileHUGS at lycos.com
Wed Mar 17 17:37:41 PDT 2010
Few new attributes that can be invented:
@readonly (transitive): like @pure but less restricting, the variables in outer scopes can be read but not written. It's a way to essentially implement "const" functions, that like class/struct members can't modify the instance but can read it. This can be useful for pre/post conditions, and invariants.
@noheap (transitive): doesn't perform heap activity. It disallows memory allocations, object creations, AA writes, array concat and append/extend, std.stdlib.malloc/calloc, and the like. It can be useful for code that has to be fast, to be sure it doesn't allocate on the heap, because they can be a little slow (if the GC is not very good). Game developers can appreciate this.
@nocommutative, to "disable" the commutativity of an operator overloading, like + or *, so it becomes like the + and * of floating point values. It's useful for example if you want to implement Clifford algebras. With the new operator overloading regime it becomes a less easy to design this attribute.
The language can even give the tools (with some static reflection) to let a D programmers to write such attributes.
Bye,
bearophile
More information about the Digitalmars-d
mailing list