问题
Are there any objective reasons to / not to use implicit parameters everywhere in code just to shorten the number of arguments that should be passed
I have a REST API. Each call of an end-point has a unique id that should be passed literally in EVERY function that is being triggered by the call for debugging purposes. A first thought that comes up to eliminate explicit passing of the parameter is to make it an implicit parameter in each function. But then, my intuition tells me that it is a misusage of implicits (though I don't have firm arguments not doing so).
Could be such approach justified by convenience reasoning where the gain is only removing a single parameter and assumed to be a good practice for the situations like mine?
回答1:
I think that this question is not a good fit for Stack Overflow. It is primarily opinion based and it is not completely clear what you are asking.
I think that passing around "context" type parameters like a request id is a fairly conventional use for implicit arguments in Scala, so I would consider your proposal good practice.
I don't feel comfortable using implicit parameters everywhere in code just to shorten the number of arguments that should be passed.
Why not?
来源:https://stackoverflow.com/questions/58434633/good-practice-of-using-implicits-in-scala