4 ms·
Bit of an OT, but: > I am a big fan of strongly typed languages > Now, in some “weakly typed” languages What does "weakly" and "strongly" typed mean here? Di
by Tade0 5y ago
Bit of an OT, but:
> I am a big fan of strongly typed languages
> Now, in some “weakly typed” languages
What does "weakly" and "strongly" typed mean here? Did the author mean dynamically and statically? Or something else?
- cygx 5y agoThe weak/strong classsification is a bit less well-defined than the dynamic/static classification, but in general, languages differ in how strongly they 'care' about their types. For example, in Javascript, you can add anything to anything, with rules that define which automatic conversions will be performed. Sometimes, hilarity ensues. In contrast, a strong language would require explicit conversions and throw an error otherwise. In languages with ad-hoc polymorphism and operator overloading, you can emulate the Javascript experience by manually adding all the different cases yourself, in some sense 'weakening' the type system.
- Tade0 5y ago> In contrast, a strong language would require explicit conversions and throw an error otherwise. That's not the definition the author is going with considering that they're saying that Python (which requires explicit type conversions in most cases) is weakly typed. From the replies here I'm seeing that there's no clear definition of "weakly" and "strongly" typed languages. I don't think it makes a lot of sense to use these terms.
- cygx 5y agoThat's not the definition the author is going with I think it is, given that he links to https://xkcd.com/1537/ https://xkcd.com/1537/ as stereotypical 'weak' behaviour. Python sits somewhere inbetween Javascript and Haskell: For example, Haskell does not allow adding floats and integers, which Python will happily do despite a potential loss of precision.
- alpaca128 5y agoRust is strongly typed, it won't let you add or compare two values of different datatypes, even if they're both integers. For example you can't add a `u8`(byte) and a `i64`(long int) without casting. Meanwhile Python, JS and many other weakly typed languages will happily add an integer and a float, maybe even a string and a number without complaints. The advantage of the former are more rigorous compile-time checks, which might catch bugs where you added/compared the wrong values. But of course it's a bit more cumbersome especially if you're not used to it. I personally prefer it, I've had numerous cases where my Python script crashed 10 minutes into some data processing because it realised I tried to add two incompatible values.
- Tade0 5y ago> Meanwhile Python, JS and many other weakly typed languages will happily add an integer and a float, maybe even a string and a number without complaints. Actually, that's a type error in Python, hence my question.
- alpaca128 5y agoYes, but that's mostly an exception compared to the rest of Python's type system. Python doesn't care a lot about types in general. Sure, it's not quite as lenient as JS, but JS is a pretty extreme case - you won't find many other languages that'll happily do an addition of an object and an array.
- josephcsible 5y agoNo, those aren't the same thing. For example, C is both statically typed (there's no type checks or type information at runtime) and weakly typed (if you use a value of one type, like char, somewhere that another type, like _Bool, was expected, an implicit conversion will usually happen instead of an error).