Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.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; 'argument': 0.05; 'explicitly': 0.05; '*not*': 0.07; 'class,': 0.07; 'alain': 0.09; 'annotations': 0.09; 'bits': 0.09; 'comment,': 0.09; 'lawrence': 0.09; 'lookup': 0.09; 'typed': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '[1].': 0.16; '[2].': 0.16; 'expecting': 0.16; 'fiddle': 0.16; 'for,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'integer,': 0.16; "object's": 0.16; 'objects.': 0.16; 'ought': 0.16; 'overriding': 0.16; 'pulling': 0.16; 'pythonic': 0.16; 'think.': 0.16; 'variables,': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'variable': 0.18; '>>>': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'integer': 0.24; 'pointer': 0.24; 'cc:2**0': 0.24; 'pass': 0.26; 'header:In-Reply- To:1': 0.27; 'function': 0.29; '[1]': 0.29; 'am,': 0.29; "doesn't": 0.30; '[2]': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '>>>>': 0.31; 'accidentally': 0.31; 'object.': 0.31; 'writes:': 0.31; 'languages': 0.32; 'up.': 0.33; 'fri,': 0.33; "can't": 0.35; 'something': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'c++': 0.36; 'method': 0.36; 'list': 0.37; 'list,': 0.38; 'rather': 0.38; 'called': 0.40; 'up,': 0.60; 'skip:* 10': 0.61; 'different': 0.65; 'great': 0.65; 'risk': 0.72; 'subject:This': 0.74; "class's": 0.84; 'everywhere.': 0.84; 'float,': 0.84; 'safety.': 0.84; 'take,': 0.84; 'thrust': 0.84; 'mistakenly': 0.91; 'to:none': 0.92 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=OGcd7J1sdLeZQASnWOLVQDHC8oZ9HPqXdHxkpDFwZac=; b=bZxDuJBDrXX+ct9KpeZPeuMo0tuKzjpXMmeLKyl+Vk9lzRAfBlkicz+8c/C/VOH0nl I82Hv0lRtALL69FqjabG5KZpj7vTImOGd/y/8mgQTZ+TN0WHSPDLCaY+HbPY91SuvGR/ JSJfKrDAFv9ikluYbltUYuqRiUiV9TBw8jF69tKsVztJ7Zd894sPzN0s8skpQHq9/NvI 41A7oz6GUTLclJf6JnDd2+hhRwMXfAj+DDRLOrmHwAXF22t01qi0FG4BC76Ha0ePgcAd tXfBk7C78aWIMqK7d32X570LEZw8RRTht7Ux6uQlGdATrdsCUyWnPb2HdiG9fAGaETsS kYdw== MIME-Version: 1.0 X-Received: by 10.52.244.84 with SMTP id xe20mr423435vdc.3.1402004193922; Thu, 05 Jun 2014 14:36:33 -0700 (PDT) In-Reply-To: References: <8738fjkc2w.fsf@dpt-info.u-strasbg.fr> <87tx7zi0i1.fsf@dpt-info.u-strasbg.fr> Date: Fri, 6 Jun 2014 07:36:33 +1000 Subject: Re: OT: This Swift thing From: Chris Angelico Cc: "python-list@python.org" 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: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1402004202 news.xs4all.nl 2836 [2001:888:2000:d::a6]:37443 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:72769 On Fri, Jun 6, 2014 at 7:23 AM, Mark Lawrence wrote: > On 05/06/2014 21:07, Alain Ketterlin wrote: >> >> Sturla Molden writes: >> >>> On 05/06/14 10:14, Alain Ketterlin wrote: >>> >>>> Type safety. >>> >>> Perhaps. Python has strong type safety. >> >> Come on. > > I don't understand that comment, please explain. "Type safety" means many different things to different people. What Python has is untyped variables, and hierarchically typed objects. It's impossible to accidentally treat an integer as a float, and have junk data [1]. It's impossible to accidentally call a base class's method when you ought to have called the overriding method in the subclass, which is a risk in C++ [2]. If you mistakenly pass a list to a function that was expecting an integer, that function will *know* that it got a list, because objects in Python are rigidly typed. But some languages stipulate the types that a variable can take, and that's something Python doesn't do. If you want to say that this function argument must be an integer, you have to explicitly check it inside the function. (And the Pythonic thing to do is to *not* check it, but that's a separate point.) This is something that function annotations can be used for, but I'm not seeing a huge thrust to make use of them everywhere. Why not? I suspect because the need for it just isn't as great as some people think. ChrisA [1] Note that in some circumstances, you can (deliberately) fiddle with an object's type. But you can't just reinterpret the bits in memory, the way you can in C, by casting a pointer and dereferencing it. Hence, it's impossible to *accidentally* muck this up. [2] Again, you can muck things up, by explicitly pulling up a function from the base class, rather than using method lookup on the object. But again, you can't do it accidentally.