Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6806029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:39:36+00:00 2026-05-26T19:39:36+00:00

In terms of best/most common practices for programming, where should code go that prevents

  • 0

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?

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

A:

Data *someData = new Data;

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

void ProcessData(Data *data)
{
    if(data)
        data->member = 5;
}

B:

Data *someData = new Data;

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

void ProcessData(Data *data)
{
    data->member = 5;
}

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.

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.

so I am asking what the average developer would expect in this situation

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:39:37+00:00Added an answer on May 26, 2026 at 7:39 pm

    Validating method calls for valid parameters has a performance cost but there’s also a ‘cost’ when errors occur. For example kernel functions can’t allow things to crash internally — it can bring down the entire system.

    Generally what I do is look how tightly coupled the caller and callee are. If they are both under your direct control than the callee can probably trust it’s not invoked with crap. But if you have have less control then it may need more validation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dilemma that I've encountered before. What's the best in terms of
In general terms and pseudo-code, what would be the best way to have a
Is there a medium-sized Clojure sample application that could be used as a "best-practices"
What's the best in terms of speed and performance? To call the function each
what is the best solution in terms of performance and readability/good coding style to
What's the best way to convert search terms entered by a user, into a
What is the best Lua OOP library in terms of speed, syntax convenience, LOC
Speaking entirely in technology-free terms, what is the best way to make a mobile
What is the best way to find out which terms in a query matched
I'm working on a site that's grown both in terms of user-base and functionality

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.