You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As of writing this issue, GitHub shows that 10% of the codebase is written in Rust. This number should be higher, as Python has the following disadvantages compared to Rust.
Weak type system: originally designed as a dynamic language, typing was added much later in Python 3.8. Type checking using mypy is still unable to figure out simple things. As this is a hobby project, weak typing support causes valuable time being lost on simple type errors that the compiler should be able to figure.
Unsuitable for programming microcontrollers. There's MicroPython, but it's very basic with a lot of Python features missing. A big advantage of Python -- lots of libraries -- is not present in MicroPython, as libraries have to be rewritten just for MicroPython.
Type system weakness examples
Many libraries are not typed
pyudev, pyserial, gpiozero and other libraries are not typed yet.
Time handling
datetime.now() and datetime.now().astimezone() cannot be subtracted, as one is decorated with a timezone while the other isn't. Doing that results in a runtime error. In Rust, these are different types, so the error is caught already during compilation.
False negatives
Printing MAC address as a number in hex is not caught when the MAC address is already passed in as a string:
mac_addr = "abcdef012345"
f"{mac_addr:012x}"
False positives
On the other hand, there's also false negatives, like the following example.
def f(x: int) -> int | tuple[int, str]:
if x == 0:
return (0, "zero")
return x
a, b = f(0)
c = f(1)
mypy complains that int is not iterable at the line a, b = f(0).
The text was updated successfully, but these errors were encountered:
As of writing this issue, GitHub shows that 10% of the codebase is written in Rust. This number should be higher, as Python has the following disadvantages compared to Rust.
mypy
is still unable to figure out simple things. As this is a hobby project, weak typing support causes valuable time being lost on simple type errors that the compiler should be able to figure.Type system weakness examples
Many libraries are not typed
pyudev
,pyserial
,gpiozero
and other libraries are not typed yet.Time handling
datetime.now()
anddatetime.now().astimezone()
cannot be subtracted, as one is decorated with a timezone while the other isn't. Doing that results in a runtime error. In Rust, these are different types, so the error is caught already during compilation.False negatives
Printing MAC address as a number in hex is not caught when the MAC address is already passed in as a string:
False positives
On the other hand, there's also false negatives, like the following example.
mypy
complains thatint
is not iterable at the linea, b = f(0)
.The text was updated successfully, but these errors were encountered: