Re: [Tutor] Name for this type of class?

2019-08-03 Thread Malcolm Greene
Thanks for everyone's feedback. Some interesting thoughts including Alan's 
"classes should never be named for their data but for their function" feedback. 
I'm going to have to noodle on that one. Good stuff!

Malcolm
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Name for this type of class?

2019-08-03 Thread Mats Wichmann
On 8/3/19 10:56 AM, Malcolm Greene wrote:
> Thanks for everyone's feedback. Some interesting thoughts including Alan's 
> "classes should never be named for their data but for their function" 
> feedback. I'm going to have to noodle on that one. Good stuff!

And more:

if the class is really just a data container, then no need to make it a
class. Use a namedtuple (or as Cameron suggested,
types.SimpleNamespace).  Of course we still don't know if that's the
case...

General comment on naming: you don't need to qualify things if the
context makes it clear, all it does is make you type more stuff (or, I
guess, exercise autocomplete in your IDE).  A favorite one is to call
your custom exception MyProgramSpecificException.  Since this is going
to appear in a line with raise or except in it, the word Exception is
superfluous.  This comes up in regards to an idea of using something
like TelemetryData or TelemetryStatistics.  It also comes up here:

>> file_count
>> line_count
>> byte_count
>> row_count
>> batch_count
>> job_count
>> error_count
>> warning_count

why not "files", "lines", "bytes"... the plural form already tells you
it's a counter.

Opinions, we all have 'em  :)

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Name for this type of class?

2019-08-03 Thread Alex Kleider

On 2019-08-03 10:16, Mats Wichmann wrote:


.  It also comes up here:


file_count
line_count
byte_count
row_count
batch_count
job_count
error_count
warning_count


why not "files", "lines", "bytes"... the plural form already tells you
it's a counter.


To me "files", "lines", "bytes" implies collections of files, lines 
bytes. (i.e. arrays or tuples...)

"___count" implies an integer.
If the latter, I'd use "n_files", "n_lines" ... (possibly without the 
underscores if you find typing them a bother.)

Comments?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Name for this type of class?

2019-08-03 Thread Richard Damon
On 8/3/19 1:40 PM, Alex Kleider wrote:
> On 2019-08-03 10:16, Mats Wichmann wrote:
>
>> .  It also comes up here:
>>
 file_count
 line_count
 byte_count
 row_count
 batch_count
 job_count
 error_count
 warning_count
>>
>> why not "files", "lines", "bytes"... the plural form already tells you
>> it's a counter.
>
> To me "files", "lines", "bytes" implies collections of files, lines
> bytes. (i.e. arrays or tuples...)
> "___count" implies an integer.
> If the latter, I'd use "n_files", "n_lines" ... (possibly without the
> underscores if you find typing them a bother.)
> Comments? 

I agree, plural nouns imply collections, and collections should
generally be plural nouns.

file_count is fine to me, or it could be numfiles or nfiles (possibly
adding the underscore)

-- 
Richard Damon

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Name for this type of class?

2019-08-03 Thread Alan Gauld via Tutor
On 03/08/2019 17:56, Malcolm Greene wrote:
>... interesting thoughts including Alan's "classes should never be named 
> for their data but for their function" feedback. I'm going to have to 
> noodle on that one. 
Let me expand slightly.

Go back to the fundamentals of OOP.

OOP is about programs composed of objects that communicate by
sending each other messages. Those messages result in the
objects executing a method. Objects, therefore are defined
by the set of messages that can be sent to them.
By their behaviour in other words. The data they contain
should only be there to support the behaviour.

So an object should expose a set of methods that determine what
it can do. It therefore stands to reason that the class (the template
for the objects) should have a name that reflects the nature
of the messages that can be sent. What kind of thing offers
those kinds of capabilities?

Once you can describe the operations that the object can
perform you can usually find a name that describes the kind
of object.

One of the anti-patterns of OOP is having classes that expose
methods that are unrelated to each other. Then we just have
a bunch of data and some functions collected together but no
coherent concept. It could be two(or more) genuine classes
accidentally merged into one. Or it could be a plain module
masquerading as a class. Another clue is where you only ever
need a single instance of this "class". That's often a sign
that it should just be a module. (There are a very few genuine
singleton use cases though, so it's not a cast iron rule.)

HTH.
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Name for this type of class?

2019-08-03 Thread David L Neil

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 )

>>> i.__class__

>>> type( C )

>>> C.__class__


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
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor