-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
UUID.[]
constructor
#13074
Comments
This is a −1 from me. Writing I draw the line even a bit earlier - I am also against using |
I thought we had a achieved a broad consensus on the
What would be types where it makes sense and where doesn't it? I don't see how such a distinction would be made.
The main intention is for Now whether that format uses a new |
@straight-shoota This is Ruby
Look! I think if there's an easy way to have But if you have to start changing a type's API just so that Hey! Look at this:
BAM! That's not valid Ruby anymore. |
Why should that prevent Crystal to do better?
Why is that a no? I don't see any reason why that would be a bad thing. |
Crystal tries to avoid having multiple ways to do the same thing. If you have Maybe the question is: in which scenario you saw a UUID being inspected and you wanted to copy that output for something? |
For that matter, I don't understand why UUID needs this special treatment. What about Bigint? An Atomic value? Etc. Are we going to adjust the entire standard library for that? |
Yes, it adds an additional way to do the same thing. And Crystal intentionally tries to avoid that. But we're not dogmatic about it. Sometimes it's worth more to have some duplication when it brings other value. In this case it brings the great convenience of being able to copy the output of It's not something that you have to explicitly learn about for every type. It's a generic pattern and you only need to know that the I don't recall the exact circumstances, but I've wished UUID would be that convenient two or three times before I felt the need to address this in #11879.
This is explicitly not a specific development about UUID, we're just discussing UUID in this particular issue. We've adopted the general pattern already in a couple of types and expect to expand to more where it makes sense. That's usually for simple value types and maybe some container types as well.. |
#11879 changes the
UUID#inspect
format to code that can be used to recreate a UUID instance with the same value using the[]
constructor.This constructor however doesn't exist yet. This is a feature request to add it.
The exact semantics need to be determined.
UUID
has has four different.new
overloads accepting eitherString
,StaticArray
,Bytes
orUUID
as main parameter. I suppose it makes sense to accept the same types for.[]
and just forward to the respective overload. Although for this syntax, I figure theString
overload to be most useful. Perhaps we should leave out the others?Another question is whether the optional
version
andvariant
parameters should also be supported. It might not be super necessary, but it's easy enough to do that (they're identical in all.new
overloads).I would make them only available as named parameters for clarity, though (should probably do that for
.new
as well).The text was updated successfully, but these errors were encountered: