ModularM
Modular2y ago
23 replies
moosems_yeehaw

Code Verbosity

The (Zen of Python)[https://peps.python.org/pep-0020/] states that “Special cases aren't special enough to break the rules.” It also states that “Explicit is better than implicit.” In my personal code I have no problem with the following:
x: Int = 5
y: StringLiteral = "Howdy Howdy!"
var z : String = str(x) + " " + y
print(z)


Many believe that if the type can be inferred, there’s no need to write it. The main exception in this is when it’s a union like var x: Int | None = None, then you add the type declaration. I believe that it’s simpler to just have the type declaration everywhere so that there’s no “special cases” to “break the rules. Again, “Explicit is better than implicit.” The main argument I see against this is the line “Simple is better than complex.” Often the claim is made that more type annotations adds complexity but I personally disagree though YMMV. It doesn’t necessarily make it more readable but IMO it doesn’t detract from it either. What are your thoughts? Any experiences that I should consider?
Was this page helpful?