naming things
If something has a user-assigned name, that name should be able to be changed easily. It is said that there are only two hard problems in computer science: cache invalidation, and naming things. But the problem of naming doesn't need to remain a problem. If people just designed better systems then we could rename stuff whenever we want. The problem is that systems today are lame. Programmers have notoriously sucked at supporting human names, now we have to deal with naming programmy things.
Let us consider the Azure cloud provider. In Azure, I have a subscription that was automatically named Visual Studio Enterprise Subscription
. Within that subscription I have a resource group with the name ca.teamdman
. Within that resource group I have a storage account with the name teamdman
.
Lets look at the ID for that storage account: /subscriptions/9db267b9-fc59-4965-940a-6f30425c2f37/resourceGroups/ca.teamdman/providers/Microsoft.Storage/storageAccounts/teamdman
What the hell is that? Well, subscriptions can be renamed, so obviously subscriptions need to have a GUID that doesn't change when the name does. They went that far, then they completely dropped the ball with resource groups, which cannot be renamed. It is even worse with the storage account, which cannot be renamed but must ALSO have a globally unique name across every azure tenant. Someone else took your name? Get fucked, too bad. You had a nice naming convention going on and now you have to break it because some egg-head already owns a storage account using the same acronym? Tough shit.
This all stems from an overloading of the purpose of a name. In the case of the storage account, the name is also used in the ID and in subdomains used for connecting to the storage account (example: https://teamdman.blob.core.windows.net/).
What's the solution? Stop using one field to do different things. Give everything a GUID and be done with it, let me rename my crap. Add a parameter for changing the subdomain and enforce global uniqueness on that instead of forcing me to add a 1
to the end of my resource names as if I was creating a RuneScape account.
This is not just a problem with Azure, this is a problem with basically every website in existence. Usernames are actually two names in a trench coat: your login name, and your display name. Sometimes websites use your email as your login name but then don't let you change your display name. Sometimes they do let you change your display name, but then they require you to also have a four-digit tag to enforce uniqueness all over again. Looking at you, Discord and Xbox.
Renaming classes in Java is easy enough, you hit a hotkey and your IDE will edit whatever used to reference the old name to point to the new one. Naming infrastructure gets slightly harder, but again, the tools exist to make it easier. Infrastructure-as-code tools such as Terraform allow you to define your resources in code and then will handle the automatic creation and modification of those resources.
Here's what the storage account from earlier looks like in Terraform:
resource "azurerm_storage_account" "main" {
resource_group_name = azurerm_resource_group.main.name
location = "canadaeast"
name = "teamdman"
account_replication_type = "LRS"
account_tier = "Standard"
}
resource "azurerm_storage_container" "web" {
storage_account_name = azurerm_storage_account.main.name
name = "$web"
}
Like normal, I assign the name
property with what I want the storage account to be called. The important part is that I can reference that value elsewhere instead of just using more string literals. Even better, if I change that name property then Terraform will handle destroying the old storage account and creating a new one. If they supported renaming, then Terraform would rename it in place instead.
Takeaway: just let people rename shit. Make it easy to rename shit. As a byproduct, the most practical approach is usually to also give GUIDs to shit. Use infrastructure-as-code (IaC) tools to make your life easier when it comes time to rename shit. Make a separate field for your URLs or whatever part needs to be unique, but let people pick the display name for shit without imposing ANY constraints. Don't want people with zalgo usernames to fuck up your interface? Just fix your CSS to clip the text; don't prevent people from using their native alphabet just because you hate fun and decided to limit the character set to ASCII.