Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: change xID to xId #6036

Merged
merged 2 commits into from
Jul 4, 2021

Conversation

kyranet
Copy link
Member

@kyranet kyranet commented Jul 4, 2021

Please describe the changes this PR makes and why it should be merged:

Did somebody order a pizza? Well, sorry to break it for you, it's another dish of breaking changes.

ℹ️ This Pull Request does not break every single bot using discord.js, and will for the most part, break those that use resolveID.

Barely any bot works untouched when switching from v12 to v13 and Sapphire is still unaffected, even by this.

Basically, the gist of this PR is that all instances of ID have been changed to Id, that includes resolveID -> resolveId, messageID -> messageId, channelID -> channelId, guildID -> guildId, etc. And this has been in our backlog for around 2 years, so this change was coming out sooner or later.

Status and versioning classification:

  • I know how to update typings and have done so, or typings don't need updating
  • This PR includes breaking changes (methods removed or renamed, parameters moved or removed)

@kyranet kyranet added this to the Version 13 milestone Jul 4, 2021
Co-authored-by: Noel <buechler.noel@outlook.com>
Copy link
Contributor

@ImRodry ImRodry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few things I'd like to see clarified. Also if you're doing this for consistency with casing across the library, why not change URL -> Url?

@@ -98,20 +98,20 @@ class Client extends BaseClient {
: null;

/**
* All of the {@link User} objects that have been cached at any point, mapped by their IDs
* All of the {@link User} objects that have been cached at any point, mapped by their ids
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this and all the other JSDoc descriptions be kept as-is?

@@ -273,7 +273,7 @@ class Client extends BaseClient {

/**
* Obtains a webhook from Discord.
* @param {Snowflake} id ID of the webhook
* @param {Snowflake} id The webhook's id
Copy link
Contributor

@ImRodry ImRodry Jul 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this specific ID be upper case? (and all others that follow the same "The x's id" pattern)

@kyranet
Copy link
Member Author

kyranet commented Jul 4, 2021

URL stands for Uniform Resource Locator, it's an acronym, which go always uppercase.

Edit: As standalone words, we'd prefer them uppercase, while joined with other words (i.e. identifiers), we'd like them in PascalCase, e.g. UrlIdentifier over URLIdentifier.

@iCrawl iCrawl merged commit a7c6678 into discordjs:master Jul 4, 2021
@kyranet kyranet deleted the refactor/change-id-convention branch July 4, 2021 22:18
@DaStormer
Copy link
Contributor

Isn't ID an abbreviation? So, following camelCase, shouldn't it be capitalized (xID)?

Reference: Microsoft Abbreviation Guidelines

The word id, which following camelCase would be xId, has a different meaning.

@kyranet
Copy link
Member Author

kyranet commented Jul 7, 2021

I don't see where in the website says that it should be ID over Id. Also quite funny you quote MSFT's guidelines when the 2 biggest .NET library for Discord uses Id, as you can see in Discord.NET's MessageReference and DSharpPlus's DiscordMessageReference. Only library I don't see using Id (and rather uses ID) is Remora.Discord.

@monbrey
Copy link
Member

monbrey commented Jul 7, 2021

The guidelines seem to tell us not to use an abbreviation at all. The final sentence "If you must use abbreviations, use camel case for abbreviations that consist of more than two characters, even if this contradicts the standard abbreviation of the word."

Admittedly this abbreviation is not more than two characters.

But we can do what we want regardless.

@Drahcirius
Copy link
Member

https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/capitalization-conventions?redirectedfrom=MSDN#capitalizing-compound-words-and-common-terms

@TheNoob27
Copy link

I know it's way too late but I'm just seeing this now and I figured I'd mention that it's more than just being the same as other discord bot libraries.

What about people with databases? They've probably stored a few structures as userID or guildID by now. The toJSON method obviously used to use ID instead of Id, and people have definitely used that for storing or sending json. So having the keys change could cause some confusion.

Changing all instances of a function like resolveID to resolveId is one thing (although quite inconsistent), but then there's other parts like the short message references and toJSON objects.

Plus, even if no bot works untouched with discord.js v13, that doesn't mean you should make that a promise.

@kyranet
Copy link
Member Author

kyranet commented Jul 27, 2021

What about people with databases? They've probably stored a few structures as userID or guildID by now. The toJSON method obviously used to use ID instead of Id, and people have definitely used that for storing or sending json. So having the keys change could cause some confusion.

The same as #6189 - your fault for not sanitizing values and instead relying on whatever discord.js gives you (which by the way, is extremely inefficient storage wise, and often does not map to the raw data it accepts in the constructor).

If I were you and I stored data from Discord, I'd make sure to pass each relevant column/property that I'd need when reading it back, as opposed to passing a dynamic set of properties with a dynamic set of values, since that gives a lot more control and makes migrations across Discord and Discord.js versions a lot easier when they somehow change or get removed.

@TheNoob27
Copy link

Perhaps I didn't do a great job at explaining the problem I see with this change.

I definitely don't just throw random objects into my database, although I'm not sure if I can speak for everyone.
However, I do store specific keys, the ones that I need, and most of them are IDs. So obviously, seeing as discord.js uses ID, it would only make sense to do so too, right?
So now you've saved millions of documents with ID but you've gotta switch up your code to use Id in some places and ID in other places because of a new discord.js version.
If discord.js used Id throughout its lifetime, I wouldn't care or have a problem, but now I have to deal with saved keys as channelID or messageID while the library I use switches to channelId and messageId.

@kyranet
Copy link
Member Author

kyranet commented Jul 27, 2021

If you don't just throw random objects into your database, then you're perhaps sanitizing it to some point. Here, the solution is very simple, map Id keys to ID (e.g. { channelID: data.channelId }) or migrate the data to use Id.

Anyways, if you want to continue any further, please ask in the official Discord server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants