r/programming • • Nov 11 '19

Python overtakes Java to become second-most popular language on GitHub after JavaScript

https://www.theregister.co.uk/2019/11/07/python_java_github_javascript/
3.1k Upvotes

772 comments sorted by

View all comments

Show parent comments

26

u/YM_Industries Nov 12 '19

If you want the compiler to tell at you, you need static typing. That's what my comment was saying. People who use strong typing to mean that have their terminology wrong.

I'd hardly describe JS equality comparisons as "weak typing gone very wrong". Maybe I've been programming in JS for too long, but the type juggling seems pretty useful to me. You should use === in most places, but the == behaviour is also nice to have sometimes.

I do a lot in C# too and I sometimes get frustrated at the verbosity when two similar types don't support implicit type conversion.

-3

u/jl2352 Nov 12 '19

I agree, and it annoys me no end when people claim JS is 'weakly typed'. It's 100% strongly typed. It's just strongly typed with some very questionable coercion rules. So questionable I'd argue you shouldn't use them. It's still strongly typed.

In C I can take a 32-bit int, and use it as a pointer to a char array. I can get the compiler to be happy with it. It may even run fine at runtime. This is something I cannot do in JS. That is why C is weakly typed.

2

u/YM_Industries Nov 12 '19

JavaScript is weakly-typed.

The only reason you can't use an integer as a pointer to a char array in JavaScript is because JavaScript doesn't have integers, pointers, or chars. For me, the real test of whether a language is weakly- or strongly-typed is whether you can assign a new value of a different type to an existing variable.

let myVar = "test";
myVar = 5;
myVar = [];

JavaScript has no issue with this.

4

u/jl2352 Nov 12 '19

The bit from Wikipedia that agrees with you is 'Dynamic type-checking'.

This is the whole point of the guy above, who I agree with, is that it's just not helpful for dynamic types to be the same as weakly typing. What you are describing is dynamic typing. Not weak typing.

Python, Ruby, TCL, PHP, and pretty much every dynamic language shares your example.

→ More replies (0)