pontoNETpt
A comunidade PontoNetPT está direccionada a todos os programadores que trabalhem com a plataforma .NET.
Complexidade Ciclomática

Apesar de não ter tido muito tempo para contribuir para o crescimento do meu blog ultimamente, consigo ir-me mantendo actualizado relativamente ao que vai sendo "posted" por aí. Acabei de ler um post interessante do João Miranda sobre Code Smells (BTW, o livro do Martin Fowler é um "must").

A primeira vez que li alguma coisa sobre Code Smells foi quando li o Code Complete do Steve McConnell, que ainda hoje considero uma leitura indispensável para todos aqueles que estão envolvidos na construcção de software (BTW está para breve uma segunda edição) à semelhança dos multiplos volumes do Donald E. Knuth denominados "The Art of Computer Programming" uma referência em termos de engenharia de software.

Neste post o João sugere dois métodos fundamentais para determinar que um determinado método é demasiado longo. Eu gostaria de acrescentar um outro que me parece ainda mais importante: a complexidade ciclomática.

A complexidade ciclomátiva mede o número de caminhos distintos (linearmente independentes) de um determinado algoritmo medida em termos do número de instrucções decisionais adicionadas de um. Um algoritmo com uma complexidade ciclomática elevada deverá ser "refactored" (factorizado ?!?! Refactorizado ?! Refabricado ?!?!? Aceitam-se sugestões para a definição Portuguesa do termo... :-) ).

Uma complexidade ciclomática relativamente baixa contribui para que uma determinada função seja mais fácilmente compreensível e passível de ser modificada com menor risco. A complexidade ciclomática é também um bom indicador do quanto um programa ou função é testável.

Em baixo fica uma pequena tabela que categoriza a complexidade ciclomática de um algoritmo.

Complexidade Ciclomática

Risco Estimado

1-10

programa simples, com baixo risco

11-20

mais complexo, risco moderado

21-50

complexo, risco elevado

maior que 50

programa não testável (risco muito elevado)

 

Mais informação em: http://www.sei.cmu.edu/str/descriptions/cyclomatic_body.html


Posted 26-4-2004 17:47 por José Almeida
Filed under: ,

Comments

Anonymous wrote soma
on 1-7-2009 1:04
Be honorable yourself if you wish to associate with honorable people.
Anonymous wrote medical billing
on 1-7-2009 1:04
They can conquer who believe they can.
Anonymous wrote dysorexia
on 1-7-2009 1:04
Anyone who has gumption knows what it is, and anyone who hasn't can never know what it is. So there is no need of defining it.
Anonymous wrote retin-a federated eidolon
on 1-7-2009 1:04
The moment we begin to fear the opinions of others and hesitate to tell the truth that is in us, and from motives of policy are silent when we should speak, the divine floods of light and life no longer flow into our souls.
Anonymous wrote prozac online radiolucency hydrol
on 1-7-2009 1:04
Do what you feel in your heart to be right - for you'll be criticized anyway. You'll be damned if you do, and damned if you don't.
Anonymous wrote angiodermatitis
on 1-7-2009 1:04
The strongest possible piece of advice I would give any young woman is: Don't screw around, and don't smoke.
Anonymous wrote soma
on 2-7-2009 1:44
Be honorable yourself if you wish to associate with honorable people.
Anonymous wrote medical billing
on 2-7-2009 1:44
They can conquer who believe they can.
Anonymous wrote dysorexia
on 2-7-2009 1:44
Anyone who has gumption knows what it is, and anyone who hasn't can never know what it is. So there is no need of defining it.
Anonymous wrote retin-a federated eidolon
on 2-7-2009 1:44
The moment we begin to fear the opinions of others and hesitate to tell the truth that is in us, and from motives of policy are silent when we should speak, the divine floods of light and life no longer flow into our souls.
Anonymous wrote prozac online radiolucency hydrol
on 2-7-2009 1:44
Do what you feel in your heart to be right - for you'll be criticized anyway. You'll be damned if you do, and damned if you don't.
Anonymous wrote angiodermatitis
on 2-7-2009 1:44
The strongest possible piece of advice I would give any young woman is: Don't screw around, and don't smoke.

Add a Comment

(requerido)  
(opcional)
(requerido)  
Remember Me?
If you can't read this number refresh your screen
Enter the numbers above:  
Powered by Community Server (Commercial Edition), by Telligent Systems