4 ms·
>The + operator in both languages converts types if required. But that is what weak typing is. >In my mind an example of a weakly typed language would look li
by imanaccount247 12y ago
>The + operator in both languages converts types if required.
But that is what weak typing is.
>In my mind an example of a weakly typed language would look like this
Just because it is converting the other way doesn't mean it is a different thing. The fact that it one happens to convert in the direction that pleases you doesn't mean it is "strong" now. If it is converting, then it is weak.
- chrisseaton 12y agoBut most languages have some operation that will implicitly convert values to a different type. In fact Ruby and Python both do this (puts and print are examples), and they were examples given of a strongly typed language.
- imanaccount247 12y agoI didn't give those examples. Strong/weak isn't binary, it is a scale. A language that does more implicit conversion is weaker than one that does less.
- cbd1984 12y agoIt's the difference between conversion and casting: Casting, explicit or implicit, throws away type information, and reinterprets the same data in a different way. Data, here, is bytes, or some other low-level representation that makes what the types apply to. Conversions, explicit or implicit, uses type information to either change data, or prove that no change is needed, in order to use the data a different way.
- imanaccount247 12y agoBut that isn't what we're talking about. Changing a number to a string and using it as a string is exactly as bad as changing a string to a number and using it as a number.
- cbd1984 12y ago> Changing a number to a string and using it as a string is exactly as bad as changing a string to a number and using it as a number. Both of those are examples of strong typing in action.
- imanaccount247 12y agoNo, they are both examples of weak typing in action. Both of those are an error in a strong type system. That's the point.
- cbd1984 12y agoOnly if the strong type system is specified to return errors on those kinds of mismatches, as opposed to using the type information to perform a conversion and give another result which is just as well-defined as an error. That's the point: Strong typing ensures all results are well-defined, as the result of a specification, and it uses type information to do that. Weak typing throws away type information, so it can no longer uphold such specifications.
- imanaccount247 12y agoYour definition is one that you made up though. Most people use the actual definitions of words.