Good Practice of Using Implicits in Scala [closed]

扶醉桌前 提交于 2020-01-24 09:07:26

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!