From 8cfccb1815d2241d031915cc886eda35347fd10b Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sun, 18 Aug 2024 14:13:52 +0100 Subject: [PATCH] Add daily email for 2024-08-17 Types add context --- source/_daily_emails/2024-08-17.md | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 source/_daily_emails/2024-08-17.md diff --git a/source/_daily_emails/2024-08-17.md b/source/_daily_emails/2024-08-17.md new file mode 100644 index 00000000..76cdc7b0 --- /dev/null +++ b/source/_daily_emails/2024-08-17.md @@ -0,0 +1,33 @@ +--- +title: Types add context +date: 2024-08-17 +permalink: daily/2024/08/17/types-add-context +tags: + - software-development + - clean-code +cta: ~ +snippet: | + Types add helpful context to code, making it easier to read and understand. +--- + +In yesterday's email, I wrote about why [readable variable names are important][0] and why I use descriptive variable names in my code. + +Given this pseudo-code: + +```php +function hande(req, res) { +} +``` + +With the short variable names, whilst you can guess, it's unclear what the variable names are. + +However, in this code, we have the same variable names, but we also have additional type information: + +```php +function handle(Request req, Response res): void { +} +``` + +Even with the same variable names, I know what their types are and what the function returns, I have better completions and diagnostics in my editor and better static analysis of my code, making it easier to identify and fix potential bugs. + +[0]: {{site.url}}/daily/2024/08/16/what-are-err--req-and-res