I hope Whidbey MembershipProvider API changes before release

I started looking closer at the upcoming provider model in ASP.NET 2.0 and found some troubling patterns in current incarnation of the API (as of the May 2004 CTP). One example is MembershipProvider.ChangePassword method with the following signature:

public abstract bool ChangePassword(
 string name,
 string oldPassword,
 string newPassword
);

Can anyone spot a problem? I'll give you a hint, look at the return type. Now, without looking at the docs, can you tell me without a shadow of a doubt what that boolean value indicates? I didn't think so.

In this case, the API follows the old C convention of returning a boolean value to indicate whether the operation succeeded. This convention always felt incomplete to me, and it truly has no place in the world that has structured exception handling, and ESPECIALLY, for a method that should not, under normal circumstances, be a performance bottleneck.

In my opinion, the return type should be void and one should be able to safely assume that under normal conditions the operation will always succeed. Any failure to do so is an exception, and should be handled through the exception mechanism.

posted @ Thursday, June 24, 2004 7:12 PM

Print

Comments on this entry:

# re: I hope Whidbey MembershipProvider API changes before release

Left by Robert W. McLaws at 8/6/2004 5:07 PM
Gravatar
Mike, your argument is incorrect. Microsoft development guidelines clearly state that exceptions are expensive and should be avoided whenever possible. The Provider Model was not designed to make the decision for you on whether or not something is exception-worthy, that is why this specific function returns a boolean. If the exception is going to be thrown, it should happen either inside your custom Provider (which is again not recommended because they are expensive) or from your method call.

# re: I hope Whidbey MembershipProvider API changes before release

Left by Michael Teper at 8/6/2004 8:14 PM
Gravatar
I responded to Robert in a new blog entry here: http://michaelteper.com/archive/2004/08/06/195.aspx.
Comments have been closed on this topic.