Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!rt.uk.eu.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!news.nosignal.org!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; 'example:': 0.03; 'attribute': 0.05; 'override': 0.07; 'parameter': 0.07; 'strings.': 0.07; 'python': 0.09; 'cc:addr:googlegroups.com': 0.09; 'chunks': 0.09; 'cc:addr:python-list': 0.10; "wouldn't": 0.11; 'accordingly': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'naming': 0.16; 'overwriting': 0.16; 'pythonic': 0.16; 'received:202.125.174': 0.16; 'received:202.125.174.133': 0.16; 'received:boardofstudies.nsw.edu.au': 0.16; 'received:cskk.homeip.net': 0.16; 'received:edu.au': 0.16; 'received:harvey.boardofstudies.nsw.edu.au': 0.16; 'received:homeip.net': 0.16; 'received:nsw.edu.au': 0.16; 'simpson': 0.16; 'subject:type': 0.16; 'users.': 0.16; 'wrote:': 0.17; 'variables': 0.17; 'module': 0.19; 'trying': 0.21; 'bit': 0.21; '(usually': 0.22; 'stopping': 0.22; 'defined': 0.22; 'mention': 0.23; 'cc:2**1': 0.24; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'common': 0.26; 'convention': 0.27; 'experiences': 0.27; 'functions.': 0.27; 'comparison': 0.29; 'domain.': 0.29; 'end,': 0.29; 'goods': 0.29; 'occurred': 0.29; 'case,': 0.29; 'probably': 0.29; 'usually': 0.30; 'basic': 0.30; 'function': 0.30; 'primary': 0.30; 'code': 0.31; 'says': 0.33; 'avoiding': 0.33; 'problem': 0.33; 'that,': 0.34; 'built-in': 0.35; 'stores': 0.35; 'similar': 0.35; 'michael': 0.36; 'but': 0.36; 'cc:no real name:2**1': 0.36; 'received:au': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'possible': 0.37; 'bad': 0.37; 'uses': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'some': 0.38; 'where': 0.40; 'subject:-': 0.40; 'your': 0.60; 'content- disposition:inline': 0.60; 'amazing': 0.61; 'evaluate': 0.62; 'situation': 0.62; 'truly': 0.62; 'ever': 0.63; 'more': 0.63; 'great': 0.64; 'here': 0.65; 'day': 0.73; 'action.': 0.84; 'bite': 0.84; 'fortunately': 0.84; 'idiom': 0.84; 'overloading': 0.84; 'understand,': 0.84; 'mistake': 0.91; 'relate': 0.91; 'urge': 0.91; 'examine': 0.95 Date: Sat, 24 Nov 2012 09:30:11 +1100 From: Cameron Simpson To: Michael Herrmann Subject: Re: Is it bad style to override the built-in function `type`? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5b8a0a43-c737-4543-99e3-76e44c544a02@googlegroups.com> User-Agent: Mutt/1.5.21 (2010-09-15) References: <5b8a0a43-c737-4543-99e3-76e44c544a02@googlegroups.com> Cc: python-list@python.org, comp.lang.python@googlegroups.com 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: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1353709817 news.xs4all.nl 6935 [2001:888:2000:d::a6]:47321 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33868 On 23Nov2012 10:41, Michael Herrmann wrote: [...] | I know it's a common beginner's mistake to incautiously override | built-in functions. However, we put in a lot of research and have come to | the conclusion that, if Python had not already defined it, `type` would | be the best name. We are now trying to evaluate how bad the disadvantages | you mention are in comparison to the advantage to having a name that is | more intuitive to use in the problem domain. | | Can you somehow relate to my explanations, or are your experiences | with overwriting built-in variables so bad that you would advise to | never ever do it? My own experience says that it is a thing best avoiding without a truly amazing reason not to. I urge you not to: type(foo) is a very basic Python idiom and you're breaking it. One day it _will_ bite you or your users. You will understand, but I would give goods odds that some of your users will not the day they go to examine the type of an object for perfectly normal pythonic reasons. Example: I have a module that stores "objects" and they have as a primary key a "name" and a "type" - not Python types, just strings. Accordingly I have a similar situation to yours: the desire to use the word "type". Fortunately for me, as an attribute in (usually small) code chunks I can usually go: t = foo.type ... work with t here ... Where I must pass one as a parameter I use the common convention of naming the parameter "type_" at the receiving end. For the calling end, as in your case, you want to use: type(blah) Is it at all possible to make all uses of your "type" function method calls? Eg: something.type("text to type") It avoids the overloading while keeping your desired name. -- Cameron Simpson Wouldn't it be great if all emergency stopping situations occurred on your favourite bit of road......you'd probably know about it before it happened and would be able to take other evasive action. - Neville Brabet