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

What is software complexity and how can you man...

What is software complexity and how can you manage it?

These are the slides from LoopConf 2018.

As WordPress developers, we spend a lot of time writing code. We also spend a lot of time maintaining that code. But how often do you go back to it and find out it’s become this tangled web that you almost can’t understand?

This happens to us more often than we care to admit! But do you know how it happened? It’s because you increased the complexity of your code and it became hard to know what it did.

Software complexity isn’t a well-known topic in the WordPress world. That said, a better understanding of it can lead to a noticeable increase in the quality of your code. It makes it less fragile and prone to bugs.

This talk will go over the basics of software complexity and its impact on your code. We’ll also look at concrete steps that you can take to manage it. This will help you write code that’s easier to understand and maintain.

You can read the companion article at:
https://carlalexander.ca/what-is-software-complexity/

Carl Alexander

February 23, 2018
Tweet

More Decks by Carl Alexander

Other Decks in Technology

Transcript

  1. 1 2

  2. function insert_default_value($mixed) { if ($mixed instanceof ToStringInterface) { $mixed =

    $mixed->to_string(); } if (!is_string($mixed) || empty($mixed)) { $mixed = 'value'; } return $mixed; }
  3. function insert_default_value($mixed) { if ($mixed instanceof ToStringInterface) { $mixed =

    $mixed->to_string(); } if (!is_string($mixed) || empty($mixed)) { $mixed = 'value'; } return $mixed; }
  4. function create_reminder($name, $date = '') { // ... $date_format =

    'Y-m-d H:i:s'; $formatted_date = DateTime::createFromFormat($date_format, $date); if (!empty($date) && (!$formatted_date || $formatted_date->format($date_format) != $date) ) { throw new InvalidArgumentException(); } // ... }
  5. function create_reminder($name, $date = '') { // ... $date_format =

    'Y-m-d H:i:s'; $formatted_date = DateTime::createFromFormat($date_format, $date); if (!empty($date) && (!$formatted_date || $formatted_date->format($date_format) != $date) ) { throw new InvalidArgumentException(); } // ... }
  6. function create_reminder($name, $date = '') { // ... if (!empty($date)

    && !is_reminder_date_valid($date)) { throw new InvalidArgumentException(); } // ... } function is_reminder_date_valid($date) { $date_format = 'Y-m-d H:i:s’; $formatted_date = \DateTime::createFromFormat($date_format, $date); return $formatted_date && $formatted_date->format($date_format) === $date; }
  7. function create_reminder($name, $date = '') { // ... if (!empty($date)

    && !is_reminder_date_valid($date)) { throw new InvalidArgumentException(); } // ... } function is_reminder_date_valid($date) { $date_format = 'Y-m-d H:i:s'; $formatted_date = \DateTime::createFromFormat($date_format, $date); return $formatted_date && $formatted_date->format($date_format) === $date; }
  8. function send_response(array $response) { if (!response_has_status_header($response)) { throw new \InvalidArgumentException();

    } // ... } function response_has_status_header(array $response) { return !empty($response['headers']) && is_array($response['headers']) && !empty($response['headers']['status']); }
  9. function send_response(array $response) { if (!response_has_status_header($response)) { throw new \InvalidArgumentException();

    } // ... } function response_has_status_header(array $response) { return !empty($response['headers']) && is_array($response['headers']) && !empty($response['headers']['status']); }
  10. function insert_default_value($mixed) { if ($mixed instanceof ToStringInterface) { $mixed =

    $mixed->to_string(); } if (!is_string($mixed) || empty($mixed)) { $mixed = 'value'; } return $mixed; }
  11. function insert_default_value($mixed) { if ($mixed instanceof ToStringInterface) { $mixed =

    $mixed->to_string(); } elseif (!is_string($mixed) || empty($mixed)) { $mixed = 'value'; } return $mixed; }
  12. function insert_default_value($mixed) { if ($mixed instanceof ToStringInterface) { $mixed =

    $mixed->to_string(); } elseif (!is_string($mixed) || empty($mixed)) { $mixed = 'value'; } return $mixed; }