David Beazley wrote:
> There was a recent bug report related to this. Is the use of a
> special variable $self really necessary in the %extend directive?
> Does the old self variable work for the purposes of backwards
> compatibility? All things being equal, I'd much rather just use
> 'self'. Please advise.
IRR, there was a request for a special variable $self in %extend. This
makes sense for a few reasons:
- Reading %extend with a 'self' in it makes no sense as there is no
obvious variable called self, whereas $self fits in with the way SWIG
works everywhere else where a special variable indicates the variable is
not declared locally, or originates from elsewhere. It is the same with
typemaps - users are meant to $result instead of 'result'.
- $self is used in various other places, eg the ref/unref feature, so
using it in %extend makes this consistent.
- Future proofing - there are various reports of variable name clashes
and in a future major version of swig, $self could be expanded into an
alternative variable name. At least the option to make this change will
then be available once $self is in common use.
Of course 'self' will still work for old versions and certainly for
future swig-1.3.x versions, but from 1.3.30 onwards, recommend using $self.