No such thing as a small change | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Two colleagues at $work frequently complain about the other's programming language of choice. The fight is between C++ and Perl. Today, not for the first time, the C++ supporter mocked Perl's lax attitude towards numbers. In a SWIG layer we use, many functions expect integer arguments. If you pass in a string in Perl, or what you consider a number in Perl terms, frequently the layer will croak that it cannot find the overloaded method call -- the method call is ambiguous because there are at least two matching methods, one that takes integer arguments and one that takes strings. So, you need to typecast with 0 + $var. The C++ thinking is that this is retarded -- a number is a sequence of bits (usually 32 or 64 bits) that fits inside the register or a memory cell of a computer. Not only that, but number types form a strict hierarchy, including integer (short, long), float(ing point), and double (floating point). Although related to strict typing, there is a related model of thinking here: that numbers are what can be represented in this particular way in a computer. The Perl thinking is that a number is what looks like a number to a human being. If it is stored in a machine-dependent number format, it is a number. If it is a string that looks like a number, it is a number. In essence, numbers are what people think are numbers. The string representation of a number is not the number; it is only a representation. Similarly, what is stored in memory is not the number, but only its representation. The C++ people, however, seem to think that the number stored in memory is the number itself. There are problems with both approaches and good arguments on both sides. However, the Perl way is better, because it lets us program more on our own terms, not on the terms of the computer or the underlying hardware. Humans do not excel in laborious or repetitious tasks, and not even in describing them in detail; thus automatic memory management and garbage collection. Similarly, the concept of a number is far larger that the small hierarchy and narrow-minded, hardware-centric view of C++ (and C) programmers.
-- In reply to Revealing difference in interpretation of 'number' between Perl and $other_language by vrk
|
|