Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Namespace collision #10

Closed
joshday opened this issue Jun 18, 2016 · 17 comments
Closed

Namespace collision #10

joshday opened this issue Jun 18, 2016 · 17 comments

Comments

@joshday
Copy link
Contributor

joshday commented Jun 18, 2016

I apparently can't use a variable with the name d

julia> using RecipesBase, Plots

julia> type A end

julia> @recipe function f(::A)
           d = 100
           randn(d)
       end
apply_recipe (generic function with 66 methods)

julia> plot(A())
ERROR: MethodError: `convert` has no method matching convert(::Type{Dict{Symbol,Any}}, ::Array{Float64,1})
This may have arisen from a call to the constructor Dict{Symbol,Any}(...),
since type constructors fall back to convert methods.
Closest candidates are:
  Dict{K,V}(::Any)
  call{T}(::Type{T}, ::Any)
  convert{K,V}(::Type{Dict{K,V}}, ::Dict{K,V})
  ...
 in apply_recipe at /Users/joshday/.julia/v0.4/RecipesBase/src/RecipesBase.jl:237
 in _plot! at /Users/joshday/.julia/v0.4/Plots/src/plot.jl:292
@tbreloff
Copy link
Member

Yup. I don't think that's going to change.

On Saturday, June 18, 2016, Josh Day [email protected] wrote:

I apparently can't use a variable with the name d

julia> using RecipesBase, Plots

julia> type A end

julia> @recipe function f(::A)
d = 100
randn(d)
end
apply_recipe (generic function with 66 methods)

julia> plot(A())
ERROR: MethodError: convert has no method matching convert(::Type{Dict{Symbol,Any}}, ::Array{Float64,1})
This may have arisen from a call to the constructor Dict{Symbol,Any}(...),
since type constructors fall back to convert methods.
Closest candidates are:
Dict{K,V}(::Any)
call{T}(::Type{T}, ::Any)
convert{K,V}(::Type{Dict{K,V}}, ::Dict{K,V})
...
in apply_recipe at /Users/joshday/.julia/v0.4/RecipesBase/src/RecipesBase.jl:237
in _plot! at /Users/joshday/.julia/v0.4/Plots/src/plot.jl:292


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#10, or mute the
thread
https://github.com/notifications/unsubscribe/AA492k0w_byMBxyB05ICVmyuNEmeCOL3ks5qM_e0gaJpZM4I4839
.

@joshday
Copy link
Contributor Author

joshday commented Jun 18, 2016

I commonly see/use n, m, p, and d used to denote dimensions of matrices. Could it be changed to something more obscure? It's a pretty confusing error as it's not clear what I'm doing "wrong".

@joshday
Copy link
Contributor Author

joshday commented Jun 18, 2016

For clarity, I ran into this doing something like

type A
    mat::Matrix{Float64}
end

@recipe function f(a::A)
    n, d = size(a.mat)
    ...
end

@tbreloff
Copy link
Member

I could see changing it to 'kw', which shouldn't clash as much. The problem
is that it's a far-reaching breaking change and would require a coordinated
effort for every package using recipes.

On Saturday, June 18, 2016, Josh Day [email protected] wrote:

For clarity, I ran into this doing something like

type A
mat::Matrix{Float64}end
@recipe function f(a::A)
n, d = size(a.mat)
...end


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#10 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AA492s32MW3UYI5wS-RUJ1OdHQ1JHG6Aks5qNAHGgaJpZM4I4839
.

@joshday
Copy link
Contributor Author

joshday commented Jun 18, 2016

That's a fair reason for wanting to keep it as is, but it's a strange gotcha. Is there a way to get a more informative error?

@tbreloff
Copy link
Member

I suppose i could search for 'd' on the lhs of an equals and warn.

And I do see that 'kw' might be better than 'd'. It's just gonna cause a
dependency mess to change.

On Saturday, June 18, 2016, Josh Day [email protected] wrote:

That's a fair reason for wanting to keep it as is, but it's a strange
gotcha. Is there a way to get a more informative error?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#10 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AA492ojNj6Q7XpJXPALU2BYKFK2aeWvOks5qNAbxgaJpZM4I4839
.

@diegozea
Copy link

The whole point of having arg --> value and similar notations was not to expose d at the user. Maybe the remaining uses of d should be manage in a similar way, letting to the macro hygiene the manage of this problem (I guest... macros aren't my strong point).

@tbreloff
Copy link
Member

'-->' and ':=' notation is certainly to reduce the need to refer to 'd'
explicitly, but there's enough cases where it's still necessary. It's a
tricky problem to avoid clashes completely through macro-fu. A warning on
re-binding should be plenty.

On Saturday, June 18, 2016, Diego Javier Zea [email protected]
wrote:

The whole point of having arg --> value and similar notations was not to
expose d at the user. Maybe the remaining uses of d should be manage in a
similar way, letting to the macro hygiene the manage of this problem (I
guest... macros aren't my strong point).


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#10 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AA492gG-Dq-TsXY4EF7zCKMsncPCRIwyks5qNCKngaJpZM4I4839
.

@jw3126
Copy link
Contributor

jw3126 commented Feb 2, 2017

If you want to change from d to kw (I would actually prefer something more verbose, maybekeywords) I don't think it would be more hurtful then any of the other gazillion breaking changes julia programmers face day by day ;) You could proceed as follows:

Step 1) emit deprecations warnings if kw is used inside recipes.
Step 2) allow both d and kw, but emit warnings if d is used.
Step 3) disallow d

@mkborregaard
Copy link
Member

mkborregaard commented Jun 9, 2017

@jw3126 I'd support this if you'd make a coordinated set of PR's implementing this to 1) all repos in JuliaPlots, and 2) all packages depending on RecipesBase that have used d (or the term keywords), and 3) documented the change in the PlotDocs. There is a map of the dependencies here:
skaermbillede 2017-03-01 kl 14 51 25

@jw3126
Copy link
Contributor

jw3126 commented Jun 9, 2017

@mkborregaard Wow. How does one find the packages depending on a given package? If you have a list of packages depending on Plots/RecipiesBase I can at least do a bit of grepping and see if these PRs are possible with sane amount of work.

@mkborregaard
Copy link
Member

👍 Pkg.dependents

@jw3126
Copy link
Contributor

jw3126 commented Jun 11, 2017

ApproxFun
    Plot.jl
AtariAlgos
    AtariAlgos.jl
AverageShiftedHistograms
    bivariate.jl
    univariate.jl
BenchmarkProfiles
ConcaveHull
    ConcaveHull.jl
ConstructiveSolidGeometry
ControlSystems
DiffEqBase
    integrator_interface.jl
    monte_solutions.jl
    solution_interface.jl
DiffEqDevTools
    plotrecipes.jl
DiffEqNoiseProcess
    recipes.jl
DiffEqPDEBase
    plotrecipes.jl
DimensionalPlotRecipes
    DimensionalPlotRecipes.jl
DynamicMovementPrimitives
    utilities.jl
        92     delete!(d,:y0)
EEG
ExperimentalAnalysis
ImageQuilting
    plot_recipes.jl
ImplicitEquations
    plot_recipe.jl
        143     xlims = get(d,:xlims, (-5,5))
        144     ylims = get(d, :ylims, (-5,5))
IntervalArithmetic
    plot_recipes.jl
IterativeSolvers
    history.jl
JWAS
LPVSpectral
    plotting.jl
        21     delete!(d,:Fs)
        89     delete!(d, :normalization)
        90     delete!(d, :normdim)
        93         delete!(d, :dims)
        137     delete!(d, :phase)
        138     delete!(d, :bounds)
        139     delete!(d, :nMC)
        140     delete!(d, :mcmean)
LossFunctions
    io.jl
MIToS
    Plots.jl
    Plots.jl
Mimi
PenaltyFunctions
    elementpenalty.jl
PhyloTrees
    plot.jl
PlotRecipes
    finance.jl
        20         @series Plots.isvertical(d) ? (sx, sy) : (sy, sx)
    graphs.jl
        300     if get(d, :linewidth, 1) > 0
        316                                     xview=d[:xlims], yview=d[:ylims], root=root)
        335             grad = get(d, :linecolor, nothing)
        362         scalefactor = pop!(d, :markersize, nodesize)
        364         nodeshape = get(d, :markershape, nodeshape)
        416         colorgradient = ColorGradient(get(d,:linecolor,cgrad()))
        498     grad = cgrad(get(d,:linecolor,:inferno), get(d, :linealpha, nothing))
    misc.jl
    pkg_deps.jl
Plots
    recipes.jl
        82     xmin, xmax = hvline_limits(d[:subplot][:xaxis])
        94     ymin, ymax = hvline_limits(d[:subplot][:yaxis])
        126     d[:x], d[:y] = make_steps(x, y, :steppre)
        130     if d[:markershape] != :none
        147     d[:x], d[:y] = make_steps(x, y, :steppost)
        151     if d[:markershape] != :none
        173     fr = d[:fillrange]
        175         yaxis = d[:subplot][:yaxis]
        194     if d[:markershape] != :none
        227     fr = d[:fillrange]
        277     procx, procy, xscale, yscale, baseline = _preprocess_barlike(d, x, y)
        279     axis = d[:subplot][isvertical(d) ? :xaxis : :yaxis]
        290     bw = d[:bar_width]
        298     fillto = d[:fillrange]
        323     if !isvertical(d)
        392     edge, weights, xscale, yscale, baseline = _preprocess_binlike(d, x, y)
        393     if (d[:bar_width] == nothing)
        405     edge, weights, xscale, yscale, baseline = _preprocess_binlike(d, x, y)
        468     axis = d[:subplot][Plots.isvertical(d) ? :xaxis : :yaxis]
        470     edge, weights, xscale, yscale, baseline = _preprocess_binlike(d, x, y)
        473     if !isvertical(d)
        478     if d[:markershape] != :none
        559     h = _make_hist((y,), d[:bins], normed = d[:normalize], weights = d[:weights])
        568     h = _make_hist((y,), d[:bins], normed = d[:normalize], weights = d[:weights])
        577     h = _make_hist((y,), d[:bins], normed = d[:normalize], weights = d[:weights])
        593     seriestype := get(st_map, d[:seriestype], d[:seriestype])
        595     if d[:seriestype] == :scatterbins
        597         edge, weights, xscale, yscale, baseline = _preprocess_binlike(d, h.edges[1], h.weights)
        644     h = _make_hist((x, y), d[:bins], normed = d[:normalize], weights = d[:weights])
        665     if d[:markershape] == :none
        728     error_style!(d)
        730     d[:x], d[:y] = error_coords(d[:x], d[:y], error_zipit(d[:yerror]))
        736     error_style!(d)
        738     d[:y], d[:x] = error_coords(d[:y], d[:x], error_zipit(d[:xerror]))
        837         quiver_using_arrows(d)
        839         quiver_using_hack(d)
        943     if d[:markershape] == :none
        946     if d[:markersize] == default(:markersize)
    series.jl
        128     xs, _ = convertToAnyVector(x, d)
        129     ys, _ = convertToAnyVector(y, d)
        130     zs, _ = convertToAnyVector(z, d)
        132     fr = pop!(d, :fillrange, nothing)
        136         convertToAnyVector(fr, d)
        148             di = copy(d)
        205     newx = _apply_type_recipe(d, x)
        207     newy = _apply_type_recipe(d, y)
        209     newz = _apply_type_recipe(d, z)
        219     newx = _apply_type_recipe(d, x)
        221     newy = _apply_type_recipe(d, y)
        230     newy = _apply_type_recipe(d, y)
        243         newv = _apply_type_recipe(d, v)
        270 @recipe f(n::Integer) = is3d(get(d,:seriestype,:path)) ? (SliceIt, n, n, n) : (SliceIt, n, n, nothing)
        274     if all3D(d)
        276         wrap_surfaces(d)
        285     if all3D(d)
        288         wrap_surfaces(d)
        328         z, d[:fillcolor] = replace_image_with_heatmap(mat)
        358     plt = d[:plot_object]
        407     wrap_surfaces(d)
        417     wrap_surfaces(d)
        425     if !like_surface(get(d, :seriestype, :none))
        426         d[:seriestype] = :contour
        428     wrap_surfaces(d)
        480 @recipe f{R1<:Number,R2<:Number,R3<:Number,R4<:Number}(xyuv::AVec{Tuple{R1,R2,R3,R4}}) = get(d,:seriestype,:path)==:ohlc ? OHLC[OHLC(t...) for t in xyuv] : unzip(xyuv)
    runtests.jl
PyDSTool
    bifurcation.jl
        9   x = bif.d[coords[1]]
        10   y = bif.d[coords[2]]
RationalFunctions
    plotting.jl
RecursiveArrayTools
    vector_of_array.jl
Reinforce
    cartpole.jl
    mountain_car.jl
    pendulum.jl
Robotlib
    Frames.jl

WARNING: deprecated syntax "typealias Vect{Ty} Union{AbstractVector{Ty},Vec{3,Ty}}".
Use "Vect{Ty} = Union{AbstractVector{Ty},Vec{3,Ty}}" instead.

WARNING: deprecated syntax "typealias Matr{Ty} Union{AbstractMatrix{Ty},Mat{3,3,Ty}}".
Use "Matr{Ty} = Union{AbstractMatrix{Ty},Mat{3,3,Ty}}" instead.

WARNING: deprecated syntax "abstract GeometricObject".
Use "abstract type GeometricObject end" instead.

WARNING: deprecated syntax "typealias Vect{Ty} Union{AbstractVector{Ty},Vec{3,Ty}}".
Use "Vect{Ty} = Union{AbstractVector{Ty},Vec{3,Ty}}" instead.

WARNING: deprecated syntax "typealias Matr{Ty} Union{AbstractMatrix{Ty},Mat{3,3,Ty}}".
Use "Matr{Ty} = Union{AbstractMatrix{Ty},Mat{3,3,Ty}}" instead.

WARNING: deprecated syntax "abstract GeometricObject".
Use "abstract type GeometricObject end" instead.
    robotplot.jl
Sims
    utils.jl
SingularIntegralEquations
    plot.jl
SpatialEcology
    PlotRecipes.jl
StatPlots
    bar.jl
        10     isstack = pop!(d, :bar_position, :dodge) == :stack
        30         bws = d[:bar_width] / nc
        56         get(d, :fillrange, nothing)
    boxplot.jl
        12     bw = d[:bar_width]
        33         center = Plots.discrete_value!(d[:subplot][:xaxis], glabel)[1]
        86     if d[:linecolor] == d[:fillcolor]
        87 	d[:linecolor] = d[:markerstrokecolor]
        94 	    if get!(d, :markershape, :circle) == :none
        95             	d[:markershape] = :circle
        97             markercolor := d[:fillcolor]
        98             markerstrokecolor := d[:linecolor]
    cornerplot.jl
        18     labs = pop!(d, :label, ["x$i" for i=1:N])
        43     fillcolor --> Plots.fg_color(d)
        44     linecolor --> Plots.fg_color(d)
        49     grad = cgrad(get(d, :markercolor, cgrad()))
    corrplot.jl
        15     labs = pop!(d, :label, [""])
        23     fillcolor --> Plots.fg_color(d)
        24     linecolor --> Plots.fg_color(d)
        26     grad = cgrad(get(d, :markercolor, cgrad()))
        28     title = get(d,:title,"")
        37             update_ticks_guides(d, labs, i, i, n)
        50             update_ticks_guides(d, labs, i, j, n)
        63                     seriestype := get(d, :seriestype, :histogram2d)
    dataframes.jl
        68         if haskey(d, k)
        69             d[k] = processDFarg(df, d[k])
        74     tuple(Any[handle_dfs(df, d, (i==1 ? "x" : i==2 ? "y" : "z"), arg) for (i,arg) in enumerate(args)]...)
    distributions.jl
    groupederror.jl
        289     if !(:seriestype in keys(d)) || (d[:seriestype] == :path)
        300     elseif d[:seriestype] == :scatter
        313     elseif d[:seriestype] == :bar
    hist.jl
        7     if Plots.isvertical(d)
        25     if Plots.isvertical(d)
    marginalhist.jl
        4     x, y = d[:x], d[:y]
        27     fillcolor --> Plots.fg_color(d)
        28     linecolor --> Plots.fg_color(d)
        38     bns = get(d, :bins, nothing)
    shadederror.jl
        15     x,y = d[:x],d[:y]
    StatPlots.jl
    violin.jl
        21     bw = d[:bar_width]
        32         xcenter = Plots.discrete_value!(d[:subplot][:xaxis], glabel)[1]
SymEngine
    recipes.jl
SymPy
    plot_recipes.jl
        184     xlims = get(d,:xlims, (-5,5))
        185     ylims = get(d, :ylims, (-5,5))
TimeSeries
    plotrecipes.jl
        3     st = get(d, :seriestype, :path)
        47     st = get(d, :seriestype, :candlestick)
        55     bw = get(d, :bar_width, nothing)
        60     cols = get(d, :seriescolor, nothing)
ValueHistories
    recipes.jl
        21         if get(d, :layout, nothing) != nothing
        22             title  --> d[:label]

@jw3126
Copy link
Contributor

jw3126 commented Jun 11, 2017

This is all files that contain @recipe and are part of packages depending on Plots or RecipesBase. Lines inside @recipes that contain d are printed. There are no such lines containing keywords.
I think the @mkborregaard s PR idea looks feasible.

@jw3126
Copy link
Contributor

jw3126 commented Jun 11, 2017

Since keywords is used in none of these packages, I think we could skip Step 1 in

Step 1) emit deprecations warnings if keywords is used inside recipes.
Step 2) allow both d and keywords , but emit warnings if d is used.
Step 3) disallow d

Any thoughts?

@mkborregaard
Copy link
Member

Hey, thanks this is great. One thought - with regards the potential for conflicts, I believe they may in fact be even bigger with keywords (which is often used to pass kwargs, I think) than d - maybe a better name would be the descriptive plotattributes?
I should say I'm headed offline so I cannot give any support to this over the next weeks - you can choose to wait if you'd need me to help or go ahead with the assistance of other JuliaPlots members.

@jw3126 jw3126 mentioned this issue Jun 12, 2017
16 tasks
@daschw
Copy link
Member

daschw commented Mar 25, 2020

fixed by #29

@daschw daschw closed this as completed Mar 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants