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


Groups > comp.lang.python > #68561

Re: 'complex' function with string argument.

References (5 earlier) <87lhw6po53.fsf@elektro.pacujo.net> <d1f09443-f5d4-4ed6-880f-bc15810a1fdd@googlegroups.com> <87bnx233gd.fsf@elektro.pacujo.net> <mailman.8276.1395225264.18130.python-list@python.org> <877g7q31f7.fsf@elektro.pacujo.net>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2014-03-19 13:35 -0600
Subject Re: 'complex' function with string argument.
Newsgroups comp.lang.python
Message-ID <mailman.8285.1395257751.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Mar 19, 2014 at 4:53 AM, Marko Rauhamaa <marko@pacujo.net> wrote:
> Ian Kelly <ian.g.kelly@gmail.com>:
>
>> On Wed, Mar 19, 2014 at 4:09 AM, Marko Rauhamaa <marko@pacujo.net> wrote:
>>> So complex(a, b) is documented to produce a+bj when a and b are integers
>>> or floats. What's more natural than saying it produces a+bj when a and b
>>> are complex numbers? It's a straightforward generalization that in no
>>> way violates the more limited documentation.
>>
>> When is it ever useful though? [...] It would be better to raise an
>> exception in either of the cases above, in my opinion.
>
> I don't think it matters one way or another.
>
> Medieval mathematicians had to address an analogous issue when they had
> to decide if
>
>    x + 0
>
> was meaningful. After all, adding nothing doesn't make any sense and
> should raise a ValueError exception...

I wasn't aware that algebra had ValueErrors.  Describing an operation
as "undefined" isn't the same thing.  Anyway, if mathematicians
discover that the definitions of the past were flawed or incomplete,
then they redefine them.  Case in point, if we were still using
Brahmagupta's rules for zero, then 0/0 would be 0.

Python though has backward compatibility to worry about.  Because of
this, it is much simpler to add wanted behavior than to remove
unwanted behavior. If an operation can be generalized but the
generalization has no apparent use case, it *may* be better to
disallow it, with the possibility of adding it later when a user pops
up and says "Hey, this would actually be useful to me", than to allow
it from the beginning, and then have no option to remove it later when
it turns out to be merely a nuisance.

Compare for example the 2-argument int constructor.  Normally this is
meant to be called like int("42", 13), where it will interpret the
digits passed as base 13 and return 54.  We might generalize that and
say that if the user passes int(42, 13), it should also return 54,
seeing that the repr of 42 provides the digits "42".  It is more
likely though that this call merely indicates a bug in the user's
code, and fortunately in this case what Python actually does is to
raise a TypeError.

Anyway, curious though this tangent is, further discussion is unlikely
to produce any useful outcome, so I'll just leave it there.

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


Thread

'complex' function with string argument. Jayanth Koushik <jnkoushik@gmail.com> - 2014-03-15 09:26 -0700
  Re: 'complex' function with string argument. Mark H Harris <harrismh777@gmail.com> - 2014-03-17 11:18 -0500
    Re: 'complex' function with string argument. Chris Angelico <rosuav@gmail.com> - 2014-03-18 04:03 +1100
      Re: 'complex' function with string argument. Marko Rauhamaa <marko@pacujo.net> - 2014-03-17 20:15 +0200
        Re: 'complex' function with string argument. Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-17 12:28 -0600
        Re: 'complex' function with string argument. Chris Angelico <rosuav@gmail.com> - 2014-03-18 05:59 +1100
          Re: 'complex' function with string argument. Marko Rauhamaa <marko@pacujo.net> - 2014-03-17 21:22 +0200
            Re: 'complex' function with string argument. Chris Angelico <rosuav@gmail.com> - 2014-03-18 06:32 +1100
            Re: 'complex' function with string argument. Steven D'Aprano <steve@pearwood.info> - 2014-03-18 04:08 +0000
      Re: 'complex' function with string argument. Mark H Harris <harrismh777@gmail.com> - 2014-03-17 13:20 -0500
    Re: 'complex' function with string argument. Steven D'Aprano <steve@pearwood.info> - 2014-03-18 04:52 +0000
      Re: 'complex' function with string argument. Chris Angelico <rosuav@gmail.com> - 2014-03-18 15:59 +1100
      Re: 'complex' function with string argument. Mark H Harris <harrismh777@gmail.com> - 2014-03-18 11:14 -0500
        Re: 'complex' function with string argument. wxjmfauth@gmail.com - 2014-03-19 00:30 -0700
          Re: 'complex' function with string argument. Marko Rauhamaa <marko@pacujo.net> - 2014-03-19 10:51 +0200
            Re: 'complex' function with string argument. wxjmfauth@gmail.com - 2014-03-19 02:52 -0700
              Re: 'complex' function with string argument. Marko Rauhamaa <marko@pacujo.net> - 2014-03-19 12:09 +0200
                Re: 'complex' function with string argument. Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-19 04:33 -0600
                Re: 'complex' function with string argument. Marko Rauhamaa <marko@pacujo.net> - 2014-03-19 12:53 +0200
                Re: 'complex' function with string argument. Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-19 13:35 -0600
                Re: 'complex' function with string argument. Skip Montanaro <skip@pobox.com> - 2014-03-19 06:04 -0500
                Re: 'complex' function with string argument. wxjmfauth@gmail.com - 2014-03-19 07:35 -0700
                Re: 'complex' function with string argument. Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-19 12:45 -0600
  Re: 'complex' function with string argument. Mark Dickinson <mdickinson@enthought.com> - 2014-03-17 17:55 +0000
  Re: 'complex' function with string argument. Terry Reedy <tjreedy@udel.edu> - 2014-03-17 18:06 -0400
  Re: 'complex' function with string argument. Skip Montanaro <skip@pobox.com> - 2014-03-17 18:59 -0500
  Re: 'complex' function with string argument. Chris Angelico <rosuav@gmail.com> - 2014-03-18 11:16 +1100
  Re: 'complex' function with string argument. Skip Montanaro <skip@pobox.com> - 2014-03-17 20:07 -0500
  Re: 'complex' function with string argument. Christian Gollwitzer <auriocus@gmx.de> - 2014-03-18 08:04 +0100
    Re: 'complex' function with string argument. Chris Angelico <rosuav@gmail.com> - 2014-03-18 18:11 +1100
    Re: 'complex' function with string argument. Steven D'Aprano <steve@pearwood.info> - 2014-03-18 08:00 +0000
      Re: 'complex' function with string argument. Christian Gollwitzer <auriocus@gmx.de> - 2014-03-18 09:21 +0100
        Re: 'complex' function with string argument. Marko Rauhamaa <marko@pacujo.net> - 2014-03-18 16:00 +0200

csiph-web