Hi,
While creating an API we hide of course implementation of API. So user of our methods does not know what's going on inside it. It is good. Is it?
But what to do if method performs complicated calculations? User does not know about it, and he his code may be very inefficient.
Of course we may write it directly in documentation. But how do it? Mark as efficient/non-efficient? It's not enough of course. The more details we expose about efficiency of our method, the more user knows about implementation. We don't want that of course.
So maybe indicate about it in method's signature, and name it like calculate*, compute* ? Its not good solution either.
Of course programmer should not think about optimization before everything works perfect, but it is good to make some steps while writing code.
Lets make an example of length() from java.lang.String.
Documentation says:
Returns the length of this
string. The length is equal to the number of 16-bit Unicode characters in the string.
And that's all.
Suppose we have code:
It is wide known that below code is inefficient, but suppose we don't know how to improve it. It cannot be done without using profiler tools or looking into method's implementation.
It is simple example, but what if our whole solution for few million dollars is based on inefficient code?
What do you think about it?