From: Waylan L. <wa...@gm...> - 2008-11-14 14:44:59
|
On Fri, Nov 14, 2008 at 4:44 AM, Yuri Takhteyev <qar...@gm...> wrote: > Now that we are changing so much, I want to propose a change that has > been on my mind for quite some time. Back in the day I made a > decision to implement all processors as classes. Since then I've been > thinking that perhaps implementing them simply as functions would make > things a lot easier and intuitive. It may make some complicated cases > a little more complicated, but will simplify the simple cases, which Meh. I'v thought about this before and even wondered why you used classes back when I started my first extension, but the class gives us so much more. Look at the InlinePatterns. Many of them are subclasses that override only part of the functionality. In fact, a few don't even have a run method, they just override an auxiliary method. Actually, there are quite a few auxiliary methods that would now litter the markdown namespace unnecessarily. Using classes keeps things neat, compartmentalized, and DRY. On a related note, when I first started to write the new BlockParser, I was intending to use functions rather than classes for the processors, but it quickly became clear that classes were a much better solution. And then there are a few extensions in which I use the class to remember state. That wouldn't work with a function. Yeah, we can always keep state on the Markdown instance, but if the only place we use that state is within one processor, why litter the Markdown instance? Personally, if you made this change, I would still be inclined to use classes with the ``__call__`` method in place of the current ``run`` method to simulate a function. But even then, as callables can't be instances, I couldn't override ``__init__`` to pass in extra arguments and/or set state on init. > would make it easier for people to write simple extensions. I agree this is important, but I think the answer is good documentation. Have you read my documentation [1] for writing extensions (the core parser part needs updating)? Once it's all spelled out, it doesn't seem that hard IMO. [1]: http://gitorious.org/projects/python-markdown/repos/mainline/blobs/master/docs/writing_extensions.txt -- ---- Waylan Limberg wa...@gm... |