in reply to Re^2: Strong typing and Type Safety.A multilanguage approach
in thread Strong typing and Type Safety.A multilanguage approach

From your earlier part:

The main difference, roughly speaking, between a strongly typed language and a weakly typed one is that a weakly typed one makes conversions between unrelated types implicitly, while a strongly typed one typically disallows implicit conversions between unrelated types.
You then imply, in Example 2 in the "Weak Typing in Perl" section, that using the numeric + operator on a Perl string is "implicit" and therefore weakly typed. As chromatic once remarked:
What's implicit about using numeric operators on strings? If you use string operators on strings, you get string behavior. If you use numeric operators (which you must do explicitly), you get numeric behavior. What isn't explicit about that?
Update: The same argument applies to your "Example 1" in that applying the Perl string concatentaion operator to a number is explicit. Perl is different (and superior IMHO) to many languages in that it does not overload + to mean both numeric addition and string concatenation.

Replies are listed 'Best First'.
Re^4: Strong typing and Type Safety.A multilanguage approach
by nikosv (Deacon) on Nov 20, 2010 at 08:23 UTC
    that using the numeric + operator on a Perl string is "implicit" and therefore weakly typed

    no but the conversion from string to number is

      No. By using the + operator, you are explicitly asking for the string to be converted to a number. Why do you say it is implicit? (This thread may be heading towards Room 12A).

        Sure, I can "explicitly" do 0+ with the intent of converting a string into a number. "Explicit" describes my motivation. But, no, 1+$duration is not an explicit type conversion, it is explicit addition that implies a type conversion, if required.

        I can write 1+$duration with no intention of doing a conversion. If I am mistaken in thinking that $duration holds a numeric value and write 1+$duration, since the explicit request for addition includes in it an implicit possibility of type conversion, the compiler can't tell that I didn't mean for a conversion to happen. The type conversion is called "implicit". Having to write 1+(int)$duration is much more explicit. Type conversion is only done when I explicitly say "do a type conversion" not when I say "do addition" and can't separately specify that I want a conversion.

        - tye        

        Quoting Modern Perl Books page 15

        Perl will do its best to coerce values to the proper type (see Coercion, page 47), depending on the operators you use. Be sure to use the proper operator for the type of context you want.

        Quoting Wikipedia

        Type Conversion In most languages, the word coercion is used to denote an implicit conversion, either during compilation or during run time.