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

Re: Re: Re: Re: There's Only One Way To Do It

by disciple (Pilgrim)
on Apr 06, 2004 at 22:09 UTC ( [id://343140]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: There's Only One Way To Do It
in thread There's Only One Way To Do It

Perl is dynamically typed, but also very strong.

Can you explain this a bit more? First, are these definitions correct? Static typing means the type of the variable is known at compile time. Dynamic typing means the type of the variable is not known at compile time.

If those definitions are correct then I assume that the aspect of Perl that makes it dynamic is that the value in a variable can be a number or string of any length (limited by memory) and therefore makes the language dynamically typed. And the aspect that makes it static is that the structure of the variable is known at compile time (scalar, array, hash) and therefore makes the language statically typed as well. However just as in C and C++ references can be used to avert this static typing.

Is that right?
  • Comment on Re: Re: Re: Re: There's Only One Way To Do It

Replies are listed 'Best First'.
Re^5: There's Only One Way To Do It
by hardburn (Abbot) on Apr 07, 2004 at 03:18 UTC

    Not quite. Realize that the definitions of "strong" and "static" typing are orthogonal, and I wish there was a completely different terminology used, since they are so easily confused. "Strong" means you can't convert between the types easily. "Static" means the compiler has some idea of what the type is. "Weak" is the opposite of "strong", and "dynamic" is the opposite of "static".

    Since you can't convert an array into a scalar, this aspect of Perl is strongly typed. Since a scalar can hold pretty much anything (strings, numbers, references, etc.), this aspect is dynamically typed.

    Static typing, IMHO, is extremely overrated. Since many statically typed languages make it easy to cast one type into another, you can't trust it to be anything more than an optimization hint.

    ----
    : () { :|:& };:

    Note: All code is untested, unless otherwise stated

      Thanks for the clarification. From your definition, isn't Perl weakly typed in addition to strongly typed? Because in a scalar you can store a string or number (and other things as well). And Perl easily converts between numbers and strings for you.

        Howdy!

        That depends on what you mean when you say "type". I chose to set the values for "type" as "scalar", "array", and "hash", being the fundamental data types (and ignoring some other, more esoteric, flavors). The number/string distinction is, in my consideration, not a part of the "type"; numbers and strings are each scalars.

        Think of them as an external representation. Some data may not have a meaningful numeric representation, but consider also a hex representation as another flavor. Regardless of the representation, the datum is a single item -- a scalar. It may be an encoding of multiple values that can be teased apart, but that, again, does not make it then a hash or an array.

        yours,
        Michael

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://343140]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 05:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found