Thursday, July 10, 2014

Writing a great end-user-friendly configuration publisher in Python

The parser with regard to fetchmail's configuration file syntax is pretty elaborate. It's actually written in YACC in addition to Lex, two classic UNIX resources for generating language-parsing rule in C. In order for fetchmailconf in order to edit existing setting files, I thought it must replicate that detailed parser in Python. I was very reluctant to do this, partly because of the quantity of work involved along with partly because My spouse and i wasn't sure the best way to ascertain that two parsers in a pair of different languages accept identical. The last issue I needed was the excess labor of keeping both the parsers in synchronization because the configuration language advanced!

This python professionals problem stumped me for quite a while. Then I received an inspiration: I'd let fetchmailconf use fetchmail's own parser! I added a --configdump option to fetchmail that might parse. Fetchmailrc and dump the result to standard output within the format of some sort of Python initializer. For the report above, the result would likely look roughly just like Listing 2 (to save lots of space, some data not relevant to the example will be omitted).

Not that this took me very long to learn the actual feature set. I wrote a functional, usable fetchmailconf, with GUI, in six business days, of which perhaps roughly the same as two days ended up spent learning Python by itself. This reflects another useful property from the language: it is compact--you can take its entire function set (and at least a concept listing of its libraries) in your head. C is any famously compact words. Perl is notoriously not; one of what exactly the notion “There's several way to do it! ” costs django experts could be the possibility of compactness.
This was our first clue in which, in Python, I was actually working with an exceptionally beneficial design. Most languages have a whole lot friction and awkwardness built in their design that you just learn most of the feature set long before your misstep price drops anywhere close to zero. Python was the primary general-purpose language I would ever used that reversed this technique.
When you are writing working rule nearly as fast that you can type and your misstep rate can be near zero, it generally suggests you've achieved mastery of the language. But that didn't make sense, because it was still day one particular and I has been regularly pausing to take a look up new dialect and link library characteristics!
But my nearly all dramatic moment connected with discovery lay ahead of time. My design had an issue: I could easily generate configuration files through the user's GUI activities, but editing all of them was a very much harder problem. Or, rather, reading them straight into an editable form was a problem.
.

No comments:

Post a Comment