develooper Front page | perl.perl5.porters | Postings from November 2016

Re: RFC: core sub signature introspection

Thread Previous | Thread Next
Sam Kington
November 24, 2016 07:28
Re: RFC: core sub signature introspection
Message ID:
On 23 Nov 2016, at 22:02, Zefram <> wrote:
> The hint name of a parameter will very often coincide with the name
> that a sub's implementation uses internally for the variable containing
> the parameter value.  As a convenience, under some pragma we could
> default to advertising hints derived from the parameter declaration in
> the implementation.  We can do that in XS, where parameter declarations
> are governed by the XS language, and we can do it for Perl subs written
> using signatures.  But even in these cases it must be possible to specify
> hint names separate from the parameter declarations: the desired hint
> name is not always the same as the internal variable name.

Apologies for side-tracking this discussion, but I wanted to query this particular bit.

I tend to think that if you use two different names for the variable (or hash key name etc.) that you document, and the variable you use internally, you’re creating confusion and you should settle on a single name.

So if e.g. you document a function as create_website($domain, $document_root) but implement it as create_website($hostname, $home_dir) that’s a sign that potentially you haven’t thought things through. ‘’ could obviously fit in both $domain and $hostname, but arguably ‘’ only makes sense as $hostname. If I’m asked for $document_root, then something like ‘/home/weddingp/public_html’ makes sense; if I’m asked for $home_dir, ‘/home/weddingp’ makes more sense.

Which use cases am I missing? If you advertise the parameters that your sub takes, with specific names, why does it make sense to immediately use different names for them internally?

(Legitimately curious, BTW, not trying to be passive-aggressive.)


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About