rsokl / Learning_Python

Source material for Python Like You Mean it
https://www.pythonlikeyoumeanit.com/
Other
168 stars 54 forks source link

New Module: OOP #9

Closed rsokl closed 5 years ago

rsokl commented 6 years ago

Module 6: Object Oriented Programming

davidmascharka commented 6 years ago

@rsokl I can take a crack at writing some stuff up if you want to have a template/skeleton to rework and modify.

rsokl commented 6 years ago

@davidmascharka that'd be awesome!

AFederici commented 6 years ago

A little late but I took a look at this module and looked over it the same as with the other modules.

OOP

Introduction to OOP

In the definition of the Rectangle class, the fourth parameter, center, is documented to be a tuple of floats. The default, however, is (0,0). Should this be (0.0,0.0)? Also, for the compute area method I think 'dx = self.width / 2.0' is better than dividing by 2 for the sake of robustness but maybe this is me just being too picky.

I also think there's potential for confusion just with many interchangeable terms getting thrown around in this beginning section. That's more of just a comment since this can't really be helped as it is important to know things by the many different names. One part that might make things more straight forward is replacing object type with class in the section "Next, we will learn abo ut creating distinct instances of a give object type..."

Instance of a class

Suggested edit with italics as changes:

Once we leave the scope of the class definition, a class object is formed - the singular object that encapsulates our class definition. We seldom will want to pass around or manipulate this class object once it is created. Rather, we will want to use it to create individual instances of that class. To be more concrete, list is a class object (remember that “class” and “type” are synonymous) - it is the same sort of object that is produced when a class definition is executed. As you saw in Module 2, we can use this class object to create individual instances of the list class, each one containing its own sequence of items. Basically, the class object is a parameter-less function that returns an instance of that class

For the reading comprehension section, add the question "What relationship do Cat and y share?" before "What relationship do x and y share?" as this is the first question answered at the end yet isn't included in the question.

At the bottom, it should be "hello world": An instance of the str type instead of instances.

Methods

For class methods maybe add that these can be called without an instance of the class or that it can have function as a non-standard constructor kind of how dict has a class method dict.fromkeys

Special Methods

Under the creating a container like class in the chart of method | signature | explanation, the styling got messed up on the second row's explanation.

Inheritance

Just a comment - I thought it was a nice summary but I'm not sure if I took away why I would actually want to use inheritance in python. It makes sense in other languages because things like storing different objects in an array becomes easy with inheritance where this isn't as applicable in python.

davidmascharka commented 6 years ago

Good stuff! After incorporating this, I think the issue can be closed -- I believe we've addressed all the bullets (so I checked them off)

center, is documented to be a tuple of floats. The default, however, is (0,0). Should this be (0.0,0.0)? Also, for the compute area method I think 'dx = self.width / 2.0' is better than dividing by 2 for the sake of robustness but maybe this is me just being too picky.

Bah...I guess technically it should be Real... my days of static typing are bleeding through. I personally hate 2.0 vs 2 when you don't need a .0 but that's just me

rsokl commented 6 years ago

I will make these changes today.

davidmascharka commented 6 years ago

@rsokl did you make those changes?

davidmascharka commented 6 years ago

@rsokl can I close this yet?

rsokl commented 5 years ago

The year is 2089. Mankind is in the throes of an epic battle against the brutal and cunning artificial intelligence that they unwittingly begot. @davidmascharka crawls out of the ventilation shaft - the only entry point leading to his bunker, where he has found refuge for the past two years. He blows dust off of his laptop; it is impossible to keep dust from regularly billowing in from the ventilation shaft. His is one of the few still-operational computers in the world; the maintainers of archlinux inadvertently became the maintainers of human technology, as no other system withstood RezNet2085.

Logged onto GitHub, @davidmascharka found his emacs.d repo with one fewer a fork. Another comrade fallen. An unfamiliar blue dot lit up in the top right corner of the screen. A notification? @davidmascharka quickly put his feet to his CTRL and META foot petals (pipe organ pedals that he had commandeered from a cathedral in the abandoned city central). Smoke billowed from his machine as he rapidly fired off the commands to traverse his proxy-cursor over to the notification widget. <Return>.

Pull Request: Incorporate AJ's edits for Module 4... finally! #69

@davidmascharka reeled back in his pod. How could this be? After all this time... @rsokl finally closed the issue. But how is it possible? He knows not how to logon to the archmacs-net. And he only ever used Surfaces. Those were among the original vectors for RezNet2085.

*Self-Destruct Sequence Initiated*. Save file ~/daily_log.txt? (y, n, !, ., q, C-r, d or C-h) >>> n

@davidmascharka slung his bag over his shoulder and sparked a torch, lighting his bedding on fire and tossing the blazing stick onto his computer. He entered the ventilation shaft, this time to leave for good.

@salesforcebot: evasive maneuvers detected. Confidence 93%. Subject did not take the bait. Alert the swarm that terminal X2 is compromised. Subject still possesses unit Y1. Pursuit-level is 9.

Closed by #69