Skip to content

Commit 8693a08

Browse files
authored
Merge pull request piotrplenik#170 from peter-gribanov/delete_functions_one_thing
Delete "Functions should do one thing" section
2 parents 89ab6f1 + 5e2d423 commit 8693a08

File tree

1 file changed

+0
-46
lines changed

1 file changed

+0
-46
lines changed

README.md

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
* [Use identical comparison](#use-identical-comparison)
1919
4. [Functions](#functions)
2020
* [Function arguments (2 or fewer ideally)](#function-arguments-2-or-fewer-ideally)
21-
* [Functions should do one thing](#functions-should-do-one-thing)
2221
* [Function names should say what they do](#function-names-should-say-what-they-do)
2322
* [Functions should only be one level of abstraction](#functions-should-only-be-one-level-of-abstraction)
2423
* [Don't use flags as function parameters](#dont-use-flags-as-function-parameters)
@@ -535,51 +534,6 @@ class Questionnaire
535534

536535
**[⬆ back to top](#table-of-contents)**
537536

538-
### Functions should do one thing
539-
540-
This is by far the most important rule in software engineering. When functions do more
541-
than one thing, they are harder to compose, test, and reason about. When you can isolate
542-
a function to just one action, they can be refactored easily and your code will read much
543-
cleaner. If you take nothing else away from this guide other than this, you'll be ahead
544-
of many developers.
545-
546-
**Bad:**
547-
```php
548-
function emailClients(array $clients): void
549-
{
550-
foreach ($clients as $client) {
551-
$clientRecord = $db->find($client);
552-
if ($clientRecord->isActive()) {
553-
email($client);
554-
}
555-
}
556-
}
557-
```
558-
559-
**Good:**
560-
561-
```php
562-
function emailClients(array $clients): void
563-
{
564-
$activeClients = activeClients($clients);
565-
array_walk($activeClients, 'email');
566-
}
567-
568-
function activeClients(array $clients): array
569-
{
570-
return array_filter($clients, 'isClientActive');
571-
}
572-
573-
function isClientActive(int $client): bool
574-
{
575-
$clientRecord = $db->find($client);
576-
577-
return $clientRecord->isActive();
578-
}
579-
```
580-
581-
**[⬆ back to top](#table-of-contents)**
582-
583537
### Function names should say what they do
584538

585539
**Bad:**

0 commit comments

Comments
 (0)