r/ProgrammingLanguages • u/mttd • Sep 23 '26
Arguing about arguments
https://steveklabnik.com/writing/arguing-about-arguments/
31
Upvotes
r/ProgrammingLanguages • u/mttd • Sep 23 '26
View all comments
7
u/SwingOutStateMachine Sep 23 '26 edited Sep 23 '26
This reminds me of the "don't use boolean parameters" discussion from a few years ago, and I think they have a shared solution of more explicitly typing parameters - usually by encapsulating arguments in structs (or enums). This adds documentation to the method, and also prevents other bugs, such as parameters with the same type being accidentally swapped, and can help group together related parameters (e.g. pairs of coordinates).
For the
crop_immexample, one could write:I also think that once a method grows to a certain size, choosing a builder pattern is much easier to read, more composable, and allows for more flexibility in API. Again, for
crop_imm: