Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.06; '(especially': 0.07; 'attribute': 0.07; 'element': 0.07; 'json': 0.07; 'expense': 0.09; 'feature.': 0.09; 'key.': 0.09; 'lookup': 0.09; 'method,': 0.09; 'methods,': 0.09; 'parsing': 0.09; 'typed': 0.09; 'undefined': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'mildly': 0.16; 'notation,': 0.16; 'partly': 0.16; 'pause': 0.16; 'typeerror:': 0.16; 'types,': 0.16; '{};': 0.16; 'wrote:': 0.18; "python's": 0.19; 'aug': 0.22; 'cc:addr:python.org': 0.22; 'skip': 0.24; 'tend': 0.24; 'cc:2**0': 0.24; 'equivalent': 0.26; 'header :In-Reply-To:1': 0.27; 'function': 0.29; 'xml': 0.29; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'consequence': 0.31; 'convenience': 0.31; 'allows': 0.31; 'running': 0.33; "can't": 0.35; '(2)': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'var': 0.36; 'similar': 0.36; '(3)': 0.38; 'mapping': 0.38; 'pm,': 0.38; 'rather': 0.38; 'little': 0.38; 'anything': 0.39; 'does': 0.39; 'though,': 0.39; 'release': 0.40; 'skip:x 10': 0.40; 'cost.': 0.60; 'reaching': 0.61; "you're": 0.61; 'name': 0.63; 'more': 0.64; 'prompt': 0.68; 'square': 0.74; 'subject:For': 0.78; 'confusing': 0.84; 'pike': 0.84; 'shadow': 0.84; 'subject:Make': 0.91; 'to:none': 0.92; 'imagine': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=mVbdgYnIPcBZU8YT8Kp0glrqWIdU4619zDiifLOl5p8=; b=ivIqc/70Ydb7s60HAxKib3PKvUqZWfEz62TJ2NfWRKsPtB+y0bzN3x+SArvjmWdAzv NhpTUcn0W52tKtOWskZQfyYFjmPLo5E6Li5nUaH9yxVvLP1CeUmAdxQqEPlmphor4rt+ XuGs6I6Yeq0rynUkL69e9jpPyzxdp06w8MNdm9J/nOGPFwj0TOkWVkOMtVQmRITqRfGE P6ks16cn1RbZr/RtknoXqwrGw8IdwT0eWaySHujfoT1NwQOhriHiESwkycARFcTAZKsx rKh7Th5ouAHFuemwgLArFPfKjZNgI9l22fCRM2LNV5jCknoQc2JBCchAU22j1PMrxNlx SEsQ== MIME-Version: 1.0 X-Received: by 10.51.17.2 with SMTP id ga2mr6868173igd.2.1407243656962; Tue, 05 Aug 2014 06:00:56 -0700 (PDT) In-Reply-To: References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87k36nxhv8.fsf@elektro.pacujo.net> Date: Tue, 5 Aug 2014 23:00:56 +1000 Subject: Re: 3 Suggestions to Make Python Easier For Children From: Chris Angelico Cc: Python Content-Type: text/plain; charset=UTF-8 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: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1407243659 news.xs4all.nl 2867 [2001:888:2000:d::a6]:57908 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75736 On Tue, Aug 5, 2014 at 10:31 PM, Skip Montanaro wrote: > JavaScript objects have that feature. I find it mildly confusing > because whenever I see it I have to pause to consider whether the name > I am looking at is an attribute or a key. This little JS code I just > typed at my console prompt was also mildly surprising: > >> var x = {}; > undefined >> x.valueOf(47) > Object {} >> x["valueOf"] = 12 > 12 >> x.valueOf > 12 >> x.valueOf(47) > TypeError: number is not a function This is partly a consequence of prototype-based inheritance; x.valueOf will shadow Object.valueOf. Pike allows a similar "dot or square brackets" notation, but at the expense of not having any methods on the mapping type itself: Pike v8.0 release 3 running Hilfe v3.5 (Incremental Pike Frontend) > mapping a=([]); > a.foo="bar"; (1) Result: "bar" > a.foo; (2) Result: "bar" > a; (3) Result: ([ /* 1 element */ "foo": "bar" ]) Since mappings (broadly equivalent to Python dicts) can't have methods, anything that Python does as a method, Pike has to do as a stand-alone function. (Swings and roundabouts, though, as those functions tend to also accept other types, so they're more akin to Python's len() than dict.pop().) Every design decision has a cost. The convenience of short-handing mapping lookup is pretty handy (especially when you're digging into deeply-nested mappings - imagine parsing an XML or JSON message and then reaching into it for one specific thing), but it means there are functions rather than methods for working with them. Take your pick. ChrisA