Dynamic typing and team development

Asked

Viewed 76 times

6

Is there any good practice, standardization, recommendation, etc. aimed at preventing invalid types from being passed to methods and functions?

If I am working alone is more quiet, I even wrote the method so I know what types of parameters he expects to receive, but I see a problem when the development becomes a team. How will a third party know if for a given method he must pass an integer or a string, if it must be a list, or any other object? Only at execution time?

The only trick I see is to make massive use of docstrings and use an editor to display the docstring when writing a call to a method.

Any alternative other than this?

  • 1

    Possibly, mypy.

1 answer

5


I’m not the one to talk to Python.

You’re right to understand that working with dynamic typing is more complicated as a team. Even worse if the project is small and can be developed on its own, but there is no stability of who will do it. The real solution is to use a static typing language, it may even be the Mypy (not that I am recommending). Although it is essentially Python I consider another language because there is semantic change.

Documenting is the obvious solution.

Using an extra static analysis tool is another more guaranteed tool. This makes code more robust, but has no performance gain. And you will have to use something extra to do the project, it is possible that you have to create the tool, IE, better use another language.

Another cool strategy, and a lot of people use it, is to create tests that work like static analyzers. In dynamic languages it is much more work to do certain checks. And much more work to write tests because too much error can occur while in static language would be guaranteed not to occur.

In some cases it is possible to test assertive form, which is kind of a test inline.

  • 1

    Seeing the site Mypy saw that it is based on PEP484. The PEP documentation says that such syntax is related to the use of Annotations. I didn’t read it further but saw that when I use this syntax def greeting(name: str) -> str: Vscode Intellisense shows the type of the parameter. I think the most practical output is actually documenting the code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.