Perl is worse!

Paul Boddie paulb at infercor.no
Fri Jul 28 13:09:36 EDT 2000


Alex Martelli wrote:
> 
> "Paul Boddie" <paulb at infercor.no> wrote in message
> news:39814767.FFEFE5D0 at infercor.no...
>     [snip]
> > > 1 + "foo" = string ("1foo")
> >
> > Doesn't Perl do this last one as well? I refer you to the example I give
> above -
> 
> Nope; in Perl, 1 + "foo" is 1.

I was probably referring to Perl's string concatenation operator.

> > to have such behaviour permeating one's code is "nasty" to say the least.
> 
> I do consider it impractical, but what's "nasty" about it?

Well, the string concatenation is not so nasty, provided that you want the
number to be encoded in decimal notation within the string, for example. After
all variables, unlike literals, may not contain number base information and so
you might not be able to direct the encoding implicitly. Of course, explicit
method or function calls in Java and Python can also cause the "wrong" encoding
to be used:

  numberVariable.toString();	// Use the java.text package.

  str(numberVariable)		// Use format strings.

> Specifically: in mathematics, there is a natural injection from naturals to
> integers, from integers to rationals, from rationals to reals, from reals to
> complex.  Unfortunately, things are *NOT* all roses and wine in the
> real world, because we don't really have rationals in Pythons (much less
> reals, of course:-), but rather an approximation -- so, precision-loss,
> which is a form of information-loss, threatens...:
> 
> >>> long(12345678901234567890123L*1.0)
> 12345678901234567741440L

Indeed. I do recall noting that some people are irritated by such behaviour.
Also, in the indirectly related area of the string encoding of longs with the
"L" suffix, such results of the str function were once an irritation too,
although I think that issue is to be fixed in 1.6.

> > whereas 1 + "foo" is meaningless to almost everyone except Perl coders.
> 
> No way -- it's perfectly valid in C, too, except that there it means the
> constant-string "oo".  Really, truly, X my heart, I kid you not, check it
> out if you don't believe me (I wouldn't blame you for disbelieving this!).

I did do C before Python, and sometimes write the occasional C program, so I am
aware of this "interesting" possibility. However, I believe that the result of
adding 1 to "foo" is implementation dependent, as Cameron Laird pointed out. (I
don't recall the size constraints on the char type, however.)

Regards,

Paul



More information about the Python-list mailing list