Re: Grokking Python
kirby urner <[email protected]> Mon, 4 Mar 2024 06:26:06 -0800
| Newsgroups | gmane.comp.python.education |
|---|---|
| Message-ID | <CAPJgG3Qfe_8S8PFWnuuOy_3PKugQs5Jmdhknd=xbhCOeX_8Hpw@mail.gmail.com> |
--===============7524943145500419460== Content-Type: multipart/alternative; boundary="0000000000006229450612d682b0" --0000000000006229450612d682b0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Mar 4, 2024 at 1:09=E2=80=AFAM DL Neil via Edu-sig <edu-sig@python.= org> wrote: > On 4/03/24 06:30, kirby urner wrote: > > On Sat, Mar 2, 2024 at 3:37=E2=80=AFPM Wes Turner <[email protected] > > <mailto:[email protected]>> wrote: > > > > They're dunder methods; double-underscore > > > > > > Certainly they are and my intro definitely includes this information. > > > > Check out the following Dog class, endowed with two of Python=E2=80=99s= =E2=80=9Cmagic > > methods=E2=80=9D also known as: =E2=80=9Cdunder methods=E2=80=9D (with = =E2=80=9Cdunder=E2=80=9D being short for > > =E2=80=9Cdouble underline=E2=80=9D) or =E2=80=9Cspecial methods=E2=80= =9D. > > In composing that post I dragged and dropped the JPG showing the actual source code for said Dog class, as it appears in Medium, but perhaps embedded pictures are not encouraged by HyperKitty's current settings, I wouldn't know. I was a nominal listowner here for a short time but then lost those credentials somewhere along the way, while still being able to post. Pleased to meet you mice dancer. A prof in New Mexico playing with ChatGPT4 just sent me what it says about me: https://flic.kr/p/2pBi659 (may be magnified) Lets I wasn't prepared for the Mailman 3 slash HyperKitty overhaul, which isn't to say anything against it happening. So what if I was unprepared? That happens a lot. Stuff happens. > > Please read "Why naming things is hard" > (https://hilton.org.uk/blog/why-naming-things-is-hard) - and yes there > is any number of similar articles. > > OK, done. The pertinent quotation is "There are only two hard things in Computer > Science: cache invalidation and naming things." (Phil Karlton). > > When training, the difficulty of choosing names is magnified by the > difficulty of choosing examples. Short, understandable, apparent, > illustrative, etc... > > So, here's a (Socratic) question: have you ever met a computer scientist > or programming professional who has had to write code about a dog's > stomach, or even the other popular one: a bowl of fruit? > > Next Socratic question: could we, or should we, choose more realistic > examples (and names)? Yes, high schoolers have little experience of the > world and of commerce. So, talking of products and minimum order > quantities might be a stretch. However, there are plenty of examples > where we can talk about class Person, and either a wallet which we'd > like filled, or a list of skills being learned, for example. > Ah so, it's the fact that I'm doing a Dog in particular that maybe irks ya. Not well-grounded in a professional use case. Sometimes I go straight to a Python class (i.e. snake) and do the same thing with the stomach (append, maybe pop from). Typically I'll do an eat method and then show how __call__ might be substituted for eat( ) or even made a synonym. The idea being these creatures have __ribs__ being vertebrates, and ribs connote a spinal cord, which is the seat of reflex reactions i.e. verb actions, responses to stimuli (being called in various ways). Snakes have lots of ribs. A mnemonic, but one not widespread in the literature (better for me that way? -- I stand out). The idea being: thinking in terms of objects was meant to meet you halfway. Think of the types of objects you know from being alive. Know any dogs? The term "object oriented" is not meant to be mysterious. It shares a lot with English grammar i.e. noun.verb(args). The parens look like a mouth turned sideways and they "eat" arguments (if any are provided). Typically humans have more experience with dogs than with programming languages by their teen years, though not always. Lets help you think about Python in terms you already understand, given you're a Person inheriting design attributes of Mammals (or more generally an Animal) in the process. So, did I learn this Pythonic Andragogy from actual practicing computer programmers who've devoted their whole lives to being good at programming (I was pretty good -- made a decent living)? They're not my principal audience. How about computer scientists? Nope, they already know this stuff= . My audience is more "English speakers" although I presume the stuff readily translates. They may not wish to become coders, ever (but since when did life obey mere wishes?). I was a philosophy major myself although at Princeton we looked down on the word "major" for some reason. After we have a Dog, Snake and Cat class, I tend to hoist the eat and even birth methods (__init__) to an Animal superclass, leaving these now subclasses of Animal to __repr__ themselves, and do things specific to their species, such as bark or meow. __repr__ could be written more generally though, making use of type(self).__name__ for like "Dog('rover')" output, even from Animal. See: https://github.com/4dsolutions/DigitalMathematics/blob/master/grok_python.p= y Wait, am I saying that Dog's have a self? Ah, now we're starting to think more analogically, like English majors. Excellent. I might substitute the word 'me' for self, or a Chinese character for 'ego' (showing off Unicode) -- see Replit for examples. As long as we're consistent; self is a placeholder, not a keyword. But the pros always-only say "self" just so you know. > The industry has a phrase, to do with using our own software creations: > "eating our own dog-food". Ghastly! Maybe? That's about the closest most > of us will ever come to programming dogs! > My daughter pined for a SONY Aibo when growing up. She downloaded and read the instruction manual at age 13. But dang that thing was expensive. Maybe if I'd got her one she'd be doing more Python and less Matlab today? I also talk about special (magic) names being like where you attach puppet strings, like with marionettes. You know: how we tie strings to: elbows, knees, chin, wrists... Python is like that: a puppet-building kit. Objects are like that: puppets we control not with strings but through "remotes" (i.e. the names themselves, remote.buttons(), GUI widgets etc.). Names are in namespaces. Objectspace (actual objects in memory) don't even know their own names, assigned at runtime, just how many references are out there in case it's time to be garbage collected. Kirby > -- > Regards =3Ddn > --0000000000006229450612d682b0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div dir=3D"ltr"><div class=3D"gmail_default" style=3D"fon= t-family:verdana,sans-serif;font-size:small"><span style=3D"font-family:Ari= al,Helvetica,sans-serif">On Mon, Mar 4, 2024 at 1:09=E2=80=AFAM DL Neil via= Edu-sig <</span><a href=3D"mailto:[email protected]" target=3D"_blank"= style=3D"font-family:Arial,Helvetica,sans-serif">[email protected]</a><sp= an style=3D"font-family:Arial,Helvetica,sans-serif">> wrote:</span><br><= /div></div><div dir=3D"ltr"><div class=3D"gmail_quote"><blockquote class=3D= "gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(2= 04,204,204);padding-left:1ex">On 4/03/24 06:30, kirby urner wrote:<br> > On Sat, Mar 2, 2024 at 3:37=E2=80=AFPM Wes Turner <<a href=3D"mailt= o:[email protected]" target=3D"_blank">[email protected]</a> <br> > <mailto:<a href=3D"mailto:[email protected]" target=3D"_blank">w= [email protected]</a>>> wrote:<br> > <br> >=C2=A0 =C2=A0 =C2=A0They're dunder methods; double-underscore<br> > <br> > <br> > Certainly they are and my intro definitely includes this information.<= br> > <br> > Check out the following Dog class, endowed with two of Python=E2=80=99= s =E2=80=9Cmagic <br> > methods=E2=80=9D also known as: =E2=80=9Cdunder methods=E2=80=9D (with= =E2=80=9Cdunder=E2=80=9D being short for <br> > =E2=80=9Cdouble underline=E2=80=9D) or =E2=80=9Cspecial methods=E2=80= =9D.<br> <br></blockquote><div><br></div><div><br></div><div><div class=3D"gmail_def= ault" style=3D"font-family:verdana,sans-serif;font-size:small">In composing= that post I dragged and dropped the JPG showing the actual source code for= said Dog class, as it appears in Medium, but perhaps embedded pictures are= not encouraged by HyperKitty's current settings, I wouldn't know.= =C2=A0</div><div class=3D"gmail_default" style=3D"font-family:verdana,sans-= serif;font-size:small"><br></div><div class=3D"gmail_default" style=3D"font= -family:verdana,sans-serif;font-size:small">I was a nominal listowner here = for a short time but then lost those credentials somewhere along the way, w= hile=C2=A0still being able to post. Pleased to meet you mice dancer.=C2=A0 = A prof in New Mexico playing with ChatGPT4 just sent me what it says about = me:</div><div class=3D"gmail_default" style=3D"font-family:verdana,sans-ser= if;font-size:small"><br></div><div class=3D"gmail_default" style=3D"font-fa= mily:verdana,sans-serif;font-size:small"><a href=3D"https://flic.kr/p/2pBi6= 59">https://flic.kr/p/2pBi659</a>=C2=A0 (may be magnified)<br></div><div cl= ass=3D"gmail_default" style=3D"font-family:verdana,sans-serif;font-size:sma= ll"><br></div><div class=3D"gmail_default" style=3D"font-family:verdana,san= s-serif;font-size:small">Lets I wasn't prepared for the Mailman 3 slash= HyperKitty overhaul, which isn't to say anything against it happening.= So what if I was unprepared? That happens a lot. Stuff happens.</div><br><= /div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0px= 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <br> Please read "Why naming things is hard" <br> (<a href=3D"https://hilton.org.uk/blog/why-naming-things-is-hard" rel=3D"no= referrer" target=3D"_blank">https://hilton.org.uk/blog/why-naming-things-is= -hard</a>) - and yes there <br> is any number of similar articles.<br> <br></blockquote><div><br></div><div><br></div><div class=3D"gmail_default"= style=3D"font-family:verdana,sans-serif;font-size:small">OK, done.</div><d= iv class=3D"gmail_default" style=3D"font-family:verdana,sans-serif;font-siz= e:small"><br></div><div class=3D"gmail_default" style=3D"font-family:verdan= a,sans-serif;font-size:small"><br></div><blockquote class=3D"gmail_quote" s= tyle=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);pad= ding-left:1ex"> The pertinent quotation is "There are only two hard things in Computer= <br> Science: cache invalidation and naming things." (Phil Karlton).<br> <br> When training, the difficulty of choosing names is magnified by the <br> difficulty of choosing examples. Short, understandable, apparent, <br> illustrative, etc...<br> <br> So, here's a (Socratic) question: have you ever met a computer scientis= t <br> or programming professional who has had to write code about a dog's <br= > stomach, or even the other popular one: a bowl of fruit?<br> <br> Next Socratic question: could we, or should we, choose more realistic <br> examples (and names)? Yes, high schoolers have little experience of the <br= > world and of commerce. So, talking of products and minimum order <br> quantities might be a stretch. However, there are plenty of examples <br> where we can talk about class Person, and either a wallet which we'd <b= r> like filled, or a list of skills being learned, for example.<br></blockquot= e><div><br></div><div class=3D"gmail_default" style=3D"font-family:verdana,= sans-serif;font-size:small"><br></div><div class=3D"gmail_default" style=3D= "font-family:verdana,sans-serif;font-size:small"><br></div><div class=3D"gm= ail_default" style=3D"font-family:verdana,sans-serif;font-size:small">Ah so= , it's the fact that I'm doing a Dog in particular that maybe irks = ya.=C2=A0 Not well-grounded in a professional use case.</div><div class=3D"= gmail_default" style=3D"font-family:verdana,sans-serif;font-size:small"><br= ></div><div class=3D"gmail_default" style=3D"font-family:verdana,sans-serif= ;font-size:small">Sometimes I go straight to a Python class (i.e. snake) an= d do the same thing with the stomach (append, maybe pop from).</div><div cl= ass=3D"gmail_default" style=3D"font-family:verdana,sans-serif;font-size:sma= ll"><br></div><div class=3D"gmail_default" style=3D"font-family:verdana,san= s-serif;font-size:small">Typically I'll do an eat method and then show = how __call__ might be substituted for eat( ) or even made a synonym.</div><= div class=3D"gmail_default" style=3D"font-family:verdana,sans-serif;font-si= ze:small"><br></div><div class=3D"gmail_default" style=3D"font-family:verda= na,sans-serif;font-size:small">The idea being these creatures have __ribs__= being vertebrates, and ribs connote a spinal cord, which is the seat of re= flex reactions i.e. verb actions, responses to stimuli (being called in var= ious ways).=C2=A0=C2=A0</div><div class=3D"gmail_default" style=3D"font-fam= ily:verdana,sans-serif;font-size:small"><br></div><div class=3D"gmail_defau= lt" style=3D"font-family:verdana,sans-serif;font-size:small">Snakes have lo= ts of ribs. A mnemonic, but one not widespread in the literature (better fo= r me that way? -- I stand out).</div><div class=3D"gmail_default" style=3D"= font-family:verdana,sans-serif;font-size:small"><br></div><div class=3D"gma= il_default" style=3D"font-family:verdana,sans-serif;font-size:small">The id= ea being:=C2=A0 thinking in terms of objects was meant to meet you halfway.= Think of the types of objects you know from being alive. Know any dogs?=C2= =A0 The term "object oriented" is not meant to be mysterious. It = shares a lot with English grammar i.e. noun.verb(args). The parens look lik= e a mouth turned sideways and they "eat" arguments (if any are pr= ovided).</div><div class=3D"gmail_default" style=3D"font-family:verdana,san= s-serif;font-size:small"><br></div><div class=3D"gmail_default" style=3D"fo= nt-family:verdana,sans-serif;font-size:small">Typically humans have more ex= perience with dogs than with programming languages by their teen years, tho= ugh not always.=C2=A0=C2=A0</div><div class=3D"gmail_default" style=3D"font= -family:verdana,sans-serif;font-size:small"><br></div><div class=3D"gmail_d= efault" style=3D"font-family:verdana,sans-serif;font-size:small">Lets help = you think about Python in terms you already understand, given you're a = Person inheriting design attributes of Mammals (or more generally an Animal= ) in the process.</div><div class=3D"gmail_default" style=3D"font-family:ve= rdana,sans-serif;font-size:small"><br></div><div class=3D"gmail_default" st= yle=3D"font-family:verdana,sans-serif;font-size:small">So, did I learn this= Pythonic Andragogy=C2=A0from actual practicing computer programmers who= 9;ve devoted their whole lives to being good at programming (I was pretty g= ood -- made a decent living)?=C2=A0 They're not my principal audience. = How about computer scientists? Nope, they already know this stuff.</div><di= v class=3D"gmail_default" style=3D"font-family:verdana,sans-serif;font-size= :small"><br></div><div class=3D"gmail_default" style=3D"font-family:verdana= ,sans-serif;font-size:small">My audience is more "English speakers&quo= t; although I presume the stuff readily translates. They may not wish to be= come coders, ever (but since when did life obey mere wishes?). I was a phil= osophy major myself although at Princeton we looked down on the word "= major" for some reason.</div><div class=3D"gmail_default" style=3D"fon= t-family:verdana,sans-serif;font-size:small"><br></div><div class=3D"gmail_= default" style=3D"font-family:verdana,sans-serif;font-size:small">After we = have a Dog, Snake and Cat class, I tend to hoist the eat and even birth met= hods (__init__) to an Animal superclass, leaving these now subclasses of An= imal to __repr__ themselves, and do things specific to their species, such = as bark or meow.=C2=A0=C2=A0</div><div class=3D"gmail_default" style=3D"fon= t-family:verdana,sans-serif;font-size:small"><br></div><div class=3D"gmail_= default" style=3D"font-family:verdana,sans-serif;font-size:small">__repr__ = could be written more generally though, making use of type(self).__name__ f= or like "Dog('rover')" output, even from Animal.</div><di= v class=3D"gmail_default" style=3D"font-family:verdana,sans-serif;font-size= :small"><br></div><div class=3D"gmail_default" style=3D"font-family:verdana= ,sans-serif;font-size:small">See:=C2=A0=C2=A0<a href=3D"https://github.com/= 4dsolutions/DigitalMathematics/blob/master/grok_python.py">https://github.c= om/4dsolutions/DigitalMathematics/blob/master/grok_python.py</a></div><div = class=3D"gmail_default" style=3D"font-family:verdana,sans-serif;font-size:s= mall"><br></div><div class=3D"gmail_default" style=3D"font-family:verdana,s= ans-serif;font-size:small">Wait, am I saying that Dog's have a self?=C2= =A0 Ah, now we're starting to think more analogically,=C2=A0like Englis= h majors. Excellent. I might substitute the word 'me' for self, or = a Chinese character for 'ego' (showing off Unicode) -- see Replit f= or examples.=C2=A0</div><div class=3D"gmail_default" style=3D"font-family:v= erdana,sans-serif;font-size:small"><br></div><div class=3D"gmail_default" s= tyle=3D"font-family:verdana,sans-serif;font-size:small">As long as we'r= e consistent; self is a placeholder, not a keyword. But the pros always-onl= y say "self" just so you know.</div><div class=3D"gmail_default" = style=3D"font-family:verdana,sans-serif;font-size:small"><br></div><div cla= ss=3D"gmail_default" style=3D"font-family:verdana,sans-serif;font-size:smal= l"><br></div><div class=3D"gmail_default" style=3D"font-family:verdana,sans= -serif;font-size:small"><br></div><blockquote class=3D"gmail_quote" style= =3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding= -left:1ex"> <br> The industry has a phrase, to do with using our own software creations: <br= > "eating our own dog-food". Ghastly! Maybe? That's about the c= losest most <br> of us will ever come to programming dogs!<br></blockquote><div><br></div><d= iv><br></div><div class=3D"gmail_default" style=3D"font-family:verdana,sans= -serif;font-size:small">My daughter pined for a SONY Aibo when growing up. = She downloaded and read the instruction manual at age 13. But dang that thi= ng was expensive. Maybe if I'd got her one she'd be doing more Pyth= on and less Matlab today?</div><div class=3D"gmail_default" style=3D"font-f= amily:verdana,sans-serif;font-size:small"><br></div><div class=3D"gmail_def= ault" style=3D"font-family:verdana,sans-serif;font-size:small">I also talk = about special (magic) names being like where you attach puppet strings, lik= e with marionettes. You know: how we tie strings to: elbows, knees, chin, w= rists... Python is like that:=C2=A0 a puppet-building kit. Objects are like= that:=C2=A0 puppets we control not with strings but through "remotes&= quot; (i.e. the names themselves, remote.buttons(), GUI widgets etc.).=C2= =A0=C2=A0</div><div class=3D"gmail_default" style=3D"font-family:verdana,sa= ns-serif;font-size:small"><br></div><div class=3D"gmail_default" style=3D"f= ont-family:verdana,sans-serif;font-size:small">Names are in namespaces.=C2= =A0 Objectspace (actual objects in memory) don't even know their own na= mes,=C2=A0assigned at runtime, just how many references are out there in ca= se it's time to be garbage collected.</div><div class=3D"gmail_default"= style=3D"font-family:verdana,sans-serif;font-size:small"><br></div><div cl= ass=3D"gmail_default" style=3D"font-family:verdana,sans-serif;font-size:sma= ll">Kirby</div><div class=3D"gmail_default" style=3D"font-family:verdana,sa= ns-serif;font-size:small"><br></div><div class=3D"gmail_default" style=3D"f= ont-family:verdana,sans-serif;font-size:small"><br></div><blockquote class= =3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rg= b(204,204,204);padding-left:1ex"> <br> -- <br> Regards =3Ddn<br></blockquote><div><br></div><div>=C2=A0</div></div></div> </div> --0000000000006229450612d682b0-- --===============7524943145500419460== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Edu-sig mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/edu-sig.python.org/ Member address: [email protected] --===============7524943145500419460==--