Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any harm in changing a void return type to something else in a commonly used utility function?

Tags:

c#

if I have a function like

public void usefulUtility(parameters...) { 
    string c = "select * from myDB";
    do_a_database_call(c);
}

that's used in alot of places, is there any possible harm in changing it to:

public bool usefulUtility(parameters...) { 
   string c = "select * from myDB";
   bool result = do_a_database_call(c);
   return result;
}

Could this possibly break any code?

I can't think of anything... but it may be possible?

like image 632
anthonybell Avatar asked Aug 09 '12 15:08

anthonybell


3 Answers

Yes, virtually anything that you could possibly do that affects your public interface is a breaking change. It could be small enough that you don't care, and that nobody, or almost nobody, will actually happen to hit the corner cases, but Eric Lippert explains that there are edge cases (many of which involve Type inference) that can cause even these seemingly innocuous changes to break.

For your particular example, this code would be broken by that change.

Action a = usefulUtility;
like image 110
Servy Avatar answered Nov 15 '22 23:11

Servy


A change like this could definitely break stuff, both in terms of binary compatibility and in terms of source compatibility.

You might want to have a look at this StackOverflow answer and its associated thread, where API-breaking changes are discussed in depth.

like image 43
Marty Avatar answered Nov 15 '22 22:11

Marty


It's certainly possible that it could break some other code. As Lippert points out, nearly Every public change is a breaking change in some bizarre situation.

The more important question is, is it likely to cause anything to break, and the answer is no. You should be pretty safe making this change, because people aren't likely to do the bizarre kinds of things they would have to do for this to cause problems. That doesn't mean it's impossible to break some other code, but it's outside the realm of reasonable responsibility.

like image 1
Tim Copenhaver Avatar answered Nov 15 '22 22:11

Tim Copenhaver