From 5ab7758d6b2d2450e4d4c53f63180b7ab056a738 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 28 Mar 2025 16:17:25 +0000 Subject: [PATCH] Add daily email for 2025-03-26 Don't repeat yourself --- source/_daily_emails/2025-03-26.md | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 source/_daily_emails/2025-03-26.md diff --git a/source/_daily_emails/2025-03-26.md b/source/_daily_emails/2025-03-26.md new file mode 100644 index 000000000..39d6e3578 --- /dev/null +++ b/source/_daily_emails/2025-03-26.md @@ -0,0 +1,48 @@ +--- +title: Don't repeat yourself +date: 2025-03-26 +permalink: daily/2025/03/26/repeat +tags: + - software-development + - php +cta: ~ +snippet: | + "Don't repeat yourself" doesn't only apply to logic within code. +--- + +When most people think of "Don't repeat yourself" or DRY, they probably think about not duplicating logic in code. + +If you've written some functionality once, you should avoid writing it again. + +I was recently browsing the code for an open source package and saw this: + +```php +/** + * Flush everything. + */ +public function flush(): void; + +/** + * Sets the formatter. + */ +public function setFormatter(FormatterInterface $formatter): void; + +/** + * Gets the formatter. + */ +public function getFormatter(): FormatterInterface; +``` + +This is another instance of repetition. + +The docblocks are just repeating what the code already tells me. + +I can understand from the method names what each function does, and I can see what parameters they have and their types. + +I can see if each method returns anything and, if so, what type it returns - e.g. `getFormatter` returns a `FormatterInterface`. + +I think these docblocks aren't needed and in my projects, would suggest they be removed. + +Unless they're adding more information, such as [PHPStan PHPDoc types][0], there's no need to repeat what the code already says. + +[0]: {{site.url}}/daily/2025/03/21/phpdoc