Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

221
Views
Is adding argument validators to internal functions bad practice?

I am trying to write a class to be used in my react app. The client of this function is my app only. Do I still need to valid arguments in the constructor function, etc.?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

IMO, validators are needed, when a function caller is unknown. What are the scenarios where the caller of function is unknown?

  • When the function is called by users of the application.
  • When the function is called by users(other programmers) of the module that has the function.
  • When the function is called the author of the function, who happen to forgot what are all the parameters that the function takes.

So,

  • If I am the only person who would ever call that function AND
  • If I am sure that I would remember the parameters or I would always ensure that I pass there right parameters:
    • I wouldn't write any validations.

If the same function happen to be used by other programmers or users, the first thing that I would do is to add validations.

When I am adding validations,

  • If I am sure that the function users are programmers, then I would simply have assert statements or throw statements.
  • If the users are functions are actual users, then I would have human readable error messages.
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!