<p>Do you often see in API documentation (as in 'javadoc of public functions' for example) the description of "value limits" as well as the classic documentation ?</p>

<p><strong>Note:</strong> I am not talking about <a href="https://stackoverflow.com/questions/20922/do-you-comment-your-code">comments within the code</a></p>

<p>By "value limits", I mean:</p>

<ul>
<li>does a parameter can support a null value (or an empty String, or...) ?</li>
<li>does a 'return value' can be null or is guaranteed to never be null (or can be "empty", or...) ?</li>
</ul>

<p><strong>Sample:</strong></p>

<p>What I often see (without having access to source code) is:</p>

<pre><code>/**
 * Get all readers name for this current Report. &lt;br /&gt;
 * &lt;b&gt;Warning&lt;/b&gt;The Report must have been published first.
 * @param aReaderNameRegexp filter in order to return only reader matching the regexp
 * @return array of reader names
 */
 String[] getReaderNames(final String aReaderNameRegexp);
</code></pre>

<p>What I <em>like to see</em> would be:</p>

<pre><code>/**
 * Get all readers name for this current Report. &lt;br /&gt;
 * &lt;b&gt;Warning&lt;/b&gt;The Report must have been published first.
 * @param aReaderNameRegexp filter in order to return only reader matching the regexp 
 * (can be null or empty)
 * @return array of reader names 
 * (null if Report has not yet been published, 
 *  empty array if no reader match criteria, 
 *  reader names array matching regexp, or all readers if regexp is null or empty)
 */
 String[] getReaderNames(final String aReaderNameRegexp);
</code></pre>

<p><strong>My point is:</strong></p>

<p>When I use a library with a getReaderNames() function in it, I often do not even need to read the API documentation to guess what it does. But I need to be sure <em>how to use it</em>.</p>

<p>My only concern when I want to use this function is: what should I expect in term of parameters and return values ? That is all I need to know to safely setup my parameters and safely test the return value, yet I almost never see that kind of information in API documentation...</p>

<p><strong>Edit:</strong> </p>

<p>This can influence the usage or not for <em><a href="https://stackoverflow.com/questions/27578#73355">checked or unchecked exceptions</a></em>.</p>

<p>What do you think ? value limits and API, do they belong together or not ?</p>

[{'answer_id': 61608, 'author': 'Fire Lancer', 'author_id': 6266, 'author_profile': 'https://Stackoverflow.com/users/6266', 'pm_score': 1, 'selected': False, 'text': '<p>I think they do, and have always placed comments in the header files (c++) arcordingly.</p>\n\n<p>In addition to valid input/output/return comments, I also note which exceptions are likly to be thrown by the function (since I often want to use the return value for...well returning a value, I prefer exceptions over error codes)</p>\n\n<pre><code>//File:\n// Should be a path to the teexture file to load, if it is not a full path (eg "c:\\example.png") it will attempt to find the file usign the paths provided by the DataSearchPath list\n//Return: The pointer to a Texture instance is returned, in the event of an error, an exception is thrown. When you are finished with the texture you chould call the Free() method.\n//Exceptions:\n//except::FileNotFound\n//except::InvalidFile\n//except::InvalidParams\n//except::CreationFailed\nTexture *GetTexture(const std::string &amp;File);\n</code></pre>\n'}, {'answer_id': 61610, 'author': 'Mike Stone', 'author_id': 122, 'author_profile': 'https://Stackoverflow.com/users/122', 'pm_score': 2, 'selected': False, 'text': "<p>I think those kinds of boundary conditions most definitely belong in the API.  However, I would (and often do) go a step further and indicate WHAT those null values mean.  Either I indicate it will throw an exception, or I explain what the expected results are when the boundary value is passed in.</p>\n\n<p>It's hard to remember to always do this, but it's a good thing for users of your class.  It's also difficult to maintain it if the contract the method presents changes (like null values are changed to no be allowed)... you have to be diligent also to update the docs when you change the semantics of the method.</p>\n"}, {'answer_id': 61612, 'author': 'Scott Dorman', 'author_id': 1559, 'author_profile': 'https://Stackoverflow.com/users/1559', 'pm_score': 4, 'selected': True, 'text': '<p>I think they <strong>can</strong> belong together but don\'t necessarily <strong>have</strong> to belong together. In your scenario, it seems like it makes sense that the limits are documented in such a way that they appear in the generated API documentation and intellisense (if the language/IDE support it).</p>\n\n<p>I think it does depend on the language as well. For example, Ada has a native data type that is a "restricted integer", where you define an integer variable and explicitly indicate that it will only (and always) be within a certain numeric range. In that case, the datatype itself indicates the restriction. It should still be visible and discoverable through the API documentation and intellisense, but wouldn\'t be something that a developer has to specify in the comments.</p>\n\n<p>However, languages like Java and C# don\'t have this type of restricted integer, so the developer would have to specify it in the comments if it were information that should become part of the public documentation.</p>\n'}, {'answer_id': 61631, 'author': 'VonC', 'author_id': 6309, 'author_profile': 'https://Stackoverflow.com/users/6309', 'pm_score': 1, 'selected': False, 'text': '<p>@Fire Lancer: Right! I forgot about exception, but I would like to see them mentioned, especially the unchecked \'runtime\' exception that this public method could throw</p>\n\n<p>@Mike Stone: </p>\n\n<blockquote>\n  <p>you have to be diligent also to update the docs when you change the semantics of the method.</p>\n</blockquote>\n\n<p>Mmmm I sure hope that the <em>public API documentation</em> is at the very least updated whenever a change -- that affects the contract of the function -- takes place. If not, those API documentations could be drop altogether.</p>\n\n<p>To add food to yours thoughts (and go with @Scott Dorman), I just stumble upon <a href="http://today.java.net/pub/a/today/2008/09/11/jsr-305-annotations.html" rel="nofollow noreferrer">the future  of java7 annotations</a></p>\n\n<p>What does that means ? That certain \'boundary conditions\', rather than being in the documentation, should be better off in the API itself, and automatically used, at compilation time, with appropriate \'assert\' generated code.</p>\n\n<p>That way, if a \'@CheckForNull\' is in the API, the writer of the function might get away with not even documenting it! And if the semantic change, its API will reflect that change (like \'no more @CheckForNull\' for instance)</p>\n\n<p>That kind of approach suggests that documentation, for \'boundary conditions\', is an extra bonus rather than a mandatory practice.</p>\n\n<p>However, that does not cover the special values of the return object of a function. For that, a <em>complete</em> documentation is still needed.</p>\n'}, {'answer_id': 24224149, 'author': 'taringamberini', 'author_id': 1972317, 'author_profile': 'https://Stackoverflow.com/users/1972317', 'pm_score': 2, 'selected': False, 'text': '<p><strong>Question 1</strong></p>\n\n<blockquote>\n  <p>Do you often see in API documentation (as in \'javadoc of public functions\' for example) the description of "value limits" as well as the classic documentation?</p>\n</blockquote>\n\n<p>Almost never.</p>\n\n<p><strong>Question 2</strong></p>\n\n<blockquote>\n  <p>My only concern when I want to use this function is: what should I expect in term of parameters and return values ? That is all I need to know to safely setup my parameters and safely test the return value, yet I almost never see that kind of information in API documentation...</p>\n</blockquote>\n\n<p>If I used a function not properly I would expect a <code>RuntimeException</code> thrown by the method or a <code>RuntimeException</code> in another (sometimes very far) part of the program.</p>\n\n<p>Comments like <code>@param aReaderNameRegexp filter in order to ... (can be null or empty)</code> seems to me a way to implement <strong><a href="http://en.wikipedia.org/wiki/Design_by_contract" rel="nofollow noreferrer">Design by Contract</a></strong> in a human-being language inside <a href="http://en.wikipedia.org/wiki/Javadoc" rel="nofollow noreferrer">Javadoc</a>.</p>\n\n<p>Using Javadoc to enforce Design by Contract was used by <code>iContract</code>, now resurrected into <a href="http://jcontracts.sourceforge.net/addingContracts.html" rel="nofollow noreferrer"><code>JcontractS</code></a>, that let you specify <em>invariants, preconditions, postconditions</em>, in more formalized way compared to the human-being language.</p>\n\n<p><strong>Question 3</strong></p>\n\n<blockquote>\n  <p>This can influence the usage or not for checked or unchecked exceptions.\n  What do you think ? value limits and API, do they belong together or not ?</p>\n</blockquote>\n\n<p>Java language doesn\'t have a Design by Contract feature, so you might be tempted to use <code>Execption</code> but I agree with you about the fact that you have to be aware about <a href="https://stackoverflow.com/questions/27578/when-to-choose-checked-and-unchecked-exceptions#73355">When to choose checked and unchecked exceptions</a>. Probably you might use unchecked <code>IllegalArgumentException</code>, <code>IllegalStateException</code>, or you might use unit testing, but the major problem is how to communicate to other programmers that such code is about Design By Contract and should be considered as a contract before changing it too lightly.</p>\n'}]
['https://Stackoverflow.com/questions/61604', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6309/']