Suggestion: properties should be treated as 'virtual members variables'
Steve Horne
stephenwantshornenospam100 at aol.com
Fri Sep 8 00:04:20 PDT 2006
On Tue, 5 Sep 2006 09:52:44 -0400, "Jarrett Billingsley"
<kb3ctd2 at yahoo.com> wrote:
>Then I got even more general, and came up with namespaces + operator
>overloading:
>
>class Foo
>{
> def int function(int)[] mCallbacks;
>
> namespace callbacks
> {
> def int function(int)[] opGet()
> {
> return mCallbacks.dup;
> }
...
> }
>}
I like it. It reminds me of something I did with properties in Python,
even though it was a lot of hassle.
I wanted reverse iteration. I solved it by having a 'reverse' propery
which returned a proxy object. The proxy referred back to the
original, but implemented some methods 'backwards'. Request an
iterator and you get one, but set up to generate the values in reverse
order.
I had a class set up to represent 'the set of integers', so that I
could use slicing and reversing to specify a range of values for a for
loop such as...
for i in Integers.reverse [0:10] :
The point being that writing a reversed slice (with a half-open range)
is just slightly painful - reversing the above slice gives [9:-1:-1]
for instance.
It was proof of concept rather than real code, but I liked the result.
But I didn't really want a proxy. I just wanted an easy notation. Your
'namespace' syntax could have given me the same notation, and avoided
the proxy object overhead.
Another thought - overloaded constructors by name. There are sometimes
different ways to construct an object for different purposes. They
can't always be separated by signature, and even if they can, the
signature doesn't always express the purpose. Usual solution - only
partly construct the object, and use ordinary methods to finish the
initialisation.
Putting a constructor in one of your namespaces would, it seems, do
the trick, allowing...
c_Object l_Object = new c_Object.alt_constructor_name (blah);
I seem to remember Turbo Pascal allowing any method to be declared as
a constructor for similar reasons, though that was a long long time
ago and I've never used Delphi. I assume the special-constructor-name
systems main benefit is that there's an obvious default constructor,
but it would still be nice to have named alternatives at times.
--
Remove 'wants' and 'nospam' from e-mail.
More information about the Digitalmars-d
mailing list