Kent Johnson said unto the world upon 2005-02-16 05:58:
Brian van den Broek wrote:

<SNIP Kent's useful explanation of how to use handlers>

Also, I know the general security concerns about things like exec. They make me nervous in using it, even though I am (as yet) the sole user. Am I right in thinking that the constrained way I am using it here protects me? My code uses most of the attributes as a simple storage container for later rewriting of the file, but in a few cases they enter into (safe seeming) conditionals like:

if 'text' == self.document_type:
   self.do_text_stuff()
if 'RTF' == self.document_type:
   self.do_RTF_stuff()


Conditionals on a 'type' flag are a code smell that suggests using subclasses. Maybe you should have a TextNode class and an RtfNode class. Then the above becomes just
self.do_stuff()


and TextNode and RtfNode each have the appropriate implementations of do_stuff().

I'm not saying this is the right choice for you, just something you might consider.

Kent

Hi Kent,

thanks for the snipped discussion on handlers -- very useful.

As for the code smell thing, I have a follow-up question. I now get the point of the type-based conditional being a smell for classes. (I get it due to a previous thread that an over-enthusiastic inbox purge prevents me from citing with certainty, but I think it was Bill and Alan who clarified it for me.)

My problem is that I've got a lot of code which was written before I got that point and my code doesn't yet actually do much. (I do have working code for parsing my original source files and storing all of their metadata, etc., but I haven't yet got working code for doing the manipulating the data in the ways I want.)

I had been thinking better to get everything working and then refactor. Is that an unsound approach? My worry about refactoring now is that I feel like I am rearranging deck-chairs when I should be worried about getting the ship to float :-)

Thanks and best to all,

Brian vdB

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to