when to block function calls?
<p>In terms of best/most common practices for programming, where should code go that prevents certain functions from being called, while keeping performance in mind?</p>

<p>for example, if I have a function that can break if called at the wrong time, which of these approaches is most common?</p>

<p>A:</p>

<pre><code>Data *someData = new Data;

while(running)
{
    ProcessData(someData);
};

void ProcessData(Data *data)
{
    if(data)
        data-&gt;member = 5;
}
</code></pre>

<p>B:</p>

<pre><code>Data *someData = new Data;

while(running)
{
    if(someData)
        ProcessData(someData);
};

void ProcessData(Data *data)
{
    data-&gt;member = 5;
}
</code></pre>

<p>edit: to clarify, I am asking whether functions should do their own validation, or rely on the client code not to call the function while in the wrong state.</p>

<p>In the case where a function could be 5 calls deep, adding validation to each function could add quite a bit of extra bulk to the code, and potentially hurt performance, but more importantly reduce the readability of the code.</p>

<p>so I am asking what the average developer would expect in this situation</p>
