Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Code Smells

Code Smells

Davi Marcondes Moreira

September 26, 2018
Tweet

More Decks by Davi Marcondes Moreira

Other Decks in Programming

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. "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
  4. 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
  5. 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) {
  6. 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(); } }
  7. 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(); } }
  8. # 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
  9. # 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
  10. # 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
  11. 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)