It’s wild that Python is getting a shoutout over javascript despite being an even bigger loosely typed mess.
I think it’s partially because Python has a reputation as being a serious language for serious people because it’s popular amongst data scientists and academics, whereas Javascript is still seen as being popular amongst script kiddies and people building crappy websites for $100 / pop.
That being said, most of the time i hear javascript jokes at work they’re pretty tongue in cheek /ironic / the dev isn’t really hating on it. I have heard a dev or two make those javascript jokes with a more serious critical tone, and everyone tends to ignore them and not engage because they’re pretty clearly just haters who have a general tendency to dislike popular things.
If by «loosely typed» you mean weakly typed, then that’s not true. Python is a dynamically and strongly typed language. Attempting to do an operation with incompatible types will result in a TypeError.
>>> "3" + 9
Traceback (most recent call last):
File "", line 1, in
TypeError: can only concatenate str (not"int") to str
You may be thinking of the following, but this only works because the __mul__ and __add__ methods of these objects have been written to accept the other types.
But it is in no way worse than javascript in that regard, though?
I don’t think static typing in Python is really so essential. I see it above all as a scripting language, so its applications don’t benefit as much from static typing as other languages do.
Maybe a better hypothetical python would have used some kind of type inference system, like in haskell, which allows for static typing while still allowing to write code unencumbered from types and stuff, but I really think, for Python’s target domain, its type system is actually adequate or good. Maybe its documentation could benefit from type hints, though.
It’s wild that Python is getting a shoutout over javascript despite being an even bigger loosely typed mess.
I think it’s partially because Python has a reputation as being a serious language for serious people because it’s popular amongst data scientists and academics, whereas Javascript is still seen as being popular amongst script kiddies and people building crappy websites for $100 / pop.
That being said, most of the time i hear javascript jokes at work they’re pretty tongue in cheek /ironic / the dev isn’t really hating on it. I have heard a dev or two make those javascript jokes with a more serious critical tone, and everyone tends to ignore them and not engage because they’re pretty clearly just haters who have a general tendency to dislike popular things.
Python programmers, brace yourself for this…
Oh wait.
If by «loosely typed» you mean weakly typed, then that’s not true. Python is a dynamically and strongly typed language. Attempting to do an operation with incompatible types will result in a TypeError.
>>> "3" + 9 Traceback (most recent call last): File "", line 1, in TypeError: can only concatenate str (not "int") to str
You may be thinking of the following, but this only works because the
__mul__
and__add__
methods of these objects have been written to accept the other types.>>> "A" * 4 + "H" 'AAAAH'
I meant that you do not declare types and a variable’s type can change at any time.
Regardless of semantics, it results in code that is not scannable.
But it is in no way worse than javascript in that regard, though?
I don’t think static typing in Python is really so essential. I see it above all as a scripting language, so its applications don’t benefit as much from static typing as other languages do.
Maybe a better hypothetical python would have used some kind of type inference system, like in haskell, which allows for static typing while still allowing to write code unencumbered from types and stuff, but I really think, for Python’s target domain, its type system is actually adequate or good. Maybe its documentation could benefit from type hints, though.