3 ms·
> But we can change around the name of the parameters like this and use proper strict types Sometimes. Other times proper strict types aren't possible because
by qayxc 5y ago
> But we can change around the name of the parameters like this and use proper strict types
Sometimes. Other times proper strict types aren't possible because the language doesn't support them (many scripting languages, C, etc.)
Assuming this is C, even a type like "celsius_degree_t" tells me nothing about the valid range. Am I supposed to just try it out and see what error code I get or are we back to looking at the implementation? In the case of C this will most likely involve locating and opening a completely different file whose name doesn't even have to be related to the header file.
The comment also doesn't need to be about all parameters and can contain additional information that's non-trivial to determine: is the function thread-safe, are there performance implications, is there notable resource usage, and so on.
Python in particular is notorious for having optional (keyword-) arguments and polymorphic arguments. Proper naming schemes are impossible in this case (lest you accept monstrosities like "node_as_id_or_name_or_object" as proper argument names) and type annotations have only very recently (as of 3.10) become somewhat sane. Type annotations don't help with kwargs, though.
TL;DR it greatly depends on the programming language and its capabilities whether naming and types alone can replace comments.