Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.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; 'operator': 0.03; 'subject:Python': 0.05; 'mrab': 0.05; 'rejected': 0.05; 'type,': 0.07; '22,': 0.09; 'creighton': 0.09; 'instance.': 0.09; 'typeerror:': 0.09; 'types:': 0.09; 'python': 0.11; 'example:': 0.11; 'value.': 0.15; 'logical.': 0.16; 'object()': 0.16; 'sentinel': 0.16; 'typeof': 0.16; 'wrote:': 0.16; 'string': 0.17; 'basically': 0.18; 'integer': 0.18; 'laura': 0.18; 'refers': 0.18; 'versions': 0.20; 'fix': 0.21; 'saying': 0.22; 'object.': 0.22; 'suppose': 0.22; '2015': 0.23; 'header:In-Reply-To:1': 0.24; 'properties': 0.24; 'equivalent': 0.27; 'wonder': 0.27; 'message- id:@mail.gmail.com': 0.28; 'subject:other': 0.29; 'fri,': 0.31; 'subject:all': 0.32; 'null': 0.33; 'received:google.com': 0.34; 'could': 0.35; 'to:addr:python-list': 0.35; 'acceptable': 0.35; 'exist': 0.35; 'instance': 0.35; 'replace': 0.35; 'sometimes': 0.35; 'but': 0.36; 'too': 0.36; 'there': 0.36; 'should': 0.37; 'subject:: ': 0.37; 'doing': 0.38; 'pm,': 0.39; 'to:addr:python.org': 0.39; 'some': 0.40; 'even': 0.61; 'caused': 0.61; 'home': 0.67; 'discover': 0.73; 'subject:have': 0.80; "'object'": 0.84; 'conclude': 0.84; 'to:name:python': 0.84; 'subject:you': 0.88 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=mrqeHkJ745F/qVxyGKqdXg4aAq0pdKEMX/ntLlDlo4M=; b=y+LzF+M2Y2EatDssce/GZniSMDumMuqtjfXepTBkUCBi/McDYwY1b7hMZA3XAqnX4R XxtZaCqcTaxq1vaPcR3qsRpbElvO9wokass6LnBZ76nGBxmswgEa3hVzdGCVSivRj1cs 3AFiBwGivEKkhed5FC+8rFO9l0ym2JROq6oZSdTrRkOBxByDiJNJFInpMVDxwA3QVUre KfeakkPpXqFKplULmLYfEg2ft5ws/4CHgDPxcPxrpr8zlr5A6VJenM+zqbcefc6uA1Ig GxHtl3gBmChAAvzT7MrRKZTSep9EN5z9Kn9MeRAdRmdGeSCbr/ufu/Kig6SmBVNCIbbH 1vOw== X-Received: by 10.50.225.35 with SMTP id rh3mr7794910igc.29.1432324656585; Fri, 22 May 2015 12:57:36 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <555F84CD.9010204@mrabarnett.plus.com> References: <555f440a$0$12990$c3e8da3$5496439d@news.astraweb.com> <201505221914.t4MJE3e9009120@fido.openend.se> <555F84CD.9010204@mrabarnett.plus.com> From: Ian Kelly Date: Fri, 22 May 2015 13:56:56 -0600 Subject: Re: Ah Python, you have spoiled me for all other languages To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1432324665 news.xs4all.nl 2932 [2001:888:2000:d::a6]:41164 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:91069 On Fri, May 22, 2015 at 1:34 PM, MRAB wrote: > On 2015-05-22 20:14, Laura Creighton wrote: >> >> The first time you discover that in javascript typeof(null) is 'object' >> and >> not 'null' you will scream. I wonder how many home versions of typeof >> to replace the system one exist out in the wild? >> > I don't think that typeof(null) should be 'null'. > > If the type of an integer instance is the integer type and the type of > a string instance is the string type, then the type of null should be > the null type, not a null instance. > > I suppose that you could consider that what JavaScript is doing is > equivalent to saying in Python that: > > None = object() > > like you sometimes do when you want a unique sentinel because None > itself would be an acceptable value. If only it were that logical. null in Javascript is a primitive type. Here's what typeof returns on some other primitive types: js> typeof(4) "number" js> typeof(4.5) "number" js> typeof('hello') "string" js> typeof(true) "boolean" js> typeof(undefined) "undefined" An "object" in Javascript is basically just a collection of properties. For example: js> typeof([1, 2, 3]) "object" js> typeof({a: 1, b: 2, c: 3}) "object" Here's what happens when you try to access a property on null: js> null.foo typein:18:0 TypeError: null has no properties We can conclude that null is not an object. Even the MDN reference page for the typeof operator refers to this as "bogus". There was a proposal to fix this in ECMAScript 5.1, but it was rejected because it caused too much breakage.