Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'value,': 0.03; 'explicitly': 0.04; 'true,': 0.04; 'subject:Python': 0.05; 'none,': 0.05; 'scripts': 0.09; 'python': 0.09; 'ambiguity': 0.09; 'bool': 0.09; 'integers': 0.09; 'worse': 0.09; 'sat,': 0.15; '(ubuntu': 0.16; '4-byte': 0.16; 'boolean': 0.16; 'conditional': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'integers,': 0.16; 'sequential': 0.16; 'true:': 0.16; 'word"': 0.16; 'wrote:': 0.17; 'bytes': 0.17; 'integer': 0.17; 'creates': 0.18; 'code,': 0.18; 'feb': 0.19; 'holds': 0.20; 'explicit': 0.22; 'long,': 0.24; 'least': 0.25; 'header:In-Reply-To:1': 0.25; 'wrote': 0.26; 'am,': 0.27; 'implemented': 0.27; 'functions.': 0.27; 'see,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'lines': 0.28; 'received:209.85.212': 0.28; 'cpu': 0.29; 'really,': 0.29; 'statements': 0.29; 'strings,': 0.29; 'types.': 0.29; "we're": 0.30; 'on,': 0.30; 'asking': 0.32; 'null': 0.33; 'to:addr:python- list': 0.33; 'languages': 0.33; 'likely': 0.33; 'that,': 0.34; 'received:google.com': 0.34; 'server': 0.35; 'adds': 0.35; 'sometimes': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'really': 0.36; 'but': 0.36; 'smaller': 0.36; 'anything': 0.36; 'test': 0.36; 'should': 0.36; 'problems': 0.36; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'store': 0.38; 'files': 0.38; 'easier': 0.38; 'fact': 0.38; 'some': 0.38; 'things': 0.38; 'performance': 0.39; 'to:addr:python.org': 0.39; 'think': 0.40; 'your': 0.60; 'most': 0.61; 'containing': 0.61; 'kind': 0.61; 'different': 0.63; 'helping': 0.63; 'today,': 0.64; 'talking': 0.66; 'obvious': 0.71; '2013': 0.84; 'hit.': 0.84; 'inherent': 0.84; 'canonical': 0.91; 'story.': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type:content-transfer-encoding; bh=IBVoy7Twc5gJzTZ59h0J3mnJHdFpMc3P2QZqoOYw5tk=; b=qCsjH2JYL7T9Y7PIC3x9eFpDWLWnMgDuLJ/++llm3nfvDamNh/McHDaX7ir4Rdm9yd FlVfi7puawTNl9DyFncM9qzqk/hKKvGoMmQ3umdb55SWMDdOwNEoj2GJByV9XtKsF8LA 49lDMAuF5Tyz16/VFy6Afk1B8mNbz69JZ1tRdWhzsQp+7EPgg2b6xkjN+uLCdYNyyU6O bWHwGX9bTTEKGnQxzOZpSaKN1hneDjCNsSA84p2U0tff+0NY4oQPDcpV1qrAoK39cDDn vjO/rtTWqPj0h8i8cPmMAhI98DvBaD1lZezueuBvU5ix3J0gxKhTWI82jMnggEyQ27qQ 45xw== MIME-Version: 1.0 X-Received: by 10.58.253.161 with SMTP id ab1mr5249413ved.55.1361578677810; Fri, 22 Feb 2013 16:17:57 -0800 (PST) In-Reply-To: <8eadd52c-d533-4333-8c7f-7bf3a6d7b046@googlegroups.com> References: <5127848B.1060004@gmail.com> <928d2cf7-728b-4f35-b8c9-4c9b958507e5@googlegroups.com> <8eadd52c-d533-4333-8c7f-7bf3a6d7b046@googlegroups.com> Date: Sat, 23 Feb 2013 11:17:57 +1100 Subject: Re: Python Newbie From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361578681 news.xs4all.nl 6949 [2001:888:2000:d::a6]:35223 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39632 On Sat, Feb 23, 2013 at 10:38 AM, wrote: > I think this obvious shortcomming is the main reason that, for example, w= hen x holds the value of 5, x is considered to be "true". You see, I have t= o maintain Python files (ubuntu server scripts) which are 2000 lines long, = all sequential code, no functions. While the person who wrote them should b= e shot :), the fact that there is inherent ambiguity with value, none, null= 0, you name it, in conditional statements is not helping me understand the= code, and this adds to my frustration. When you want to clearly ask if something is the specific value True, you can do that thus: if x is True: That's the canonical ("pythonic") way to explicitly check for a boolean value, in the same way that PHP scripts test strpos(...)=3D=3D=3DFALSE. > Btw, there are still languages with no boolean type today, MySQL for one.= This creates big efficiency problems when fetching data from the database = into a C# program - what should be a bool is fetched as an 8-byte integer! = But that's a different story. I shut up now. It's really not that big a deal to have or not have an explicit boolean type. Ultimately, the CPU is going to work with integers, booleans, strings, and so on, in the same way, and that most likely will be an integer of at least 4 bytes in size - the "machine word" for your architecture. Asking for anything smaller comes with a performance hit. So it's easier to store and manage booleans as 4-byte or 8-byte integers containing either 1 or 0, than to have some kind of "bit" type - unless we're talking about a *set* of booleans, which is sometimes implemented as bitflags. Really, there are worse things in the world. Don't get het up about boolean types. :) ChrisA