Sorting distionary by value

Jeff Shannon jeff at ccvcorp.com
Thu Mar 28 20:55:13 EST 2002


phil hunt wrote:

> On Thu, 28 Mar 2002 12:01:15 -0800, Jeff Shannon <jeff at ccvcorp.com> wrote:
> >
> >I disagree.  I'm just as happy that Python doesn't try to guess what would be a
> >suitable "default" value for non-existent keys.
>
> The default value should always be None.
>
> None should act like 0 or "" or [] or {} where appropriate, i.e.:
>
>    None + 1 --> 1
>    None + "x" --> "x"
>    None * 4 --> 0
>    None + ['x'] --> ['x']
>    None + {2:3} --> {2:3}

I strongly disagree with that.  Next thing you know, you'll be saying that (3 +
'one' ) should evaluate to 4.  Python has strong typing for a reason, just as it has
dynamic typing for a reason.  I wouldn't want to blur the line on types like this.
I *want* to know that None is not valid for all of those operations, so that I can
*tell* when I've got an error condition.


> >It seems to me to be entirely
> >consistent with the philosophy of "explicit is better than implicit".
>
> But that isn't the philosophy of any high level langauge. In fact,
> the more high level any language is, the more implicit things are.
> And I would argue that's a pretty good definition of what a high
> level language is.

I disagree with your conception of high level language.  A high level language hides
unnecessary details, but I don't think that conversion between different data types
is an unnecessary detail.  High level means that a logical step can be done in one
or two lines of code, not that it does magic transmutations in the background.
There's a large class of cases where the interpreter, in trying to "do the right
thing", is as likely to guess wrongly as it is to guess right.  If you want an
interpreter that guesses anyhow, use Perl.  I'll stick with Python, where uncertain
cases are brought to my attention instead.

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list