Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

223
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda