Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #61354
| References | (3 earlier) <mailman.3717.1386476467.18130.python-list@python.org> <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> <CAMjeLr_cGDRKKeg+rC9KqkPFM9xxK94ixKgT+oK1qg=QzuwB3Q@mail.gmail.com> <CAPTjJmpyASyVEOgBbmRL=eTpssgUb1gshPh708O8JhPr51g+zg@mail.gmail.com> <CAMjeLr9OS+3ZvbzBpoSRzNZROwuoPd8g4a8a-7ZQZNe+BEwC0Q@mail.gmail.com> |
|---|---|
| Date | 2013-12-09 14:17 +1100 |
| Subject | Re: interactive help on the base object |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3758.1386559028.18130.python-list@python.org> (permalink) |
On Mon, Dec 9, 2013 at 2:05 PM, Mark Janssen <dreamingforward@gmail.com> wrote:
> But, in any case, if you don't have a way to map your abstract objects
> into machine types, you're working on magic, not computer science.
Maybe, but that mapping isn't always an inheritance relationship.
Ultimately the computer can't work with my data without it being
represented in memory and in registers (at least in part - "relational
database" could be considered a type, the full implementation of which
is never actually loaded into memory), but the most common way to do
this is effectively some form of composition. For instance, C++ has a
type called "pair" (actually a template); what's the most obvious way
to define the type "pair of integers"? Place the first integer, then
place the second integer. The pair has two members, first and second.
The pair isn't the first integer, nor is it the second integer. It
doesn't make sense to inherit pair from integer, so you don't. You
compose it of two integers.
class Pair(object):
# in C++, we'd need to declare these:
# int first;
# int second;
def __init__(self, first, second):
self.first, self.second = first, second
Calling integer methods on a Pair makes no sense. Which of its members
did you want to call that on? Both of them? (Wouldn't make sense if
you had a mixed pair, like pair<employee,gun> which could be a little
awkward to try to fire().) You can't sensibly use a Pair in a context
where an integer would be wanted, so it fails LSP. It composes, but
does not inherit from, int.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
interactive help on the base object Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-06 17:03 +0000
Re: interactive help on the base object Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-12-08 13:10 +1300
Re: interactive help on the base object Ned Batchelder <ned@nedbatchelder.com> - 2013-12-07 19:59 -0500
Re: interactive help on the base object Mark Janssen <dreamingforward@gmail.com> - 2013-12-07 20:21 -0800
Re: interactive help on the base object Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-08 10:33 +0000
Re: interactive help on the base object Mark Janssen <dreamingforward@gmail.com> - 2013-12-08 15:01 -0800
Re: interactive help on the base object Steven D'Aprano <steve@pearwood.info> - 2013-12-09 05:11 +0000
Re: interactive help on the base object Ned Batchelder <ned@nedbatchelder.com> - 2013-12-09 05:59 -0500
Re: interactive help on the base object Steven D'Aprano <steve@pearwood.info> - 2013-12-10 03:19 +0000
Re: interactive help on the base object rusi <rustompmody@gmail.com> - 2013-12-09 20:32 -0800
Re: interactive help on the base object Steven D'Aprano <steve@pearwood.info> - 2013-12-10 05:10 +0000
Re: interactive help on the base object rusi <rustompmody@gmail.com> - 2013-12-09 21:16 -0800
Re: interactive help on the base object Roy Smith <roy@panix.com> - 2013-12-10 00:31 -0500
Re: interactive help on the base object Steven D'Aprano <steve@pearwood.info> - 2013-12-10 06:05 +0000
Re: interactive help on the base object Roy Smith <roy@panix.com> - 2013-12-10 01:20 -0500
Re: interactive help on the base object Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-10 09:37 +0000
Re: interactive help on the base object rusi <rustompmody@gmail.com> - 2013-12-10 03:51 -0800
Re: interactive help on the base object alex23 <wuwei23@gmail.com> - 2013-12-11 12:04 +1000
Re: interactive help on the base object Ian Kelly <ian.g.kelly@gmail.com> - 2013-12-10 04:35 -0700
Re: interactive help on the base object Chris Angelico <rosuav@gmail.com> - 2013-12-09 13:44 +1100
Re: interactive help on the base object Mark Janssen <dreamingforward@gmail.com> - 2013-12-08 19:05 -0800
Re: interactive help on the base object Chris Angelico <rosuav@gmail.com> - 2013-12-09 14:17 +1100
Re: interactive help on the base object Ian Kelly <ian.g.kelly@gmail.com> - 2013-12-09 03:12 -0700
Re: interactive help on the base object Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-09 15:06 +0000
Re: interactive help on the base object Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-12-09 12:15 +1300
Re: interactive help on the base object Ned Batchelder <ned@nedbatchelder.com> - 2013-12-08 07:11 -0500
csiph-web