[Potentially misleading title, but I'm not sure how best to word it.]
Theoretical question on compilers and language design.
Say I'm re-implementing a method in a code base. Instead of removing or commenting out the method that I'm re-implementing I leave it where it is, for reference and testing purposes, and just remove all the calls to it. Something like the following (in C-style pseudo code):
public void aMethodToCallFooVariants()
{
// oldFoo();
newFoo();
}
private void oldFoo ()
{
// Some code here that's not very good
}
private void newFoo ()
{
// Some better code here
}
newFoo is called by the method that originally called oldFoo, meaning that oldFoo is no longer called anywhere in the source code, but it still in the listing.
Are compilers smart enough such that when I run my build script, the code for oldFoo isn't included in the compiled binary, or will oldFoo still be included but not called anywhere? I can understand if public method will still be included, they could be called by code that is external to the compiled binary (especially if it's compiled as a library). But would the private method still be compiled into the binary?