Pro Yearly is on sale from $80 to $50! »

Code Smells

Code Smells

049fbbe4e5fb94c45d6ccd656290d6fb?s=128

Davi Marcondes Moreira

September 26, 2018
Tweet

Transcript

  1. CODE SMELLS CODE SMELLS 2018-09-26 @ 7Masters Davi Marcondes Moreira

    - @devdrops Photo by on Braydon Anderson Unsplash
  2. $ ~ $ ~ WHOAMI WHOAMI - Davi Marcondes Moreira

    - Software Developer @ Pagar.me - @devdrops - PHP, JavaScript, Kotlin e o que mais vier \,,/ - Mending > Making
  3. Photo by on Steve Harvey Unsplash

  4. Photo by on Daniil Silantev Unsplash

  5. "I have an occasion to ask people if they've heard

    of code smells, and everyone say yes. (...) Then I ask them to list five, and no one can." Sandi Metz
  6. A LISTA É GRANDE A LISTA É GRANDE - Alternative

    classes with different interfaces - Comments - Data Class - Data Clumps - Divergent change - Duplicated code - Feature envy - Inappropriate Intimacy - Incomplete library client - Large class - Lazy class - Long method - Long parameter list - Message chain - Middle man - Parallel inheritance hierachies - Primitive obsession - Refused bequest - Shotgun surgery - Speculative generality - Switch statements - Temporary fields
  7. 3 3 BONS BONS EXEMPLOS EXEMPLOS

  8. MÉTODOS LONGOS MÉTODOS LONGOS

  9. public function submit() { $this->load->model('checkout/order'); $this->load->model('account/customer'); $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']); $customer

    = $this->model_account_customer->getCustomer($order_info['customer_id']); $discountPercentage = $this->config->get('checkout_boleto_discount_percentage'); $discountAmount = ($this->cart->getSubtotal() * $discountPercentage) / 100; $json=array(); $json['amount'] = str_replace(array(".", ","), array("", ""), number_format($order_info['total'], 2 $json['button_text'] = $this->config->get('checkout_texto_botao') ? $this->config->get('checkout_tex $json['boleto_discount_amount'] = number_format($discountAmount, 2, '', ''); $json['button_class'] = $this->config->get('checkout_button_css_class'); $payment_methods = $this->config->get('checkout_payment_methods'); if (count($payment_methods) == 1) { $json['payment_methods'] = $payment_methods[0]; } else { $json['payment_methods'] = $payment_methods[0] . ',' . $payment_methods[1]; } $card_brands = ''; $card_brands_array = $this->config->get('checkout_card_brands'); foreach ($card_brands_array as $card_brand) { if (reset($card_brands_array) == $card_brand) { $card_brands .= $card_brand; } else { $card_brands .= ',' . $card_brand; } } $json['card_brands'] = $card_brands; /* Máximo de parcelas */ $max_installment = $this->config->get('checkout_max_installments'); $order_total = $order_info['total']; $max_installment_value = $this->config->get('checkout_max_installment_value'); if($max_installment_value) {
  10. MIDDLE MAN MIDDLE MAN Photo by on rawpixel Unsplash

  11. class User { private $phone; public function getPhone() { return

    $this->phone; } public function getPhoneDdi() { return $this->phone->getDdi(); } public function getPhoneDdd() { return $this->phone->getDdd(); } public function getPhoneNumber() { return $this->phone->getNumber(); } }
  12. class User { private $phone; public function getPhone() { return

    $this->phone; } public function getPhoneDdi() { return $this->phone->getDdi(); } public function getPhoneDdd() { return $this->phone->getDdd(); } public function getPhoneNumber() { return $this->phone->getNumber(); } }
  13. AGLOMERADO DE DADOS AGLOMERADO DE DADOS

  14. # Mudamos disso class PostRepository def draft(title, description, author) #

    code code code end def publish(title, description, author) # code code code end def update(id, title, description, author) # code code code end end
  15. # Mudamos disso class PostRepository def draft(title, description, author) #

    code code code end def publish(title, description, author) # code code code end def update(id, title, description, author) # code code code end end
  16. # Mudamos disso class PostRepository def draft(title, description, author) #

    code code code end def publish(title, description, author) # code code code end def update(id, title, description, author) # code code code end end # Para isso Post = Struct.new(:title, :description, :author) class PostRepository def draft(post) # code code code end def publish(post) # code code code end def update(id, post) # code code code end end
  17. CONCLUSÃO CONCLUSÃO

  18. Aprender code smells torna mais fácil identificar problemas no seu

    código.
  19. REFERÊNCIAS REFERÊNCIAS - Code Refactoring: Learn Code Smells And Level

    Up Your Game! (https://www.youtube.com/watch?v=D4auWwMsEnY) - Smells to Refactoring Quick Reference Guide (http://www.industriallogic.com/wp- content/uploads/2005/09/smellstorefactorings.pdf)
  20. MUITO OBRIGADO! :D MUITO OBRIGADO! :D @devdrops devdrops.me/about bit.ly/7masters-code-smells