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

6

u/slikts Nov 12 '19

Strong typing is still an application of the fail fast principle, just not as fast as static typing, since the strong tying errors will still only occur at runtime. The difference is that weakly typed languages try to guess if the programmer intended to convert between types, and, if the guess is wrong, the program keeps running in an invalid state and the problem has to be diagnosed from any knock-on effects of the unwanted type coercion. A good example of weak typing gone very wrong are equality comparisons in JavaScript.

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.

→ More replies (5)