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

Re: RFC: core sub signature introspection

Thread Previous | Thread Next
From:
Sam Kington
Date:
November 24, 2016 07:28
Subject:
Re: RFC: core sub signature introspection
Message ID:
03891EE1-9766-4547-95F8-94D03E8950B6@illuminated.co.uk
On 23 Nov 2016, at 22:02, Zefram <zefram@fysh.org> 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. ‘example.com’ could obviously fit in both $domain and $hostname, but arguably ‘development.example.com’ 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.)

Sam
-- 
Website: http://www.illuminated.co.uk/


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About