Julia: remove `repr(::UUID)`, move UUID code

Created on 20 Jun 2016  路  7Comments  路  Source: JuliaLang/julia

Looking at https://github.com/JuliaLang/julia/pull/17017, I noticed that there is room for more specialized (eg. faster) method specializations for repr().

julia> methods(repr)
#2 methods for generic function "repr"
repr(u::Base.Random.UUID) at random.jl:1252
repr(x) at strings/io.jl:86

The generic implementation in strings/io.jl:85 uses an IOBuffer, so it is probably much slower than it needs to be (especially for Strings which I think could be implemented as repr(s::string) = s). The documentation demands the result must be the same as showall, so testing should ensure that is still the case.

help wanted

Most helpful comment

Making this a method of string would be the way to go here. Moving UUIDs out would be good too.

All 7 comments

Since this function is just an alias for showall, I propose we eliminate it.

More precisely, it's an alias for sprint(showall, ...), right? I agree about deprecating it, since in 0.5 what's often needed is sprint(showcompact, ...) instead, and the fact that we have repr can cause confusion.

It is not the case that repr(x::String) = x, since repr adds quotes and escaping.

@JeffBezanson Thanks for noticing. I somehow managed to convince myself that it did not, but my REPL history shows I did not actually try.

If anything, the repr method for UUID should be removed since nothing else defines it directly. Instead it should define string or show. Then the UUID code is a good candidate for #5155, since AFAICT it's not used anywhere in Base.

Some of the UUID code will be needed for Pkg3, but if that itself is a package then it can have other-package dependencies that aren't all Base code.

Making this a method of string would be the way to go here. Moving UUIDs out would be good too.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dpsanders picture dpsanders  路  3Comments

tkoolen picture tkoolen  路  3Comments

iamed2 picture iamed2  路  3Comments

i-apellaniz picture i-apellaniz  路  3Comments

manor picture manor  路  3Comments