Deutsch English Français Italiano |
<vo3ts7$379us$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=C3=B8j?= <arne@vajhoej.dk> Newsgroups: comp.os.vms Subject: Re: basic BASIC question Date: Thu, 6 Feb 2025 22:15:18 -0500 Organization: A noiseless patient Spider Lines: 129 Message-ID: <vo3ts7$379us$1@dont-email.me> References: <vnipj8$3i2i9$1@dont-email.me> <vnj7or$ga7$3@reader2.panix.com> <vnr1lq$1d7as$1@dont-email.me> <67a4cc2d$0$708$14726298@news.sunsite.dk> <vo2k7g$a7s$1@reader2.panix.com> <vo2mhs$30u76$1@dont-email.me> <vo3929$34a3i$10@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 07 Feb 2025 04:15:20 +0100 (CET) Injection-Info: dont-email.me; posting-host="b0775602d98a4cfe09b6e7190e1dd29b"; logging-data="3385308"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+foO4Uy88NHznj9b9O7NDgWVzECObOzo=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:nTVyIW4wV8R5TUkX0Xg0+JwgwZs= Content-Language: en-US In-Reply-To: <vo3929$34a3i$10@dont-email.me> Bytes: 4059 On 2/6/2025 4:20 PM, Lawrence D'Oliveiro wrote: > On Thu, 6 Feb 2025 11:04:12 -0500, Arne Vajhøj wrote: >> If JavaScript was unique in the web frontend world for lack of type >> safety, then the lack of type safety could be due to its history. >> Other popular languages like PHP and Python also has a relaxed >> approach to types. > > Worth being clear what we’re talking about. None of these languages is > type-unsafe in the way that C, for example, allows free typecasting > between unrelated types, and in particular between pointers to unrelated > types. They are all dynamic languages, and every value that a variable can > hold does have an explicit type, and conversions between types follow > well-founded semantic rules. > > However, JavaScript and PHP have a laissez-faire attitude to equivalences > with strings, and will happily autoconvert between strings and non-string > types in various situations, often leading to surprising results. This is > why both those languages have the “===” comparison operator as a stricter > form of “==” which says “turn off these string-nonstring autoconversions”. > > Python never had this particular bit of brain damage. But it does still > have that common weakness with booleans. Which is a more manageable issue. There are different conventions. $ type cmp.php <?php function test($a, $b) { if($a == $b) { echo "true "; } else { echo "false "; } if($a === $b) { echo "true\r\n"; } else { echo "false\r\n"; } } test(0, 0); test(0, 0.0); test(0, '0'); test(0, 'X'); test(0, False); test(0, null); ?> $ php cmp.php true true true false true false false false true false true false $ type cmp.py def test(a, b): if a == b: print('true') else: print('false') test(0, 0) test(0, 0.0) test(0, '0') test(0, 'X') test(0, False) test(0, None) $ python cmp.py true true false false true false $ type Cmp.groovy def test(a, b) { if(a == b) { println("true") } else { println("false") } } test(0, 0) test(0, 0.0) test(0, "0") test(0, "X") test(0, false) test(0, null) $ groovy Cmp.groovy true true false false false false $ type Cmp.java public class Cmp { private static void test(Object a, Object b) { if(a.equals(b)) { System.out.println("true"); } else { System.out.println("false"); } } public static void main(String[] args) { test(0, 0); test(0, 0.0); test(0, "0"); test(0, "X"); test(0, false); test(0, null); } } $ javac Cmp.java $ java Cmp true false false false false false Arne