To: plclub@saul.cis.upenn.edu From: mjd-list-plclub@plover.com cc: mjd@plover.com Subject: Strongly typed languages Organization: Plover Systems Date: Fri, 22 Jun 2001 17:52:08 -0400 Sender: mjd@plover.com The following rather bizarre article appeared today in the comp.lang.perl.misc newsgroup: ---------------------------------------------------------------- Path: monger.newsread.com!bad-news.newsread.com!netaxs.com!newsread.com!newshub.northeast.verio.net!verio!news.maxwell.syr.edu!sn-xit-03!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: merlyn@stonehenge.com (Randal L. Schwartz) Newsgroups: comp.lang.perl.misc Subject: Perl *is* strongly typed (was Re: Perl description) Date: 22 Jun 2001 11:21:25 -0700 Organization: Stonehenge Consulting Services; Portland, Oregon, USA Message-ID: References: <9guq0b$ig7$1@sunsite.dcc.uchile.cl> <993223794.104092308785766.gnarinn@hotmail.com> <9gvv60$sdq$1@sunsite.dcc.uchile.cl> User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: newsabuse@supernews.com Lines: 31 Xref: bad-news.newsread.com comp.lang.perl.misc:402109 >>>>> "Cristian" == Cristian Cespedes V writes: Cristian> yes, i undestand the questions. I can suposse that Perl is Cristian> weak typing (not strong typing) No, Perl has strong compile-time typing for primitive data types (scalars, arrays, hashes, filehandles), and strong run-time typing for user-defined data types (but weak compile-time typing). The compiler will abort if you try to put an array into a hash variable: in fact, it can't even be specified because of the prefix characters and the context they provide. The runtime system will abort if you use a method on an object of the wrong type. There's some work being done to detect this at compile-time in Perl 6, but don't hold your breath for Perl 5 to get it right. I don't know where everyone gets this notion that Perl has "weak typing". It's just not true, as long as you define the context properly. C++, by contrast, has strong compile-time typing, but weak run-time typing, because you can cast a pointer to another type and call a totally broken method on it. Crash! -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! ---------------------------------------------------------------- (Another, similarly peculiar, message about Perl appears at http://www.mail-archive.com/perl6-language@perl.org/msg00329.html) I found this bizarre because I would not have thought that anyone could find a more perfect example than Perl of a language was was very weakly typed. Almost any type of data will be automatically and implicitly converted to any other at run time, depending on context. This includes many information-discarding conversions, such as a conversion from a hash table to a scalar. However, I do not know what 'strongly typed' is commonly held to mean, and a web search only increased my confusion. For example: An example for a statically, but weakly typed language is C. (http://compilers.iecc.com/comparch/article/95-10-071) C is strongly typed... (http://www.google.com/search?q=cache:-Gt7Q2VqCFo:www.cis.njit.edu/~elsa/280/280%2520Lecture%252012%2520became13_files/slide0138.htm+%22strongly+typed%22+%22%2Bc%22) This works fine in weakly typed languages such as C. (http://www.mvps.org/vb/hardcore/html/typelessvariables.htm) LISP engines ... are themselves generally written in strongly typed languages like C... (http://tlug.linux.or.jp/ML/0010/msg00352.html) In a weakly typed language such as C, ... (http://www.cs.colorado.edu/~diwan/5535-99/hw-6-soln.html) TYPE: strongly typed: (C, Algol, Fortran) (http://sweat.cs.unm.edu/~bap/teach/S2000/CS257/notes/lecture/2000-01-19.txt) Similarly, Pascal was frequently cited as 'strongly typed' in contrast to C, even though the Pascal and C type systems are nearly identical and both Pascal and C both provide several mechanisms for evading compile-time type checks. Other articles conflated 'strongly typed' with 'has compile-time type checking' (http://whatis.techtarget.com/definition/0,289893,sid9_gci213058,00.html for example.) It appears that 'strongly typed' may have at least the following meanings: 1. A language is strongly typed if type annotations are associated with variable names, rather than with values. If types are attached to values, it is weakly typed. 2. A language is strongly typed if it contains compile-time checks for type constraint violations. If checking is deferred to run time, it is weakly typed. 3. A language is strongly typed if it compile or run-time checks for type constraint violations. If no checking is done, it is weakly typed. 4. A language is strongly typed if conversions between different types are forbidden. If such conversions are allowed, it is weakly typed. 5. A language is strongly typed if conversions between different types must be indicated explicitly. If implicit conversions are performed, it is weakly typed. 6. A language is strongly typed if there is no language-level way to disable or evade the type system. If there are casts or other type-evasive mechansisms, it is weakly typed. 7. A language is strongly typed if it has a complex, fine-grained type system with compound types. If it has only a few types, or only scalar types, it is weakly typed. 8. A language is strongly typed if the type of its data objects is fixed and does not vary over the lifetime of the object. If the type of a datum can change, the language is weakly typed. It may be that 'strongly typed' has no generally accepted substantive meaning. In any event, there appears to be a widespreak confusion about what it does mean. I was repeatedly reminded of articles about the cold-war-era use of words like 'democratic', or recent uses of the word 'biased'. These words have ceased to have any objective meaning, and instead become epithets: our country is democratic, yours is not; your statements are biased, ours are not. These word are used automatically to describe anything at all, and their use by a single person may not be consistent with even that person's stated definition. For example, the author of #8 above (http://members.nbci.com/STOFI/fc_c.htm) contrasts the language 'Force' with C, using C as a 'weakly-typed' lanaguge, even though, according to the author's own definition, C is strongly typed.