[Tutor] Ideas on making this cleaner?

dn PythonList at DancesWithMice.info
Sun May 5 02:26:16 EDT 2024


Hi Leam,

On 5/05/24 10:42, Alan Gauld via Tutor wrote:
> On 04/05/2024 20:44, Leam Hall wrote:
> 
>> TBQ, the Report class is a builder inside the Chapter class.
> 
> I think the question is, why a class and not just a function?
> You could just have a report module with a report_data() function
> that takes the same inputs as the constructor. There is no real
> value in creating an instance of the class since it does not
> hold any useful state(the individual reports could be created
> on demand) The argument for retaining a class is if you
> subsequently compare different chapter reports but then
> there should be comparison methods in the class...
> 
> So arguably you could clean up the code by removing the
> class and just making a module with a set of functions.

Yes, even this class-y guy was thinking the same.

Remember that a Python-module is also a self-contained name-space, and 
thus would give many of the advantages discussed.

Noted inconsistent spelling of "syllable".

Prefer not to have 'magic constants', but some might (quite reasonably) 
argue that:

     QUESTION_MARK = "?"

is more an affectation than adding quality to the code-base.

Found the word "grade" confusing/a mis-use. Usually it is referring to 
degrees of pass/fail, eg an examination; whereas this is about 
'readability'. Perhaps a (class) docstring would have helped, but 
silly-boys (like...) would probably jump to the incorrect assumption 
anyway...


-- 
Regards,
=dn


More information about the Tutor mailing list