[Tutor] Name for this type of class?

David L Neil PyTutor at DancesWithMice.info
Sat Aug 3 23:44:48 EDT 2019


NB am heading somewhat OT
NBB Python3+


On 3/08/19 12:38 PM, Alan Gauld via Tutor wrote:
> On 03/08/2019 00:47, Malcolm Greene wrote:
>> Anyways, I'm looking for help coming up for the proper name for a class that collects the following type of telemetry data
> 
> Classes should never be named for their data but for their function.
> What does this class do? What operations does it support.


This statement caused me to double-take. Do I misunderstand?


Quick survey of my PC's Projects directory:- sure-enough, few of my 
classNMs are verbs and convey little/no idea of function.
(to a degree one's expectations/experience lead to ideas of (what might 
be) included in its functionality)

They are almost exclusively nouns, eg Customer, Person, Organisation; 
rather than verbs/functions, eg Selling, Addressing, Billing.


[I'm not an OOP-native, and embraced OOP concepts as extensions to 
practices learned whilst programming with languages such as COBOL!]

Part of my introduction to OOP included the word "entity". A class was 
to represent an entity. An entity would be described (have attributes), 
just like a data-record; and it would have associated actions (methods 
or procedures) which acted on the entity's attributes. An entity was 
described as a 'thing' - no mention of an entity being an action, even 
though 'things' do 'stuff'.


Python is not particularly dogmatic or "pure" in its following of the 
OOP paradigm. Unlike some languages it does not insist on OOP and will 
support elements of both "procedural" and "functional" programming.

For this discussion then, a Wikipedia definition* 'will do'. What is 
included in OOP? [sometimes have 'translated' into Python terminology]

- objects
- data attributes
- methods
- inheritance
- instances and dynamic dispatch
- encapsulation [dotted notation]
- composition [will come back to this...]
- inheritance/delegation [ditto]
- polymorphism [sub-classing]

NB the article was no help with regard to the naming of objects/classes.


Simple comprehensions of inheritance and composition boil down to the 
phrases "is a" and "has a". The subjects and objects of such sentences 
will surely be a noun, rather than a verb?

	Employee is a Person
	Circle/Oval/Square/Triangle/Shape has a CentralPoint

Thus:

	class Person(): ...

	class Employee( Person ): ...


Python says "everything is an object" and makes little/no distinction 
between "type" and "class":

 >>> class C: pass
...
 >>> i = C()
 >>> type( i )
<class '__main__.C'>
 >>> i.__class__
<class '__main__.C'>
 >>> type( C )
<class 'type'>
 >>> C.__class__
<class 'type'>

So, what are Python's base types/objects/classes? eg int, str, list. Are 
these "data or function"?


Expand that outwards into the PSL. Same: numbers, decimals, fractions. 
However, does "math" convey more "function" than "data"?


There's current discussion about concerns of the 
age/relevance/maintenance of certain members within the PSL. So, let's 
look at a recent addition (it even features O-O in its description): 
"pathlib — Object-oriented filesystem paths". Function or data?

Let's argue that it is a library not a class/object per-se. Fine. 
However, the six (major) classes that library contains, eg Path, 
PosixPath, are all nouns!

At first I thought Inspect might be different, but (it is billed as a 
module of functions cf classes!) the classNMs are nouns (one is even 
called "Attribute"). The functions though, are indeed verbs, eg getargs().


Whither "Classes should never be named for their data but for their 
function."?


WebRef:
https://en.wikipedia.org/wiki/Object-oriented_programming

--
Regards =dn


More information about the Tutor mailing list