At first I was reluctant of the syntax, after a while I got used to it. Function definitions look a lot like Rust ones and do not require the endless docstrings just to document the type of the expected parameters anymore.
At first I was reluctant of the syntax, after a while I got used to it. Function definitions look a lot like Rust ones and do not require the endless docstrings just to document the type of the expected parameters anymore.
That's partly because we tend to use the same types for everything. For instance in a spreadsheet you can subtract a column number from a row number and get no complaints even though the difference between the two quite likely makes no sense. If you have a separate type for row numbers and column numbers such mistakes can be caught.
What you probably meant: This is where being strongly typed helps. Python is and always has been strongly typed.
http://mypy.readthedocs.io/en/latest/cheat_sheet_py3.html#st...
I'm not happy seeing language designers introducing strong or optional typing in languages that didn't have it, but I understand that their goals are different from the goals of the developers that use their languages. I'd say leave the core of Python (and Ruby [1]) alone: if we picked those dynamically typed languages in the last 25 years (they're that old) it means we like them so. We can use plenty of other languages if we really need types.
[1] https://blog.heroku.com/ruby-3-by-3 "Matz: ... the third major goal of the Ruby 3 is adding some kind of static typing whille keeping the duck typing, so some kind of structure for soft-typing or something like that. The main goal of the type system is to detect errors early. So adding this kind of static type check or type interfaces does not affect runtime."
So you get a string, and you want to pass it unmodified to something that expects a string? The static typing answer is simple: Your variable is a string! How does that slow you down, or cost your customers a single cent?
In addition to alexvoda's comment: If you don't know what you get from your framework, then how do you know that you database frontend can handle it? Maybe in some cases, your framework gives you a list of lists, or a hashmap, and your database has no idea what to do with it. I really hope that's not the level of thoroughness you spend on your professional work.
Besides, if your framework were statically typed, it would either give you a String, or some kind of Variant/Any/Object with a to_string() method, the output of which can be passed to your database. There, problem solved, no time wasted, and you can be sure that whatever your framework does, your database can handle it.
Different areas of programming give importance to different things.
> "static typing only catches trivial errors"
To be honest I've not seen that sentiment very often, and it's definitely not something I agree with.
typecheck [0] is one (which can also run-time enforce the check) used like:
import typecheck as tc
def logathing(
dest: tc.hasattrs('write'),
thing: tc.any(int, float, str),
prefix: tc.optional(str)=None
):
dest.write(prefix + str(thing) if prefix else str(thing))
[0] - https://github.com/prechelt/typecheck-decoratorMoreover, if you would think a bit you would realize that the world around you is duck-typed. At least at the level of proteins.
One more thing. Every ontological attempt to use naive categories would fail and end up in duck-typing-like approach, because it reflects how the mother nature is.