Analisando Complexidade de Código Ruby
Upcoming SlideShare
Loading in...5
×
 

Analisando Complexidade de Código Ruby

on

  • 3,971 views

Palestra feita no evento Ruby Masters Conf edição 2011.

Palestra feita no evento Ruby Masters Conf edição 2011.

Statistics

Views

Total Views
3,971
Views on SlideShare
2,157
Embed Views
1,814

Actions

Likes
3
Downloads
23
Comments
0

5 Embeds 1,814

http://blog.egenial.com.br 1809
http://forum.rubyonbr.org 2
http://webcache.googleusercontent.com 1
http://www.plugmasters.com.br 1
http://theoldreader.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Analisando Complexidade de Código Ruby Analisando Complexidade de Código Ruby Presentation Transcript

    • Analisando Complexidade de Código Ruby Utilizando Métricas para Encontrar Código que Fede Cássio Marques RubyMasters Conf 2011Saturday, February 26, 2011
    • Cássio Marques • código + comida vegan + livros + skate + música • Taoweb • Lime • http://cassiomarques.wordpress.com • @cassiomarquesSaturday, February 26, 2011
    • Porque analisar o código?Saturday, February 26, 2011
    • http://www.flickr.com/photos/rovingi/312078231/Saturday, February 26, 2011
    • Como analisar o código?Saturday, February 26, 2011
    • EstéticaSaturday, February 26, 2011
    • Dificuldade de ManutençãoSaturday, February 26, 2011
    • ChuteSaturday, February 26, 2011
    • AbstraçõesSaturday, February 26, 2011
    • MétricasSaturday, February 26, 2011
    • Medir alguma propriedade específica do códigoSaturday, February 26, 2011
    • Objetivo: Quantificar o que antes era abstratoSaturday, February 26, 2011
    • Métrica ABCSaturday, February 26, 2011
    • Analisa ComplexidadeSaturday, February 26, 2011
    • flog github.com/seattlerb/flogSaturday, February 26, 2011
    • Assignement Definir o valor de uma variável explicitamenteSaturday, February 26, 2011
    • = += *= << /= etc... -=Saturday, February 26, 2011
    • Branching Criar um novo fluxo de execuçãoSaturday, February 26, 2011
    • if or else rescue elsif (argh!) until case while andSaturday, February 26, 2011
    • Calls Chamadas a métodosSaturday, February 26, 2011
    • (Outras implementações usam Condition)Saturday, February 26, 2011
    • |ABC| = sqrt((A*A)+(B*B)+(C*C))Saturday, February 26, 2011
    • Mas em Ruby temos mais do que isso!Saturday, February 26, 2011
    • eval & cia (pontuação alta!!!) define_method eval module_eval class_eval instance_evalSaturday, February 26, 2011
    • blocos/yieldSaturday, February 26, 2011
    • Introspecção instance_method method_defined? private_instance_method privante_class_method public_instance_method etc...Saturday, February 26, 2011
    • Hooks Module#included Module#extended Class#inherited method_defined etc...Saturday, February 26, 2011
    • Ou seja...Saturday, February 26, 2011
    • Ou seja... METAPROGRAMAÇÃO É COMPLEXO E DIFICULTA A MANUTENÇÃO DO CÓDIGOSaturday, February 26, 2011
    • Quando verificar isso no seu código?Saturday, February 26, 2011
    • FrequentementeSaturday, February 26, 2011
    • (já deixei para a fase final de um projeto e o resultado foi traumático)Saturday, February 26, 2011
    • Complexidade CiclomáticaSaturday, February 26, 2011
    • saikuro http://saikuro.rubyforge.org/Saturday, February 26, 2011
    • Mede o número de segmentos linearmente independentes na execução do códigoSaturday, February 26, 2011
    • Grafo direcionado para representar os caminhos de execuçãoSaturday, February 26, 2011
    • 1 def some_method(value) 2 if value % 2 == 0 3 value.times { |i| puts i } 4 else 5 while value >= 0 6 puts value 7 value -= 1 8 end 9 end 10 endSaturday, February 26, 2011
    • Início value % 2 == 0 value.times { |i| ... while value >= 0 puts value puts i puts value -= 1 FimSaturday, February 26, 2011
    • C = A - V + 2P C => Complexidade ciclomática A => Número de arestas V => Número de vértices P => Número de componentes conectadosSaturday, February 26, 2011
    • Pode ser utilizada para definir o número de casos de teste necessários para ter total cobertura do códigoSaturday, February 26, 2011
    • Métrica procedural, mas pode ser usada em código OO no escopo de métodosSaturday, February 26, 2011
    • Duplicação de códigoSaturday, February 26, 2011
    • flay http://ruby.sadi.st/Flay.htmlSaturday, February 26, 2011
    • Pesquisa por códigos SEMELHANTESSaturday, February 26, 2011
    • Resultados são bons candidatos para refactoringSaturday, February 26, 2011
    • Código que muda com muita frequênciaSaturday, February 26, 2011
    • churn github.com/danmayer/churnSaturday, February 26, 2011
    • Código que muda muito == problemasSaturday, February 26, 2011
    • Indica quantidade de alterações ao longo do tempoSaturday, February 26, 2011
    • Métodos Classes ArquivosSaturday, February 26, 2011
    • git/mercurialSaturday, February 26, 2011
    • Code SmellsSaturday, February 26, 2011
    • Sintoma que indica algum problema mais sérioSaturday, February 26, 2011
    • O código pode feder por vários motivosSaturday, February 26, 2011
    • reek github.com/kevinrutherford/reekSaturday, February 26, 2011
    • Aceita opções sobre quais smells identificar/ ignorarSaturday, February 26, 2011
    • AtributosSaturday, February 26, 2011
    • readers/writers (ou getters/setters) podem expor demais seus objetosSaturday, February 26, 2011
    • Variáveis de ClasseSaturday, February 26, 2011
    • 1 class MyClass 2 @@my_class_variable = 1 3 4 class << self 5 attr_accessor :my_other_class_variable 6 end 7 endSaturday, February 26, 2011
    • Aumenta o escopo globalSaturday, February 26, 2011
    • Classe LongaSaturday, February 26, 2011
    • Muitas linhasSaturday, February 26, 2011
    • Muitas variáveis de instânciaSaturday, February 26, 2011
    • Muitos métodosSaturday, February 26, 2011
    • *provavelmente* fazendo coisa demais!Saturday, February 26, 2011
    • Método LongoSaturday, February 26, 2011
    • Lista de Parâmetros LongaSaturday, February 26, 2011
    • 1 def pay_with_credit_card(number, security_code, holder_name, expiration, value) 2 # ... 3 endSaturday, February 26, 2011
    • Possíveis soluçõesSaturday, February 26, 2011
    • Passar um hashSaturday, February 26, 2011
    • Encapsular em um objetoSaturday, February 26, 2011
    • Baixa Coesão Feature EnvySaturday, February 26, 2011
    • 1 class Cart 2 def price 3 @item.price + @item.tax 4 end 5 endSaturday, February 26, 2011
    • Baixa Coesão Utility FunctionSaturday, February 26, 2011
    • Método que não depende do estado do objetoSaturday, February 26, 2011
    • 1 class Oven 2 def formatted_temperature(sensor) 3 "#{sensor.temperature} #{sensor.unit}" 4 end 5 endSaturday, February 26, 2011
    • Polimorfismo SimuladoSaturday, February 26, 2011
    • 1 def some_method(value) 2 if value > 10 3 if value < 20 4 if value != 15 5 puts "duh" 6 else 7 puts "meh" 8 end 9 end 10 end 11 endSaturday, February 26, 2011
    • switch também :) (o reek ainda não identifica)Saturday, February 26, 2011
    • Uncommunicative NamesSaturday, February 26, 2011
    • Nomes não refletem a intenção do códigoSaturday, February 26, 2011
    • 1 class SomeClass 2 def some_method 3 # ... 4 end 5 6 def some_method_2 7 # ... 8 end 9 10 def another_method 11 a = 10 12 aLocalVariable = 25 13 end 14 endSaturday, February 26, 2011
    • Pode ser configurado com uma lista de regexps default [/^.[0-9]*$/]Saturday, February 26, 2011
    • Cobertura de TesteSaturday, February 26, 2011
    • != “bem testado”Saturday, February 26, 2011
    • rcov http://eigenclass.org/hiki.rb?rcovSaturday, February 26, 2011
    • Pode indicar trechos do código que foram negligenciadosSaturday, February 26, 2011
    • Too Simple To BreakSaturday, February 26, 2011
    • Novas funcionalidades são adicionadas, mas continua sem testesSaturday, February 26, 2011
    • Saturday, February 26, 2011
    • Saturday, February 26, 2011
    • Outros smells e erros de estiloSaturday, February 26, 2011
    • roodi github.com/martinjandrews/roodiSaturday, February 26, 2011
    • Atribuição de valor dentro de uma estrutura condicionalSaturday, February 26, 2011
    • 1 # Deveria ser foo == 100 2 if foo = 100 3 # ... 4 endSaturday, February 26, 2011
    • 1 # Falso positivo... 2 def some_method(value) 3 if @value = value 4 # ... 5 end 6 endSaturday, February 26, 2011
    • case sem cláusula elseSaturday, February 26, 2011
    • 1 def some_method(value) 2 case value 3 when 1..10 4 puts "Entre 1 e 10" 5 when 11..20 6 puts "Entre 11 e 20" 7 end 8 endSaturday, February 26, 2011
    • Classes com muitas linhas de código (por padrão limita em 300)Saturday, February 26, 2011
    • Padrão para nome de classes e módulos (verifica se o nome das classes e módulos está em CamelCase)Saturday, February 26, 2011
    • cláusulas rescue vaziasSaturday, February 26, 2011
    • 1 def calculate_factor(number) 2 begin 3 SOME_CONSTANT / number 4 rescue 5 6 end 7 endSaturday, February 26, 2011
    • 1 def calculate_factor(number) 2 begin 3 SOME_CONSTANT / number 4 rescue => e 5 # Tratar a exceção de alguma forma... 6 end 7 endSaturday, February 26, 2011
    • Uso de loops com forSaturday, February 26, 2011
    • 1 def print_list(list) 2 for value in list do 3 puts value 4 end 5 endSaturday, February 26, 2011
    • 1 def print_list(list) 2 list.each {|value| puts value } 3 endSaturday, February 26, 2011
    • Métodos com muitas linhas de código (por padrão limita em 20)Saturday, February 26, 2011
    • Padrão para nomes de métodos (verifica se os nomes dos métodos estão snake_case)Saturday, February 26, 2011
    • rails_best_practices github.com/flyerhzm/rails_best_practicesSaturday, February 26, 2011
    • Ok...Saturday, February 26, 2011
    • Mas é muita coisa para gerenciar!Saturday, February 26, 2011
    • metric_fu http://metric-fu.rubyforge.org/Saturday, February 26, 2011
    • saikuro + flog + flay + rcov + reek + roodi + churn + rails_best_practicesSaturday, February 26, 2011
    • rake metrics:allSaturday, February 26, 2011
    • Integração ContínuaSaturday, February 26, 2011
    • Métricas ao longo do tempoSaturday, February 26, 2011
    • Relatórios!Saturday, February 26, 2011
    • Saturday, February 26, 2011
    • Saturday, February 26, 2011
    • Saturday, February 26, 2011
    • Saturday, February 26, 2011
    • Problema:Saturday, February 26, 2011
    • O metric_fu acaba virando uma dependência do seu projetoSaturday, February 26, 2011
    • metrical github.com/iain/metricalSaturday, February 26, 2011
    • $ gem install metrical $ cd /path/of/your/project $ metricalSaturday, February 26, 2011
    • Dúvidas?Saturday, February 26, 2011
    • Obrigado!Saturday, February 26, 2011