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

171
Visualizações
Does dynamic dispatching decrease the cyclomatic complexity?

Imagine the following method converting a boolean into an int:

def bool_to_int(bool)
  bool ? 1 : 0
end

bool_to_int(false) # => 0
bool_to_int(true) # => 1

Because of the conditional, the cyclomatic complexity score is two. Does the score drop to one by utilizing refinements in Ruby?:

module Extension
  refine FalseClass do
    def to_int; 0; end
  end

  refine TrueClass do
    def to_int; 1 end
  end
end

using Extension

false.to_int # => 0
true.to_int # => 1

In other words; does dynamic dispatching reduce the cyclomatic complexity score or are we just hiding the complexity by letting Ruby do the “heavy lifting”?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Cyclomatic complexity is based on the nodes and edges available in them. By implementing dynamic dispatching, you are just implementing conditions in a different way.

So, the cyclomatic complexity stays constant.

Edit based on the below comments.

Yes, the cyclomatic concept is bound tightly with conditional statements. Reducing if/else statements results in less cyclomatic complexity. But the paths are constants. But now they are more isolated and not based on the conditions.

So I feel, the answer should be, Yes, the complexity gets reduced if you are successful in removing the conditional statements. But paths are constants.

over 4 years ago · Santiago Trujillo 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