|
|
Subscribe / Log in / New account

An interview with Larry Wall (LinuxVoice)

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 8:18 UTC (Fri) by Cyberax (✭ supporter ✭, #52523)
In reply to: An interview with Larry Wall (LinuxVoice) by mrons
Parent article: An interview with Larry Wall (LinuxVoice)

> I don't see your point here. The perl code is predictable.
It's not.

> You used the + operator so in "$a+$b" $a and $b are to be treated as numbers.
Which numbers? Rationals, floats, doubles, integers, bigints?

And the answer, of course, is ANY OF THEM (depending on the Moon's current phase and Mars's relative position to it).

> If you wanted $a and $b to be treated as strings, you would use "$a . $b"
BTW, the fact that "+" happily works with strings without any errors is another braindead idea.


to post comments

An interview with Larry Wall (LinuxVoice)

Posted Jul 26, 2015 16:17 UTC (Sun) by flussence (guest, #85566) [Link] (7 responses)

> BTW, the fact that "+" happily works with strings without any errors is another braindead idea.

Perl 5 has errors for that. You can enable them by typing "-w" on the command line. They're off by default; little things like that are why code from 20 years ago still runs correctly in it unmodified.

I'd say any language where I can't be sure of the return type of "a + b" at a glance is more brain damaged.

An interview with Larry Wall (LinuxVoice)

Posted Jul 26, 2015 18:57 UTC (Sun) by Cyberax (✭ supporter ✭, #52523) [Link] (6 responses)

> I'd say any language where I can't be sure of the return type of "a + b" at a glance is more brain damaged.
Ah, so you do agree that not being able to tell what comes out of "a+b" is braindamaged. Like not being able to tell whether it's float, rational or bigint.

An interview with Larry Wall (LinuxVoice)

Posted Jul 26, 2015 20:06 UTC (Sun) by dvdeug (guest, #10998) [Link] (1 responses)

In Python, "a + b" could return literally any type, any value. All it takes is the appropriate "def __add__ (a, b): return value" in some class somewhere. That being "brain damaged" is an opinion I'm not going to get into, but it's not different between Perl and Python.

An interview with Larry Wall (LinuxVoice)

Posted Jul 26, 2015 23:02 UTC (Sun) by anselm (subscriber, #2796) [Link]

In Python, "a + b" could return literally any type, any value. All it takes is the appropriate "def __add__ (a, b): return value" in some class somewhere.

That applies to Perl, too – see “perldoc overload”.

An interview with Larry Wall (LinuxVoice)

Posted Jul 27, 2015 0:03 UTC (Mon) by mchapman (subscriber, #66589) [Link] (1 responses)

> Like not being able to tell whether it's float, rational or bigint.

Perl guarantees it's a scalar. If the result is an integer, the scalar will "look like" an integer. If the result is a floating-point value, the scalar will "look like" an integer.

"Looks like" in Perl is as strong a guarantee as "has a type of" in Python or some other languages. I would like to think you are merely unwilling to acknowledge this idea, not incapable of it. Either way though, I don't think there's anything more I have to say on the matter.

An interview with Larry Wall (LinuxVoice)

Posted Jul 27, 2015 0:06 UTC (Mon) by mchapman (subscriber, #66589) [Link]

> ... the scalar will "look like" an integer.

And obviously that should be "... floating-point value".

An interview with Larry Wall (LinuxVoice)

Posted Jul 27, 2015 17:08 UTC (Mon) by flussence (guest, #85566) [Link] (1 responses)

> Like not being able to tell whether it's float, rational or bigint.

You're almost getting it now, yes. Don't you just hate it when mathematical operators are commutative and return *numbers*? How dare they.

Maybe I should have used a more extreme example: "(a + b) * a / b". Does that return a number, a string, or a runtime error?

An interview with Larry Wall (LinuxVoice)

Posted Jul 27, 2015 17:13 UTC (Mon) by Cyberax (✭ supporter ✭, #52523) [Link]

>Don't you just hate it when mathematical operators are commutative and return *numbers*?
WHICH numbers? They behave differently.

> Maybe I should have used a more extreme example: "(a + b) * a / b". Does that return a number, a string, or a runtime error?
In Python it's either a floating number or a runtime error (barring bizarre operator overloads).


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds