Re: [Pyparsing] Proposed notational shortcut for setResultsName
Brought to you by:
ptmcg
From: Jean-Paul C. <ex...@di...> - 2007-05-25 13:41:58
|
On Fri, 25 May 2007 01:20:14 -0500, Paul McGuire <pa...@al...> wrote: > [snip] > >Please don't focus on the fact that [] is implemented using __getitem__, or >that [] implies that we are "getting" anything - does this notation seem >like a reasonable shortcut, in place of the following? > >stats = "AVE =" + realNum.setResultsName("average") + "STD. DEV. =" + >realNum.setResultsName("stdDevn") + \ > "MIN =" + realNum.setResultsName("min") + "MAX =" + >realNum.setResultsName("max") > >Or, if you really want to think of this as a "getting" kind of operation, >you could interpret this notation as indicating that realNum["average"] is >getting for us a special form of realNum that names its returned tokens >"average". For that matter, it also mirrors the dict-style format for >retrieval of the data: > >results = stats.parseString( inputData ) >print results["average"] > The advantage of setResultsName over __getitem__ is what it suggests to a reader solely through its name. Throwing that away makes result naming a more expensive feature, since it becomes exceedingly likely to confuse a reader who isn't already familiar with the API. Perhaps worse, it's much more difficult to search for the API documentation for __getitem__ than it is to search for the API documentation for setResultsName. The suggested `_' method is just as bad, as far as obviousness goes, but at least it wins out in that searching for its documentation is easier. Ultimately, setResultsName doesn't bother me at all. Typing out identifiers isn't anywhere near the biggest expenditure of my time. I'd much rather have a clearly named method than an overloaded operator. Jean-Paul |