Beefy Boxes and Bandwidth Generously Provided by pair Networks
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.

--
say "Just Another Perl Hacker";


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

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2024-04-24 07:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found