Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'example:': 0.03; 'subsequent': 0.04; 'subject:Python': 0.05; 'none:': 0.05; 'false,': 0.07; 'none):': 0.07; 'variables.': 0.07; 'python': 0.09; '"if': 0.09; '(default': 0.09; 'ambiguity': 0.09; 'arguments,': 0.09; 'confuse': 0.09; 'def': 0.10; 'programmer': 0.11; 'language': 0.14; 'cases': 0.15; "'default',": 0.16; 'boolean': 0.16; 'cleaner': 0.16; 'constitutes': 0.16; 'dropping': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'means.': 0.16; 'none"': 0.16; 'wrote:': 0.17; 'examples': 0.18; 'code,': 0.18; 'code.': 0.20; 'equivalent': 0.20; 'trying': 0.21; 'required.': 0.22; 'work.': 0.23; 'statement': 0.23; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'common': 0.26; 'lines': 0.28; 'trouble': 0.28; 'comparison': 0.29; 'dictionary': 0.29; 'testing.': 0.29; 'time:': 0.29; 'types.': 0.29; 'this.': 0.29; "i'm": 0.29; 'knows': 0.30; 'lists': 0.31; 'code': 0.31; 'point': 0.31; 'could': 0.32; 'print': 0.32; 'to:addr:python- list': 0.33; 'thanks': 0.34; 'list': 0.35; 'along': 0.35; 'mine': 0.35; 'said,': 0.35; 'pm,': 0.35; 'sometimes': 0.35; 'too.': 0.35; 'there': 0.35; 'received:org': 0.36; 'really': 0.36; 'but': 0.36; 'message-id:@gmail.com': 0.36; 'programmers': 0.36; 'should': 0.36; 'why': 0.37; 'detail': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'things': 0.38; 'gives': 0.39; 'to:addr:python.org': 0.39; 'takes': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'header:Received:5': 0.40; 'most': 0.61; 'more.': 0.62; "you'll": 0.62; 'is.': 0.62; 'email addr:gmail.com': 0.63; 'more': 0.63; 'show': 0.63; 'unnecessary': 0.65; 'finally': 0.66; 'study': 0.66; 'enjoy': 0.67; 'truth': 0.75; 'absolutely': 0.84; 'clearer': 0.84; 'concept,': 0.84; 'confusing': 0.84; 'fact.': 0.84; 'idiom': 0.84; 'incredibly': 0.96 X-Virus-Scanned: amavisd-new at torriefamily.org Date: Sat, 23 Feb 2013 11:58:39 -0700 From: Michael Torrie User-Agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.12) Gecko/20130105 Thunderbird/10.0.12 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Python Newbie References: <5c262e95-b3a8-4f2a-b752-84b30bf4f81e@googlegroups.com> <52a5d2ab-5cf8-483f-b0b0-15260e4bda2a@googlegroups.com> In-Reply-To: <52a5d2ab-5cf8-483f-b0b0-15260e4bda2a@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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: 57 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361645928 news.xs4all.nl 6845 [2001:888:2000:d::a6]:41485 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39700 On 02/21/2013 04:34 PM, piterrr.dolinski@gmail.com wrote: > Thanks for this. Regarding ambiguity, you will never find me write > ambiguous code. I don't sabotage my own work. But the reality is > that in addition to writing my own code, I have to maintain existing. > I find it incredibly confusing then I see a statement along the > lines of "if not something" - have to study the code in detail to see > what it is testing. As others have said, I don't see why this should be confusing. It's a common idiom that happens in C# or C all the time: if (!some_state) { //blah } There is absolutely no ambiguity here. Every C# and C programmer knows exactly what this means. As others have said, it's the equivalent of saying, ((bool)(expression) != True). Just in a cleaner way and in a way that echos how most programmers actually think. And in python, dropping the unnecessary comparisons actually gives you a speed up too. In python there is some ambiguity as to what constitutes a boolean truth or falsehood value for some types. For example, an empty list ([]) is false, as is an empty dictionary ({}), and a number is 0. And in some cases (default arguments, for example), using a "is None" comparison is required. For example: def some_function( a = None): # None is used above as the default because lists are # mutable, and if a list were placed up there it would # affect all subsequent calls to some_function() if a is None: a = [ 'default', 'values', 'here'] for x in a: print x some_func() some_func(1,2,3) > I could show more examples of what I find confusing in existing > code, but I don't intent to troll. I'm just trying to understand the > language as it is. I will see how it goes. As long as you are trying to write C# code in Python, you'll be very frustrated. Takes some time to learn about what it means to write "pythonic" code. You'll be well-served and you will start to enjoy the language more. Ditch the excess parenthesis. They don't make things clearer necessary and they really confuse what is a statement with what is an expression (a pet peeve of mine with C). Finally take some time to learn about how Python works from a language theory point of view. One interesting thing you'll learn is that python actually has no variables. This is a powerful concept, but can get you in trouble sometimes when you're not aware of this fact.