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


Groups > comp.lang.python > #33894

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

Newsgroups comp.lang.python
Date 2012-11-24 14:32 -0800
References <5b8a0a43-c737-4543-99e3-76e44c544a02@googlegroups.com> <mailman.244.1353709817.29569.python-list@python.org>
Subject Re: Is it bad style to override the built-in function `type`?
From Michael Herrmann <michael.herrmann@getautoma.com>
Message-ID <mailman.263.1353796348.29569.python-list@python.org> (permalink)

Show all headers | View raw


Hi,

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!

Thanks!
Michael

On Friday, November 23, 2012 11:30:18 PM UTC+1, Cameron Simpson wrote:
> 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

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