Friday Finking: Limiting parameters
Peter J. Holzer
hjp-python at hjp.at
Tue Jul 21 13:37:26 EDT 2020
On 2020-07-13 17:21:40 +1200, dn via Python-list wrote:
> On 12/07/20 10:10 PM, Barry Scott wrote:
> > I'd expect to see something like this:
> >
> > def mail_label( person, address ):
> > first_name = person.first_name
> > # or if you want a function interface
> > first_line_of_address = address.get_first_line()
>
> Does this idea move whole objects across the interface? (see earlier in the
> thread)
Assigning an object in Python only copies a pointer (and may adjust some
house-keeping info, like a reference count). So it doesn't matter
whether the object has 5 fields or 50. The function will only access
those it knows about and ignore the rest.
One might argue that mail_label should be a method of the person object
because it depends on the person (e.g., depending on the ethnicity of
the person the name might be written "first_name last_name" or
"last_name firstname"). OTOH a person may have many addresses (and an
address shared by many people), so a function which combines a person
and address (which therefore can't be a method of either person or
address) may be better.
Maybe that should be treated as a model-view relationship: You have two
models (person and address) and a view (which combines some aspects of
both while ignoring others).
hp
--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp at hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20200721/b6e8538d/attachment.sig>
More information about the Python-list
mailing list