An interview with Larry Wall (LinuxVoice)
An interview with Larry Wall (LinuxVoice)
Posted Jul 24, 2015 0:29 UTC (Fri) by mrons (subscriber, #1751)In reply to: An interview with Larry Wall (LinuxVoice) by Cyberax
Parent article: An interview with Larry Wall (LinuxVoice)
You used the + operator so in "$a+$b" $a and $b are to be treated as numbers.
If you wanted $a and $b to be treated as strings, you would use "$a . $b"
If the python code, when I look at "a+b", I have to examine the rest of the code to determine what "a+b" means (addition or concatenation).
Posted Jul 24, 2015 8:18 UTC (Fri)
by Cyberax (✭ supporter ✭, #52523)
[Link] (8 responses)
> You used the + operator so in "$a+$b" $a and $b are to be treated as numbers.
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"
Posted Jul 26, 2015 16:17 UTC (Sun)
by flussence (guest, #85566)
[Link] (7 responses)
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.
Posted Jul 26, 2015 18:57 UTC (Sun)
by Cyberax (✭ supporter ✭, #52523)
[Link] (6 responses)
Posted Jul 26, 2015 20:06 UTC (Sun)
by dvdeug (guest, #10998)
[Link] (1 responses)
Posted Jul 26, 2015 23:02 UTC (Sun)
by anselm (subscriber, #2796)
[Link]
That applies to Perl, too – see “perldoc overload”.
Posted Jul 27, 2015 0:03 UTC (Mon)
by mchapman (subscriber, #66589)
[Link] (1 responses)
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.
Posted Jul 27, 2015 0:06 UTC (Mon)
by mchapman (subscriber, #66589)
[Link]
And obviously that should be "... floating-point value".
Posted Jul 27, 2015 17:08 UTC (Mon)
by flussence (guest, #85566)
[Link] (1 responses)
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?
Posted Jul 27, 2015 17:13 UTC (Mon)
by Cyberax (✭ supporter ✭, #52523)
[Link]
> 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)
It's not.
Which numbers? Rationals, floats, doubles, integers, bigints?
BTW, the fact that "+" happily works with strings without any errors is another braindead idea.
An interview with Larry Wall (LinuxVoice)
An interview with Larry Wall (LinuxVoice)
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)
An interview with Larry Wall (LinuxVoice)
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.
An interview with Larry Wall (LinuxVoice)
An interview with Larry Wall (LinuxVoice)
An interview with Larry Wall (LinuxVoice)
An interview with Larry Wall (LinuxVoice)
WHICH numbers? They behave differently.
In Python it's either a floating number or a runtime error (barring bizarre operator overloads).