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

  • SEARCH
  • Home
  • 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 6999903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:36:07+00:00 2026-05-27T20:36:07+00:00

Whats the best practice? function A() { if (someClassValue > 0) { B(); }

  • 0

Whats the best practice?

function A() {

   if (someClassValue > 0) {
       B();
   }

}

function B() {

   ...do smth, you expect (someClassValue > 0)...
}

here the coder might forget to check the conditions before calling, and run the system unconsistent…
but from the logical point of view, the caller calls the function, therefore he should be responsible for conditions, when calling a function, on the other hand, its error prone

or

function A() {

   B();

}

function B() {

   if (someClassValue > 0) {
      return;
   }

   ...do smth...
}

this might look missleading from the view of body A

or

function A() {

   if (someClassValue > 0) {
       B();
   }

}

function B() {

   if (someClassValue > 0) {
      return;
   }

   ...do smth...
}

this is unnecessary double checking

whats the right approach? should a function check the condition to be executed, or should the function that calls this function check the conditions for calling B

  • 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-27T20:36:08+00:00Added an answer on May 27, 2026 at 8:36 pm

    Rule: Always validate parameters in all publicly exposed functions.

    Corollary: It’s not necessary to validate parameters in any non-publicly exposed functions. This usually has some marginal performance benefit, but it also keeps your code clean and easier to read, especially if you follow otherwise good design patterns and have public-facing functions call down into consolidated private functions to do actual work.

    If and only if profiling tells you that parameter validation is a significant bottleneck in your application should you become concerned with minimizing impact points and trimming them out where not absolutely necessary. Alternatively, you could leave them in for debug builds and remove them for release builds, minimizing the performance impact while still fulfilling their basic purpose as sanity checks. But I must say that I’ve never seen a parameter validation that was bottlenecking an application…

    As for your question above (which I’ve conveniently ignored), it really doesn’t matter which style you pick, so long as you follow the above rule(s). As is generally the case with questions tagged coding-style, the most important thing is to pick a style and stick with it—consistency is the real winner in the long term.

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

Sidebar

Related Questions

What's best practice (in VB.Net): Function GetSomething() as String GetSomething = Here's your string
Whats the best practice for setting up package structures in a Java Web Application?
Whats the best practice approach to creating a form that is used to both
Whats the best practice for implementing a confirmation page in .Net? I've used response.redirect(Thankyou.aspx)
What's the best practice to handle errors if using objects? A) Before the method
whats the best practice to use these? var x = { a: 'a', eat:
Whats the best practice for getting a commenter's email address from the cookie (this
In Obj-C, what's the best practice for function prototype ? Should I include them
What's the difference (if any) between model.__dict__['title_en'] and model.__getattribute__('title_en') and what's best practice ?
I'm faced with the following and I'm not sure what's best practice. Consider the

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.