Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33899

Re: Is it bad style to override the built-in function `type`?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <cameron@cskk.homeip.net>
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.04; 'function,': 0.07; 'file"': 0.09; 'function:': 0.09; 'method:': 0.09; 'similar,': 0.09; 'typed': 0.09; 'cc:addr:python-list': 0.10; 'library': 0.15; 'sat,': 0.15; 'confusion': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'here!")': 0.16; 'message- id:@cskk.homeip.net': 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; 'stuff.': 0.16; 'subject:type': 0.16; 'suggestion.': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'write.': 0.16; 'wrote:': 0.17; 'typical': 0.17; 'module': 0.19; 'proposed': 0.20; 'context.': 0.22; 'cheers,': 0.23; 'cc:2**0': 0.23; 'nearly': 0.23; 'seems': 0.23; 'cc:no real name:2**0': 0.24; 'least': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'looks': 0.26; 'common': 0.26; 'used,': 0.27; "doesn't": 0.28; "d'aprano": 0.29; 'inspect': 0.29; 'steven': 0.29; 'this.': 0.29; 'usually': 0.30; 'function': 0.30; 'code': 0.31; 'gets': 0.32; 'file': 0.32; 'suggestion': 0.32; 'function.': 0.33; 'text': 0.34; 'whatever': 0.35; 'nov': 0.35; 'similar': 0.35; 'there': 0.35; 'michael': 0.36; 'but': 0.36; 'received:au': 0.36; 'should': 0.36; 'charset:us-ascii': 0.36; 'signature': 0.37; 'does': 0.37; 'uses': 0.37; 'why': 0.37; 'far': 0.37; 'subject:: ': 0.38; 'fact': 0.38; 'object': 0.38; 'instead': 0.39; 'called': 0.39; 'skip:" 10': 0.40; 'subject:-': 0.40; 'your': 0.60; 'content- disposition:inline': 0.60; 'side': 0.61; 'referred': 0.62; 'more': 0.63; 'natural': 0.65; 'sound': 0.65; 'acts': 0.71; 'flash': 0.72; 'william': 0.78; 'confusion.': 0.84; 'idiot,': 0.84; 'thing,': 0.84; 'procedure,': 0.91
Date Sun, 25 Nov 2012 17:33:58 +1100
From Cameron Simpson <cs@zip.com.au>
To Steven D'Aprano <steve+comp.lang.python@pearwood.info>
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 <50b19934$0$29981$c3e8da3$5496439d@news.astraweb.com>
User-Agent Mutt/1.5.21 (2010-09-15)
References <50b19934$0$29981$c3e8da3$5496439d@news.astraweb.com>
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.267.1353825242.29569.python-list@python.org> (permalink)
Lines 62
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1353825242 news.xs4all.nl 6971 [2001:888:2000:d::a6]:50291
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:33899

Show key headers only | View raw


On 25Nov2012 04:06, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:
| On Sat, 24 Nov 2012 14:32:19 -0800, Michael Herrmann wrote:
| > how about "write" instead of "type"? Just came to me in a flash of
| > inspiration. I know it's also pretty general but at least it's not a
| > built-in!
| 
| "write" is an extremely common operation with a signature very similar to 
| that of your function you want. The typical use of your function:
| 
| automata.write("Hello world")  # or whatever your module is called
| 
| looks exactly like writing to the file referred to by the name "automata".

Which is actually an argument _for_ his suggestion.

[...]
| If I inspect the way that the functions are used, the difference is 
| clear: write is nearly always used as a procedure, while type is used as 
| a function. [...]
| Your "simulate typing" function does not look like this. It doesn't 
| return anything. It usually gets used as a procedure, not a function, 
| just like the write method:

Again, an argument _for_ his suggestion.

| 
| There is far more opportunity for confusion with the name "write" than 
| "type":
[...]
| * but a call to your proposed function "write(string)" does look
|   very similar, if not identical, to a typical call to write.

Again, an argument _for_ his suggestion.

Why do I find these reasons to be plusses while you find them minuses?
Because you're conveniently glossing over the fact that almost all
uses of "write" in the library and common code have an object for
context.

And I find his suggestion good because for us old UNIX heads, the way you
present typed text to a terminal is usually to write it to the master
side of a pseudotty, thus:

  pty.write("typed text here!")

The usage is _exactly_ analogous to the conventional uses of write(),
because "everything is a file" (one of the UNIX mantras). Writing typed
text is the natural way to express this stuff.

Your argument seems to be that because his write looks and acts like
other write()s it is cause for confusion. My argument is that using the
name "write" is a good thing, _because_ his usage looks and acts like
the other common uses of write.

So I maintain it should cause less confusion.

Cheers,
-- 
Cameron Simpson <cs@zip.com.au>

It is a tale told by an idiot, full of sound and fury, signifying nothing.
        - William Shakespeare

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Is it bad style to override the built-in function `type`? Michael Herrmann <michael.herrmann@getautoma.com> - 2012-11-23 08:12 -0800
  Re: Is it bad style to override the built-in function `type`? Emile van Sebille <emile@fenx.com> - 2012-11-23 08:39 -0800
  Re: Is it bad style to override the built-in function `type`? Roy Smith <roy@panix.com> - 2012-11-23 11:47 -0500
  Re: Is it bad style to override the built-in function `type`? Michael Herrmann <michael.herrmann@getautoma.com> - 2012-11-23 09:08 -0800
  Re: Is it bad style to override the built-in function `type`? Terry Reedy <tjreedy@udel.edu> - 2012-11-23 13:35 -0500
    Re: Is it bad style to override the built-in function `type`? Michael Herrmann <michael.herrmann@getautoma.com> - 2012-11-23 10:41 -0800
      Re: Is it bad style to override the built-in function `type`? Cameron Simpson <cs@zip.com.au> - 2012-11-24 09:30 +1100
        Re: Is it bad style to override the built-in function `type`? Michael Herrmann <michael.herrmann@getautoma.com> - 2012-11-24 14:32 -0800
          Re: Is it bad style to override the built-in function `type`? Cameron Simpson <cs@zip.com.au> - 2012-11-25 09:47 +1100
          Re: Is it bad style to override the built-in function `type`? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-25 04:06 +0000
            Re: Is it bad style to override the built-in function `type`? Cameron Simpson <cs@zip.com.au> - 2012-11-25 17:33 +1100
        Re: Is it bad style to override the built-in function `type`? Michael Herrmann <michael.herrmann@getautoma.com> - 2012-11-24 14:32 -0800
    Re: Is it bad style to override the built-in function `type`? Michael Herrmann <michael.herrmann@getautoma.com> - 2012-11-23 10:41 -0800
  Re: Is it bad style to override the built-in function `type`? Ramchandra Apte <maniandram01@gmail.com> - 2012-11-24 23:02 -0800
  Re: Is it bad style to override the built-in function `type`? Michael Herrmann <michael.herrmann@getautoma.com> - 2012-11-29 03:46 -0800
  Re: Is it bad style to override the built-in function `type`? rusi <rustompmody@gmail.com> - 2012-11-30 09:54 -0800
    Re: Is it bad style to override the built-in function `type`? Michael Herrmann <michael.herrmann@getautoma.com> - 2012-12-03 02:57 -0800

csiph-web