3

The content below is from the Android developer site:

enter image description here

According to the phrase it is expecting the developer to store this info in his head. Shouldn't this be simple if they kept only setDataAndType and let user to set both, either or none, in which we don't have to remember this caveat since it is taken care by design.

As the code is from Google, I would like to check with the community if there is any good reason for they doing this that I am missing to see?

Signatures:

setType(String) 

setData(Uri)

setDataAndType(Uri, String)
gnat
  • 21,442
  • 29
  • 112
  • 288
Saran
  • 397
  • 1
  • 3
  • 11
  • 1
    this looks like a variation of [“Comments are a code smell”](http://programmers.stackexchange.com/q/1/31260) where comments are moved from code to docs to aid API clients in using it. Note how docs of `setType` and `setData` offer similar warnings about one clearing other. When there seems to be too much explanation of how code is supposed to work (be it in comments or in API docs), the usual suspect is that something isn't quite right in design – gnat Sep 19 '14 at 16:10

1 Answers1

6

From the fragment you show there is no good reason - if both URI type and MIME type can be present simultaneously, it seems strange to null either when setting the other. There might be hidden reasons, but I can't think of any right now, therefore I'm leaning towards "This just isn't a very good API".

(Note also that the API talks about "type" and "data", but the documentation talks about "URI" and "MIME type". Such inconsistent language is another sign of an inexperienced API writer.)

Kilian Foth
  • 107,706
  • 45
  • 295
  • 310