-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Use new where syntax in misc files #21428
Conversation
Out of curious: Is this now the recommended form for parameterized functions? |
The old version might be deprecated/replaced in 1.0 so that it can be used to define outer constructors. |
This is a pretty fundamental change. The old syntax was pretty readable IMHO. I thought that |
The new syntax helps clarify parameterized function and parameterized constructors and IMO is a lot more clear and less confusing now. |
Could you give a link where this has been decided? In my point of view the former syntax was clear and readable, whereas the trailing notation requires looking back and forth (i.e. is less readable) |
Very heavily discussed here #18457 The new rule is a lot more simple: if there is a type X{T}; end
X{T}(::T) = X{T}()
type Y{T}; end
Y{T}(::T) where {T} = Y{T}()
|
What does the following definition do?
It shouldn't be controversial that this looks like it defines a constructor for the type See discussion starting here: #10146 (comment) |
I partly understand this issue within constructors. But this is a quite local issue in contrast to parametrized functions that occur a lot more often than constructors. I had a look at the above patch and it seems that 100% of the changes did not involve a constructor. |
That is largely because this syntax change has already been done for constructors. |
You're right that non-constructors occur much more often than constructors, but the syntax should still be consistent. We don't want |
I see the consistency issue here. I am not sure if this outweighs the regression in readability. One could also see the |
Not everybody agrees that there is any regression in readability. For instance I found the examples in #11310 (comment) compelling in favor of the new syntax. Arguably, the list of static parameters and their bounds is not the first thing you want to see. Both the old and new syntax group together (1) the arguments, (2) the static parameter bounds, so with either syntax you might have to look back and forth. There is also a new syntax that combines them:
In that case there is truly no looking back and forth. Some also find that the |
ok, maybe I simply need to get used to that. Thanks for the explanation. |
8f6eca2
to
a961492
Compare
So could the first line in this pull request
become
instead of
|
No because we need I suppose this would work |
Yes, of course But I do agree with @tknopp that the new syntax is overly verbose for ordinary functions. |
I think once you get used to the syntax you start appreciating it, give it a shot first before dismissing it. It took me awhile to get used to the current syntax and how it works, but now it feels natural, so I think familiarity has strong impact on preference. |
aaa528e
to
18ec763
Compare
base/pair.jl
Outdated
@@ -35,5 +35,5 @@ function convert(::Type{Pair{A,B}}, x::Pair) where A where B | |||
Pair{A, B}(convert(A, x[1]), convert(B, x[2])) | |||
end | |||
|
|||
promote_rule{A1, B1, A2, B2}(::Type{Pair{A1, B1}}, ::Type{Pair{A2, B2}}) = | |||
promote_rule(::Type{Pair{A1, B1}}, ::Type{Pair{A2, B2}}) where {A1, B1, A2, B2} = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra spaces?
base/dates/types.jl
Outdated
@@ -298,7 +298,7 @@ Base.eltype{T<:Period}(::Type{T}) = T | |||
Base.promote_rule(::Type{Date}, x::Type{DateTime}) = DateTime | |||
Base.isless{T<:TimeType}(x::T, y::T) = isless(value(x), value(y)) | |||
Base.isless(x::TimeType, y::TimeType) = isless(Base.promote_noncircular(x, y)...) | |||
=={T<:TimeType}(x::T, y::T) = ==(value(x), value(y)) | |||
==(x::T, y::T) where {T<:TimeType} = ==(value(x), value(y)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Unrelated, but the } = ==(
tripped up my wetware parser. Perhaps infix ==
would be better?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, but I think this is better for a separate PR
base/docs/utils.jl
Outdated
@@ -72,7 +72,7 @@ print(io::IO, t::Text) = print(io, t.content) | |||
print(io::IO, t::Text{<:Function}) = t.content(io) | |||
show(io::IO, t::Text) = print(io, t) | |||
|
|||
=={T<:Union{HTML, Text}}(t1::T, t2::T) = t1.content == t2.content | |||
==(t1::T, t2::T) where {T<:Union{HTML, Text}} = t1.content == t2.content |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space?
base/test.jl
Outdated
a::StridedVecOrMat{S}, b::StridedVecOrMat{T}, | ||
err = length(indices(a,1))^3*(eps(S)+eps(T)) | ||
) | ||
) where {S<:Real,T<:Real} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent seems odd?
@@ -25,17 +25,17 @@ const BitUnsigned64T = Union{Type{UInt8}, Type{UInt16}, Type{UInt32}, Type{UInt6 | |||
|
|||
## integer comparisons ## | |||
|
|||
<{T<:BitSigned}(x::T, y::T) = slt_int(x, y) | |||
(<)(x::T, y::T) where {T<:BitSigned} = slt_int(x, y) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space or alignment here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no this is supposed to be aligned with the code in the lines below
base/promotion.jl
Outdated
promote_to_supertype{T<:Number,S<:Number}(::Type{T}, ::Type{S}, ::Type{T}) = (@_pure_meta; T) | ||
promote_to_supertype{T<:Number,S<:Number}(::Type{T}, ::Type{S}, ::Type{S}) = (@_pure_meta; S) | ||
promote_to_supertype{T<:Number,S<:Number}(::Type{T}, ::Type{S}, ::Type) = | ||
promote_to_supertype(::Type{T}, ::Type{T}, ::Type{T}) where {T<:Number } = (@_pure_meta; T) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the injection of spaces for alignment would be better between the }
and =
?
base/linalg/lq.jl
Outdated
@@ -137,15 +137,15 @@ end | |||
|
|||
## Multiplication by Q | |||
### QB | |||
A_mul_B!{T<:BlasFloat}(A::LQPackedQ{T}, B::StridedVecOrMat{T}) = LAPACK.ormlq!('L','N',A.factors,A.τ,B) | |||
A_mul_B!(A::LQPackedQ{T}, B::StridedVecOrMat{T}) where {T<:BlasFloat} = LAPACK.ormlq!('L','N',A.factors,A.τ,B) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra spaces?
base/linalg/matmul.jl
Outdated
|
||
function dot{T<:BlasReal, TI<:Integer}(x::Vector{T}, rx::Union{UnitRange{TI},Range{TI}}, y::Vector{T}, ry::Union{UnitRange{TI},Range{TI}}) | ||
function dot(x::Vector{T}, rx::Union{UnitRange{TI},Range{TI}}, y::Vector{T}, ry::Union{UnitRange{TI},Range{TI}}) where {T<:BlasReal, TI<:Integer} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space?
base/linalg/matmul.jl
Outdated
@@ -56,7 +56,7 @@ function dot{T<:BlasReal, TI<:Integer}(x::Vector{T}, rx::Union{UnitRange{TI},Ran | |||
BLAS.dot(length(rx), pointer(x)+(first(rx)-1)*sizeof(T), step(rx), pointer(y)+(first(ry)-1)*sizeof(T), step(ry)) | |||
end | |||
|
|||
function dot{T<:BlasComplex, TI<:Integer}(x::Vector{T}, rx::Union{UnitRange{TI},Range{TI}}, y::Vector{T}, ry::Union{UnitRange{TI},Range{TI}}) | |||
function dot(x::Vector{T}, rx::Union{UnitRange{TI},Range{TI}}, y::Vector{T}, ry::Union{UnitRange{TI},Range{TI}}) where {T<:BlasComplex, TI<:Integer} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space?
base/essentials.jl
Outdated
@@ -133,18 +133,18 @@ function typename(a::Union) | |||
end | |||
typename(union::UnionAll) = typename(union.body) | |||
|
|||
convert{T<:Tuple{Any,Vararg{Any}}}(::Type{T}, x::Tuple{Any, Vararg{Any}}) = | |||
convert(::Type{T}, x::Tuple{Any, Vararg{Any}}) where {T<:Tuple{Any,Vararg{Any}}} = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent / extra space?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This space was already there but I might as well also fix this thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cheers :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much thanks for slogging through this @musm! Generally looks great.
(Abstracting from this PR, developing a consistent style guideline for when to use e.g. where {S,T}
rather than where S where T
in long-form method definitions involving more than one type parameter seems worthwhile. After reading through this diff, I lean towards using the compact form consistently.)
Agreed, although I don't have a strong pref on the convention, but that we should have some guideline Also thank you for going through this. I pushed a commit to address reviews. Can you please take another look to give it a final g2g. |
imported::Bool = false, | ||
ambiguous_bottom::Bool = false, | ||
allow_bottom::Union{Bool,Void} = nothing) | ||
if allow_bottom !== nothing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated but shoould be !== not !=
if allow_bottom != nothing | ||
imported::Bool = false, | ||
ambiguous_bottom::Bool = false, | ||
allow_bottom::Union{Bool,Void} = nothing) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this how we break spacing ? I don't see anywhere else where we put the closing )
on a seperate line
Checked out the touchup commit (#32) --- lgtm! :)
Some squashing seems in order. Though how much squashing would be best I don't know. Perhaps someone wiser in this regard will weigh in? |
I think it might just make the most sense to squash all the commits, I can't see any benefit otherwise |
can we merge this now? |
The changes here in That's a bug in those packages, but in the interest of not breaking things that were previously passing right before an RC, we should probably revert the part of this that changed deprecated.jl for now. |
cc @TotalVerb for |
https://github.com/JuliaCI/pkg.julialang.org/blob/3e484195ef2fcccae5f1447447c3590d142e570e/logs/LanguageServer_0.6.log but it's the exact same failure, I think it tries to Lint itself |
I'll have a fix in Lint. It's probably that lint is trying to parse Base's deprecated.jl file, and doesn't understand |
tahnks @TotalVerb ! |
No description provided.