On Thu, Jan 9, 2020 at 5:28 AM Edward K. Ream <edream...@gmail.com> wrote:
> On Wed, Jan 8, 2020 at 10:49 PM Brian Theado <brian.the...@gmail.com> > wrote: > > *>> Prefer functions to classes/methods* > > > The TokenOrderTraverser class looks to me like a good opportunity to > follow the above principle. AFAICT, the way it is written, that class is > ONLY useful if it is subclassed. > > True. > I'm guessing this is a response only to my 2nd sentence and not both sentences? > > > For me, subclassing is usually extra friction and the resulting code is > less clear. > > Without a class, you would have to implement visit as a callback. > Isn't the purpose of 'visit' to be able to loop over the nodes? Sounds like the job of a for loop to me. No callbacks and no classes needed. Having the traverse functionality reside in a method of TOT forces the user to subclass. Extracting it into a separate function like traverse_in_token_order allows the user to choose to use a for loop instead. The TOT class can still exist. It would call the same traverse_in_token_order convenience function. If the user want to do the extra work of subclassing TOT, they still can. Brian -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/CAO5X8CyfcQRWX7yPHWXaSY-tdJ%3DxRhtWH_7qZyJfvm1XcJYMZA%40mail.gmail.com.