-
Notifications
You must be signed in to change notification settings - Fork 82
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
Make Snowflake -> String conversion more idiomatic #441
Conversation
I've to mention that before we proceed that |
The PR changes the functionality So that means you can compare json retrieved values with Is that what you mean? |
But this is not a string representation of a snowflake |
I think I get what you're saying. Is there a reason the citation's needed in the String representation? It's normal in idiomatic Kotlin for |
But they are numbers still, just limited, Snowflakes are not normal numbers in the system, they hold things like timestamps, date of creation etc. |
Yep! That's the semantics I was talking about |
I think I was also unclear in the previous comment comment.
but these are numbers, when you read the value you know it's a number, however, when you read a number that belongs to s a snowflake, you have no clue it's a snowflake. Snowflakes are not just numerical numbers, they hold, again, data like when the entity was created. Thus this is why asString exist. to allow get the string value of the snowflake, where as toString is for the representation |
Yeah I completely agree, but I'm not saying the string representation should give the impression that it's just a number. That wasn't really my point This is the general rule for
This is how you'll find it done everywhere in the official Kotlin libraries. Like I think you could agree that for There is a good reason why CdnUrl("$BASE_URL/guilds/$guildId/users/$userId/avatars/$hash") // this
CdnUrl("$BASE_URL/guilds/${guildId.asString}/users/${userId.asString}/avatars/$hash") // than this I'm also not sure I understand the concern with not knowing the number is a snowflake. E.g. |
And sorry for the wall of text. I hope I'm not being annoying because I don't mean to be, I just want to flesh out my thoughts. I've been using Kotlin as my language of choice since it was in beta and have a firm grasp on its conventions. I'm loving Kord so far and want to nudge it in the right direction if can, helping iron out any awkward or non-idiomatic APIs. Don't stress out about this PR if you really don't want to include the change :) |
Hey Ben, sorry for the late reply. I looked that up but I didn't find any source that mention such a convension. could you link me to the source? |
Hah no worries, and good question! I don't think it's documented anywhere as a hard-and-fast rule, that's just how I see it done in the official libraries. Like there aren't right/wrong ways to implement |
Hey Ben, sorry for not responding, Your points are valid and I don't see a reason to keep the toString as is, users can always define their own logging string on the entities. Tho I wonder how would this affect logging |
Hmm, you'd know better than I do since I haven't paid attention to Kord's logging at all so far |
Will merge this, we just have to wait for Scheduled events and auto complete to be merged. |
This PR deprecates
Snowflake.asString
, and gives its functionality toSnowflake.toString()
instead.(And migrates all usages of
.asString
in the repo to.toString()
)With this change,
"$snowflake"
can be done instead of"${snowflake.asString}"
.The main changes are in Snowflake.kt, with all the other changes being the migrations.
Thinking this is more idiomatic is mostly based on intuition, but I have some rationale:
"Snowflake(value=...)"
outside of println debuggingSnowflake.toString()
is never used in this repo"...${snowflake.asString}..." is used 26 times
, when"...$snowflake..."
would be more convenientasString
being a property feels out of place, since semantically it's a conversion, not an attribute of Discord snowflakessnowflake == Snowflake(snowflake.toString())
.to*()
and.as*()
functions:snowflake.asString == snowflake.toString()