2024-01-03 20:00:00 +00:00
|
|
|
---
|
|
|
|
title: >
|
2024-02-07 20:01:19 +00:00
|
|
|
Suffixing names
|
2024-01-03 20:00:00 +00:00
|
|
|
pubDate: 2023-12-10
|
|
|
|
permalink: >-
|
2024-02-07 20:01:19 +00:00
|
|
|
archive/2023/12/10/suffixing-names
|
2024-01-03 20:00:00 +00:00
|
|
|
tags:
|
2024-02-07 20:01:19 +00:00
|
|
|
- software-development
|
|
|
|
- php
|
|
|
|
- drupal
|
|
|
|
- symfony
|
|
|
|
- clean-code
|
2024-01-03 20:00:00 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
When writing code, it's common to suffix the class name with the type of class it is.
|
|
|
|
|
|
|
|
I do this often for most types of classes, such as Controllers, EventListeners, Factories, Repositories and Builders.
|
|
|
|
|
|
|
|
However, I don't always for value objects and data transfer objects (DTOs).
|
|
|
|
|
|
|
|
Also, I don't always suffix interfaces with `Interface`.
|
|
|
|
|
|
|
|
I've been re-reading the documentation for the Symfony Serializer component, which references both `NameConverterInterface` and `MyDto::class`.
|
|
|
|
|
|
|
|
Whilst it does make the names more verbose, it does clarify what the class is used for.
|
|
|
|
|
|
|
|
Symfony's coding standards and Drupal's PHP coding standards have conventions for this, but what do you think?
|
|
|
|
|
|
|
|
Do you add suffixes to your class or interface names, or do you prefer the simplified versions?
|