Weak Type Ability for Python

avi.e.gross at gmail.com avi.e.gross at gmail.com
Thu Apr 13 14:36:47 EDT 2023


This reminds me a bit of complaints that the parser does not do what you
want when you do not supply parentheses in an expression like:

5 * 4 + 3

In many and maybe most languages it is seen as (5*4)+3 UNLESS you tell it
you want 5*(4+3). There are precedence and associativity rules.

Of course the computer might guess you meant the latter or could refuse to
do it and offer you a choice before calculating it. Or the language may
insist on parentheses always so you would need to also say ((5*4)+3) with no
default behavior.

The golden rule remains. If there is more than one way something can be
done, then either the programmer must make the choice explicit OR the
documentation must very clearly warn which path was chosen and perhaps point
to ways to do other choices. 

Some people take more complex (but not Complex) arithmetic than the above
and break it up into quite a few simple parts like:

temp1 = 4 + 3
result = 5 + temp1

Of course, the latter can be hard to read and understand for some people,
and some (others?) find fully parenthesized versions hard. But having
precedence rules and also allowing the other methods, should work fine for a
good segment of people except perhaps the ones who like Reverse Polish
Notation and insist on 5 4 3 + * instead.


-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com at python.org> On
Behalf Of aapost
Sent: Thursday, April 13, 2023 12:28 PM
To: python-list at python.org
Subject: Re: Weak Type Ability for Python

On 4/12/23 04:03, Ali Mohseni Roodbari wrote:
 >
On 4/13/23 07:50, Stefan Ram wrote:
 >    If tomorrow Python would allow "string+int" and "int+string"
 >    in the sense of "string+str(int)" and "str(int)+string",
 >    what harm would be there?
 >
 >    But for now, I think a typical approach would be to just use "str",
 >    i.e., "string+str(int)" and "str(int)+string".


I agree with Py Zen rule 2 in this case:
Explicit is better than implicit.

I hate when things try to guess what I am doing... It is why I can't use 
lxml.
-- 
https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list