3 ms·
> Java can afford to distinguish between bytes and characters because it is strongly typed throughout the language. In Python, whether 2 or 3, as a developer yo
by heavyset_go 6y ago
> Java can afford to distinguish between bytes and characters because it is strongly typed throughout the language. In Python, whether 2 or 3, as a developer you do not have the luxury of informed reasoning whether something is bytes or a string, because your functions' input parameters can be either.
Python is a strongly typed language, and you can check a function's argument types at runtime with isinstance(), and inspect those types' class hierarchies with issubclass().
- takeda 6y agoThe parent meant statically typed. Meaning it shows the errors at compile time. Yes, you can check at runtime, the problem though is that especially on Python 2. Those checks don't happen very often. Python 3 though will crash if you try to use bytes as text or vice versa. The python 2 though it will do an implicit casting and execute code, which will run and look like it runs correctly until you get an unicode characters, then it will crash. Java won't even let you compile such program. You could get somewhat similar protection if you annotate types and use mypy to check them.