TheDirtyDozen

alternate text

KubaWerłos

SoftwareHouseInnovativeTechnologies


by

alternate text

KICK ME

alternate text

KeepItComplicatedKeepMeEmployed

One good programmer can easily create two new jobs a year.

KICK ME


  • I am having trouble understanding this code.
  • Let's take a look.
  • Do you see this function? It calls these 13 other functions and has roughly 1000 lines of commented out code in it.
  • Ah yes, that is the Job Security Design Pattern in action!

Hundred responsibilities principle


alternate text
the more the merrier

knows very much or does very much

knows very much
LOC, properties, methods
does very much
cyclomatic complexity

Hundred responsibilities principle

LOC
CC
1.
giggsey/libphonenumber-for-php/src/geocoding/data/en/61.php
61 094
1
2.
Mpdf\Mpdf
27 506
7 021
3.
TCPDF
24 748
4 415
4.
voku\helper\UTF8
14 100
1 498
5.
ScssPhp\ScssPhp\Compiler
10 430
1 493
6.
TYPO3\CMS\Core\DataHandling\DataHandler
10 020
1 450
7.
WordPress/wp-includes/functions.php
8 467
826
8.
PhpOffice\PhpSpreadsheet\Reader\Xls
8 088
1 020

Untestability

Profits of not having tests:

  • not doing work no one pays for
  • no problems with failing build on CI
  • increase need for manual testing
  • more thrilling changes to the code
  • make it harder to change the code without worrying that anything will get broken
  • deprive us from having documentation for what the code is actually meant to do

Untestability


open/closed principle


A module should be open for modification.

A module should be closed for extension.

Redefine the functionality



reinventing the wheel

re-implementing (limited) PHP functions

prefer implementing custom solutions over using open source library

overriding methods

Really big interfaces



big ⟶ complicated


complicated ⟶ advanced


advanced ⟶ smart

Really big interfaces

Methods
1.
Carbon\CarbonInterface
375
2.
Magento\Sales\Api\Data\OrderInterface
274
3.
Illuminate\Support\Enumerable
139
4.
Drupal\Core\Form\FormStateInterface
91
5.
Knp\Menu\ItemInterface
58
6.
Doctrine\ORM\Query\TreeWalker
50
7.
Laminas\Barcode\Object\ObjectInterface
47
8.
Symfony\Component\Form\FormInterface
35

You should rely on others


Extend third party libraries directly


                    class InvoicePdf extends FPDF
                    {
                    }

Use third party libraries directly

new Symfony\Component\Process\Process(/* ... */);
Hundred responsibilities principle
Untestability
Redefine the functionality
Really big interfaces
You should rely on others

Bus factor