In article <11ei…@kst.eternal-september.org>,
Keith Thompson <Keit…@gmail.com> wrote:
>cro…@spitfire.i.gajendra.net (Dan Cross) writes:
>> In article <2026…@yahoo.com>,
>> Michael S <alre…@yahoo.com> wrote:
>[...]
>>>There is a whole continuum of possibilities between strongly typed and
>>>untyped.
>>
>> Then you should explain yourself.
>>
>> "Python is strongly typed. It is of little practical
>> importance." What, precisely, did you mean? And why do you
>> consider it of, "little importance?"
>
>I think this is devolving into an debate that's mostly about the
>meanings of English phrases like "strongly typed" rather than about the
>semantics of various programming languages.
>
>I do agree that if someone is going to say a language is "strongly
>typed", they should probably explain just what they mean by that.
>
>I'm not aware that there's any widely accepted definition of
>"strongly typed". And I would argue that "strong typing" cannot
>be measured along a single continuum, with "weakly typed" languages
>at one end and "strongly typed" languages at the other. One language
>might have strong typing enforced at run time; another might have
>weak typing enforced at compile time.
No, these terms of art that are, as I understand it, fairly well
understood in the PL community. Generally, "strong typed" means
"no implicit conversions", and "statically typed" means "types
are known at compile time."
I do agree that there are languages that are more strongly or
weakly typed than others; on the one hand, assembly languages
tend not to have any notion of type at all: they work in terms
of different sized pieces of memory and registers of various
kinds. But if you want to load bytes from a string into a
floating-point register most hardware won't stop you (though you
may get an exception if you try to _use_ those bytes). Towards
the weaker end you've got languages like C and COBOL; at the
stricter side you've got languages based on affine and linear
types; Rust, Idris, and so on. On the strictest end you've got,
I dunno, the typed lambda calculus or something.
Many (most?) interpreted languages (Python, Ruby, Tcl, Perl,
Lua, and so on) as well as most Lisps are dynamically typed; the
type of an object is a runtime property, and the type of the
object associated with an identifier might chaghe over time.
>> To tie this back to C, C is a weakly-typed language; add a
>> number to a string literal and the result is a pointer. This
>> has been a source of a _huge_ number of bugs over the years.
>
>I can imagine a definition of "weakly-typed" that applies to C,
>probably based on its rather promiscuous implicit conversions. On
>the other hand, every C expression has an unambiguous type, determined
>entirely by the expression itself and the rules of the language.
Just so. C is a curious beast that is statically but weakly
typed.
>(The conversion/adjustment of expressions of function an array
>type is arguably an exception to this, but one that's completely
>specified by the language rules).
>
>Adding an integer to a string literal yields a pointer because
>(a) an array expression, such as a string literal, is "converted"
>to a pointer expression in most contexts, and (b) there exists an
>addition operator that takes a pointer and an integer and yields
>a pointer. (And I'm skeptical that this has been a source of a
>huge number of bugs.) Python allows a string to be multiplied by
>an integer; "foo" * 3 yields "foofoofoo".
Sure; we know _why_ C does this. But it is an example of weak
typing.
As for bugs....Consider how many "off-by-one" bugs have resulted
from C's loose treatment of pointer arithmetic. Most languages
that provide non-nullable references don't allow you to perform
arithmetic on them at all.
>In a typical assembly language, you can load two floating-point values
>into registers and apply a bitwise xor to them as easily as you can
>multiply them. You can't do that in most higher-level languages,
>including C, without extra steps that make the weirdness explicit. In
>Python, you can assign an expression of any type to a variable named
>"x"; the type is associated with the value, not with the variable.
>C doesn't do that. I would argue that most assembly languages are
>very weakly typed, but I wouldn't necessary say that C is more
>strongly typed than Python is or vice versa.
Yes. I agree that assembly languages are weakly typed; however,
your Python example is along the dimension of being dynamically
typed: you can't perform arithmetic addition on a list in Python
while you can in C: assuming a _linked list_ in C, this is
almost certainly an error (as opposed to following a `next`
pointer or whatever), whereas in Python it's just not
expressible.
- Dan C.