Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'encoding': 0.05; 'explicitly': 0.05; 'string.': 0.05; 'subject:Python': 0.06; '*not*': 0.07; 'float': 0.07; 'string': 0.09; 'covered.': 0.09; 'forcing': 0.09; 'objects,': 0.09; 'pointless': 0.09; 'strings.': 0.09; 'wrong,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'jan': 0.12; 'stored': 0.12; 'suggest': 0.14; 'mostly': 0.14; "wouldn't": 0.14; '(note': 0.16; 'agree.': 0.16; 'buffers,': 0.16; 'bugs.': 0.16; 'coercion': 0.16; 'coercions': 0.16; 'debugging,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'ideal.': 0.16; 'ideally,': 0.16; 'operation.': 0.16; 'operations*': 0.16; 'programmer,': 0.16; 'rarely': 0.16; 'repr': 0.16; 'repr()': 0.16; 'sane': 0.16; 'str()': 0.16; 'string:': 0.16; 'sure.': 0.16; 'them...': 0.16; 'sat,': 0.16; 'language': 0.16; 'wrote:': 0.18; '(but': 0.19; "python's": 0.19; 'typing': 0.19; 'seems': 0.21; 'import': 0.22; 'saying': 0.22; 'cc:addr:python.org': 0.22; '31,': 0.24; 'alternate': 0.24; 'convenient': 0.24; 'helper': 0.24; 'instance,': 0.24; 'integer': 0.24; 'replace': 0.24; 'string,': 0.24; 'cc:2**0': 0.24; 'possibly': 0.26; 'post': 0.26; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'function': 0.29; 'raise': 0.29; 'related': 0.29; 'converting': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'that.': 0.31; 'closer': 0.31; "d'aprano": 0.31; 'implicit': 0.31; 'steven': 0.31; 'allows': 0.31; 'class': 0.32; 'there.': 0.32; 'sense': 0.34; 'maybe': 0.34; 'could': 0.34; "can't": 0.35; 'display': 0.35; 'except': 0.35; 'something': 0.35; 'convert': 0.35; 'objects': 0.35; 'operations': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'object,': 0.36; 'doing': 0.36; 'method': 0.36; 'useful': 0.36; 'should': 0.36; 'error.': 0.37; 'being': 0.38; 'server': 0.38; 'pm,': 0.38; 'little': 0.38; 'anything': 0.39; 'does': 0.39; 'though,': 0.39; 'system.': 0.39; 'how': 0.40; 'new': 0.61; 'you.': 0.62; 'complete': 0.62; 'more': 0.64; 'taking': 0.65; 'relatively': 0.65; 'between': 0.67; 'default': 0.69; 'saving': 0.69; 'subject:! ': 0.74; "'foo'": 0.84; '2015': 0.84; 'float,': 0.84; 'gains': 0.84; 'pike': 0.84; 'risking': 0.84; 'cast': 0.91; 'magical': 0.91; 'thing,': 0.91; 'to:none': 0.92; 'hand,': 0.93; 'imagine': 0.93; 'serious': 0.97 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=enpe1mbAG6delwgblFa4oekm/19A13hFySKoN1voj4A=; b=cCA98cM2xKeLxG3fh6Z8+LRtYFFRnIr3WNeBKYGoXXXQE0ANY1l4AHXQ3saCFUO5eF WbatJA17c74cob5JH8KsYzOmIWVO9oQJWjdN3Auv6MZezPzar+c7ef/9Fn+7MwOyAaYa kyuq0sqDCPopphwwS4+7X3dBcsTjzQ8UygyKktPHRTnBROGWYYTm6c9wSdUAyRhSWhOz 1gpxRabdTkEP71KWs9WrMOIRjtApRKvZI6GqcTZRrICtjXNTprRaiZdNp+vEoCyqkQpY l6VPoakmnFdPaQDjiVUK0ZktZSft44bymHf+e37QOtHZWvBiOFrbTIaurOrytghvg3Ne FZqw== MIME-Version: 1.0 X-Received: by 10.107.158.146 with SMTP id h140mr13134269ioe.27.1422715997609; Sat, 31 Jan 2015 06:53:17 -0800 (PST) In-Reply-To: <54ccc2fc$0$13009$c3e8da3$5496439d@news.astraweb.com> References: <54c07d04$0$13012$c3e8da3$5496439d@news.astraweb.com> <1939680766443642112.878725sturla.molden-gmail.com@news.gmane.org> <6eb91c4b-92ff-44a8-b5a9-6ef04c71f4cb@googlegroups.com> <35a40ec6-3763-448b-9ea4-4a233a04979b@googlegroups.com> <54c1ccc8$0$13005$c3e8da3$5496439d@news.astraweb.com> <54c6d7c2$0$12992$c3e8da3$5496439d@news.astraweb.com> <54c83ab4$0$12982$c3e8da3$5496439d@news.astraweb.com> <54ca583e$0$13005$c3e8da3$5496439d@news.astraweb.com> <54ccc2fc$0$13009$c3e8da3$5496439d@news.astraweb.com> Date: Sun, 1 Feb 2015 01:53:17 +1100 Subject: Re: Python is DOOMED! Again! 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: 74 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1422716000 news.xs4all.nl 2905 [2001:888:2000:d::a6]:35004 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:84955 On Sat, Jan 31, 2015 at 10:56 PM, Steven D'Aprano wrote: > Both ints and floats are models of the same abstract thing, namely "number". > Ideally, from a mathematically standpoint, there should be no difference > between 23 and 23.0. Automatic coercions allow us to get a little closer to > that ideal. So far, I'm mostly with you. (Though if your float type is not a perfect superset of your integer type - as in Python - then the default "up-cast" from int to float, while disallowing a corresponding implicit "down-cast", seems flawed. But in concept, yes, automatic coercion allows us to treat 23 and 23.0 as the same.) > Arbitrary objects, on the other hand, are rarely related to strings. Given > that we need to be able to display arbitrary objects to the human > programmer, if only for debugging, we need to be able to *explicitly* > convert into a string: > > > py> import nntplib > py> SERVER = "news.gmane.org" > py> server = nntplib.NNTP(SERVER) > py> str(server) > '' Here, though, I'm not so sure. Why should you be able to *type-cast* anything to string? Python has another, and perfectly serviceable, function for converting arbitrary objects into strings, and that's repr(). It would make perfect sense for a language to make this distinction much more stark: 1) str() attempts to convert something into a string. It can do this automatically in the case of "string-like" objects (eg buffers, maybe some magical things that come from databases), and can convert others with help (eg bytes->string using an encoding parameter), but anything else will raise an error. 2) repr() guarantees to convert anything into a string. It does this in a relatively arbitrary fashion; you can write a helper method for your class to make this more useful to the human. #2 is how Python's repr already functions, so explicitly converting arbitrary objects into strings is covered. The idea that we can str() them as well isn't necessarily part of a sane typing system. (Note that I'm not saying that Python got it wrong, here; just that taking the alternate choice would also be not-wrong.) > but doing so *implicitly* gains us nothing except the saving of a few > keystrokes, while risking serious bugs. Complete and automatic casting to string, I would agree. However, I would suggest that there are a few *binary operations* which could be more convenient if they allowed some non-strings. For instance, Pike allows addition of strings and integers: "1" + 2 == "12", where Python requires "1" + str(2) for the same operation. (But Pike does *not* allow just any object there. Only a few, like numbers, can be quietly cast on being added to strings.) > Forcing all arbitrary objects to > support string operations would be pointless and confusing. What could this > possibly mean? > > server.replace('7', 'FOO') Well duh, you would go to the server and replace the 7th stored post with the new body 'FOO' :) Strings have *tons* of methods. There's no way you'd want them all on every object, and it wouldn't make sense. You definitely don't up-cast everything to string just to use methods on them... I can't imagine any (sane) language ever doing that. ChrisA