Emma Boudreau
2 min readApr 15, 2024

--

Of course, abstraction and methods always has the ability to use methods unexpectedly.

E.g. Inheritance could certainly derive a similar unintended behavior, and of course this is what overloading is for. I would say the main reason this is concerning more-so is because the methods aren't part of the object, but the functions. They are certainly disconnected.

Of course, there is no inheritance of attributes, a key distinction is that it is hard to know what fields or methods abstract types have in common.

Things are also a little different though, as the methods are not part of the types but part of the functions -- most functions are not written super generically in Julia.

```julia

julia> methods(filter)

# 10 methods for generic function "filter" from Base:

[1] filter(f)

@ array.jl:2690

[2] filter(f, t::Tuple)

@ tuple.jl:440

[3] filter(f, a::Array{T, N}) where {T, N}

@ array.jl:2605

[4] filter(f, d::AbstractDict)

@ abstractdict.jl:471

[5] filter(f, Bs::BitArray)

@ bitarray.jl:1823

[6] filter(f, a::AbstractArray)

@ array.jl:2617

[7] filter(pred, s::AbstractSet)

@ abstractset.jl:489

[8] filter(f, s::Union{SubString{String}, String})

@ strings/substring.jl:268

[9] filter(f, s::AbstractString)

@ strings/basic.jl:634

[10] filter(f, itr::Base.SkipMissing{<:AbstractArray})

@ missing.jl:393

--------

julia> using DataFrames

julia> methods(filter)

# 10 methods for generic function "filter" from Base:

[1] filter(f)

@ array.jl:2690

[2] filter(f, t::Tuple)

....

[19] filter(f, s::AbstractString)

@ strings/basic.jl:634

[20] filter(f, itr::Base.SkipMissing{<:AbstractArray})

@ missing.jl:393

[21] filter(f, a::SentinelArrays.ChainedVector{T, A} where A<:AbstractVector{T}) where T

@ SentinelArrays ~/.julia/packages/SentinelArrays/1kRo4/src/chainedvector.jl:907

[22] filter(f, a::AbstractArray)

@ array.jl:2617

[23] filter(f, gdf::GroupedDataFrame; ungroup)

@ DataFrames ~/.julia/packages/DataFrames/58MUJ/src/groupeddataframe/groupeddataframe.jl:1181

[24] filter(f, df::AbstractDataFrame; view)

@ DataFrames ~/.julia/packages/DataFrames/58MUJ/src/abstractdataframe/abstractdataframe.jl:1188

```

Above, the methods are pretty direct and describe a certain area of the type system -- anything that differs of course would have a different Method to go along with its implementation.

I think part of the reason I would say this is not high coupling is because methods are still heavily utilized alongside abstraction; the tools are there to prevent high coupling, someone not using them is no fault of your language.

To your concern, though, yes it is the design -- the downside you mentioned is certainly noteworthy -- it is certainly possible to be calling the wrong method, a lot more so than typical of using inheritance. One counter-balance to this is introspection. Julia also has a robust type system to help facilitate this paradigm and abstraction system... but also, it is ultimately a design choice -- it provides advantages and disadvantages, like any design choice.

I don't disagree, but it seems to work great for me!

--

--

Emma Boudreau
Emma Boudreau

Written by Emma Boudreau

i am a computer nerd. I love art, programming, and hiking. https://github.com/emmaccode

Responses (1)