preparing for const, final, and invariant
Walter Bright
newshound1 at digitalmars.com
Fri May 18 10:42:16 PDT 2007
Daniel Keep wrote:
> Is final really necessary?
No. It's there because nearly all the time, one won't be rebinding a
parameter, so making it easier to be final seems like a good idea.
> I can understand const and scope; but is it
> really a problem if the function rebinds the argument? I mean, that
> shouldn't affect the calling code in the slightest, should it?
No, it does not affect the caller. Only the callee.
> void foo(const scope int[] a)
> {
> a = [1,2];
> }
>
> static bar = [3,4];
> foo(bar);
> assert( bar == [3,4] ); // This should still hold, right?
Yes.
> There are a few functions I've written which re-bind the argument as
> they run; the simplest examples being functions that process strings
> (effectively, it just loops until there's just an empty slice left).
>
> Apart from that, I don't think there's any problems with doing this. Oh
> well; I'll just have to declare an extra argument. :P
>
>> Adding in all those 'in's is tedious, as I'm finding out :-(, but I
>> think the results will be worth the effort.
>
> Actually, I was thinking of doing this anyway so that my argument lists
> are nice and symmetric (qualifiers on all of them, instead of just ref
> and out). Now I have an excellent reason to do so other than my
> pedantic-ness. :)
>
> One question: is there a keyword for "normal" arguments--
No. We could use 'auto' for that, but what's the point <g>.
> for instance, I
> know that most variables are "auto" if you don't specify the storage
> class explicitly. I can't imagine where it would be useful; just curious.
>
> At any rate, looks spiffy.
>
> -- Daniel
>
More information about the Digitalmars-d-announce
mailing list