Note that there are some explanatory texts on larger screens.

plurals
  1. POSeeking clarification on apparent contradictions regarding weakly typed languages
    primarykey
    data
    text
    <p>I think I understand <a href="http://lucacardelli.name/Papers/OnUnderstanding.A4.pdf" rel="noreferrer">strong typing</a>, but every time I look for examples for what is weak typing I end up finding examples of programming languages that simply coerce/convert types automatically.</p> <p>For instance, in this article named <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=7590" rel="noreferrer">Typing: Strong vs. Weak, Static vs. Dynamic</a> says that Python is strongly typed because you get an exception if you try to:</p> <p><strong>Python</strong></p> <pre><code>1 + "1" Traceback (most recent call last): File "", line 1, in ? TypeError: unsupported operand type(s) for +: 'int' and 'str' </code></pre> <p>However, such thing is possible in Java and in C#, and we do not consider them weakly typed just for that.</p> <p><strong>Java</strong></p> <pre><code> int a = 10; String b = "b"; String result = a + b; System.out.println(result); </code></pre> <p><strong>C#</strong></p> <pre><code>int a = 10; string b = "b"; string c = a + b; Console.WriteLine(c); </code></pre> <p>In this another article named <a href="http://www.i-programmer.info/programming/theory/1469-type-systems-demystified-part2-weak-vs-strong.html" rel="noreferrer">Weakly Type Languages</a> the author says that Perl is weakly typed simply because I can concatenate a string to a number and viceversa without any explicit conversion.</p> <p><strong>Perl</strong></p> <pre><code>$a=10; $b="a"; $c=$a.$b; print $c; #10a </code></pre> <p>So the same example makes Perl weakly typed, but not Java and C#?.</p> <p>Gee, this is confusing <img src="https://i.stack.imgur.com/U5kPT.gif" alt="enter image description here"></p> <p>The authors seem to imply that a language that prevents the application of certain operations on values of different types is strongly typed and the contrary means weakly typed.</p> <p>Therefore, at some point I have felt prompted to believe that if a language provides a lot of automatic conversions or coercion between types (as perl) may end up being considered weakly typed, whereas other languages that provide only a few conversions may end up being considered strongly typed. </p> <p>I am inclined to believe, though, that I must be wrong in this interepretation, I just do not know why or how to explain it.</p> <p>So, my questions are: </p> <ul> <li>What does it really mean for a language to be truly weakly typed? </li> <li>Could you mention any good examples of weakly typing that are not related to automatic conversion/automatic coercion done by the language?</li> <li>Can a language be weakly typed and strongly typed at the same time?</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload