Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; ';-)': 0.03; 'yet.': 0.04; 'subsequent': 0.05; 'subject:Question': 0.07; '(aka': 0.09; 'check,': 0.09; 'components,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:skip:a 10': 0.09; 'vast': 0.09; 'python': 0.11; 'anyway': 0.14; '(and,': 0.16; '18:13,': 0.16; 'bracket': 0.16; 'brackets': 0.16; 'check.': 0.16; 'chris,': 0.16; 'clauses': 0.16; 'discarded': 0.16; 'downside': 0.16; 'grouped': 0.16; 'messy': 0.16; 'mixture': 0.16; 'nesting': 0.16; 'nightmare': 0.16; 'placeholder': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'pushed': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'bit': 0.19; 'separate': 0.22; 'tests': 0.22; 'header:User-Agent:1': 0.23; 'entries': 0.24; 'mon,': 0.24; 'sort': 0.25; 'this:': 0.26; 'least': 0.26; 'gets': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'chris': 0.29; 'points': 0.29; 'charged': 0.30; 'evaluation': 0.30; '(which': 0.31; 'gives': 0.31; 'getting': 0.31; 'lines': 0.31; 'software,': 0.31; '(unless': 0.31; 'bad.': 0.31; 'ordinary': 0.31; 'option': 0.32; 'implemented': 0.33; 'could': 0.34; 'requirement': 0.35; 'but': 0.35; 'there': 0.35; 'described': 0.36; 'his/her': 0.36; 'much.': 0.36; 'entry': 0.36; 'too': 0.37; 'two': 0.37; 'implement': 0.38; 'loss': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'pm,': 0.38; 'that,': 0.38; 'little': 0.38; 'explain': 0.39; 'extremely': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'users': 0.40; 'how': 0.40; 'even': 0.60; 'simple,': 0.60; 'tell': 0.60; 'free': 0.61; 'full': 0.61; 'range': 0.61; 'simple': 0.61; "you're": 0.61; 'first': 0.61; 'times': 0.62; "you've": 0.63; 'costs': 0.63; 'group,': 0.63; 'choose': 0.64; 'our': 0.64; 'more': 0.64; 'approved': 0.65; 'finally': 0.65; 'assistance': 0.66; 'here': 0.66; 'six': 0.68; '20,': 0.68; 'combining': 0.68; 'frank': 0.68; 'line,': 0.68; 'overall': 0.69; 'business': 0.70; 'safe': 0.72; 'bulk': 0.74; 'cut': 0.74; "'and'": 0.84; 'complexity': 0.84; 'everything.': 0.84; 'dirty': 0.93; 'hands': 0.96; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Frank Millman Subject: Re: Question about ast.literal_eval Date: Tue, 21 May 2013 08:46:08 +0200 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 197.87.30.233 User-Agent: Mozilla/5.0 (Windows NT 5.2; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 61 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369118786 news.xs4all.nl 15992 [2001:888:2000:d::a6]:45886 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45646 On 20/05/2013 18:13, Chris Angelico wrote: > On Mon, May 20, 2013 at 11:26 PM, Frank Millman wrote: >> 0 - for the first entry in the list, the word 'check' (a placeholder - it is >> discarded at evaluation time), for any subsequent entries the word 'and' or >> 'or'. >> >> 1 - left bracket - either '(' or ''. >> >> 5 - right bracket - either ')' or ''. > > I think what you have is safe, but extremely complicated to work with. > Six separate pieces, and things have to be in the right slots... I > think you've spent too many "complexity points" on the above three > components, and you're getting too little return for them. What > happens if the nesting is mucked up? Could get verrry messy to check. > > Combining multiple conditions with a mixture of ands and ors is a > nightmare to try to explain (unless you just point to the Python docs, > which IMO costs you even more complexity points); the only safe option > is to parenthesize everything. The system I pushed for at work (which > was finally approved and implemented a few months ago) is more or less > this: conditions are grouped together into blocks; for each group, you > can choose whether it's "all" or "any" (aka and/or), and you choose > whether the overall result is all-groups or any-group. That still > costs a few complexity points (and, btw, our *actual* implementation > is a bit more complicated than that, but I think we could cut it down > to what I just described here without loss of functionality), but it > gives the bulk of what people will actually want without the > complexities of point-and-click code. > > The downside of that sort of system is that it requires a two-level > tree. On the flip side, that's often how people will be thinking about > their conditions anyway (eg using a pair of conditions ">" and "<" to > implement a range check - conceptually it's a single check), so that > won't cost too much. > You may be right, Chris, but I don't think my approach is all that bad. The vast majority of tests will be simple - either a single line, or two lines for a range check, with no brackets at all. If the requirement is more complicated than that, well, I don't think the complication can be avoided, and at least this approach gives full control. FWIW, I use the same approach to allow users to construct their own WHERE clauses in custom views. Again, the vast majority are simple, but there are times when it can get complicated. The proof of the pudding will be when I try to get ordinary users to get their own hands dirty - I am not there yet. If I ever get this released, the business model will be free software, but support will be charged for. So if a user gets out of his/her depth, there will be assistance available. Time will tell who is right ... ;-) Frank