Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

60
Vistas
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.?

7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

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.
7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.