Dynamic typing and team development

4

There is some good practice, standardization, recommendation, etc. that aims to prevent invalid types from being passed to methods and functions?

If I'm working alone, it's calmer, I wrote the method myself so I know what kind of parameters it expects to receive, but I see a problem when the development happens to be as a team. How will a third one know if for a given method it must pass an integer or a string, whether it should be a list, or some other object whatsoever? Only at runtime?

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

Any other alternative besides this?

    
asked by anonymous 07.06.2018 / 21:20

1 answer

4

I'm not the best one to talk to Python.

You're right to understand that it's more complicated to work with dynamic typing in a team. Worse still if the project is small and can develop alone, but there is stability of who will do this. The real solution is to use a static typing language, it may even be MyPy (not that I'm recommending). Although 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. This leaves the code more robust, but has no performance gain. And you will have to use something extra to do the project, you may have to create the tool, that is, better use another language.

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

In some cases it is possible to test assertive form , which is sort of a test < in> inline .

    
07.06.2018 / 21:29