3 ms·
Rust 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)
by alpaca128 5y ago
Rust 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.