DEV Community

loading...

Discussion on: Practical Advice to Good API Design

Collapse
johannea profile image
Johanne Andersen Author

Thank you, I was just repeating what was in the talk and I guess some of it is outdated with regards to monetary values.
For the input values, he does say to "use the most specific input parameter type", but I think it goes for both input and output.

Collapse
tibi profile image
Thiébaut Champenier

Bloch would not say such a thing, no.

I've checked his slides, he says

  • Don't use floating point for monetary values: Binary floating point causes inexact results
  • Use double rather than float

There is no relation between his two assertions. double is as bad as float for monetary values. He says so in the talk.

For the input type, he says in the talk "if you accept a collection but blow up unless you're passed a Set, that's broken." And this I agree, but the fix imho should be to make it work with any Collection. Only if not possible, declare the input as Set. We've all been annoyed by APIs accepting only a List when we have a Set that would perfectly work. But I'm not sure I'm qualified to disagree with Bloch even so slightly ;-)

Thread Thread
johannea profile image
Johanne Andersen Author

You are right, I'm sorry, I misread. I'll edit it in the post as well. Thanks for pointing it out!

For the input type, I'm no expert, but I imagine it also depends on the use case. But I completely agree with your point, if it works for any collection, a collection would also be the most specific input type there is. (I would think so at least)