Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Comment on

( #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.

say "Just Another Perl Hacker";

In reply to Revealing difference in interpretation of 'number' between Perl and $other_language by vrk

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (3)
    As of 2018-06-19 00:16 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (111 votes). Check out past polls.