4 ms·
It calls x.__add__(y). Python types are strictly specified, but also dynamic. You don't need static types in order to have strict types, and indeed just becau
by andrewaylett 2y ago
It calls x.__add__(y).
Python types are strictly specified, but also dynamic. You don't need static types in order to have strict types, and indeed just because you've got static types (in TS, for example) doesn't mean you have strict types.
A Python string is always a string, nothing is going to magically turn it into a number just because it's a string representation of a number. The same (sadly) can't be said of Javascript.
- hot_gril 2y agoYeah and even with static typing, a string can be many things. Some people even wrap their strings into singleton structs to avoid something like sending a customerId string into a func that wants an orderId string, which I think is overkill. Same with int.
- GTP 2y ago> It calls x.__add__(y) Your answer doesn't solve the problem, it just moves it: can you tell me what x. __add__(y) does?
- andrewaylett 2y agoWhatever it's defined to do, and nothing else. Dynamic typing, but strong typing. There's no magic going on here, just an attribute lookup. It's still possible to write terrible Python code -- as it is in any language -- and the recommendation is still "don't write terrible code", just as it is in any language. You don't have to like it, but not liking it won't make it any different. The older I get, the more I like writing statically-typed code. I wrote a lot more Python (for my own use) in my youth, and tend towards Rust nowadays. Speaking of which: if you dislike the dynamic typing of Python then you must hate the static typing of Rust -- what does fn add<T:Add<U>, U>(a: T, b: U) -> T::Output { a + b } do?