Consistent patterns to convert types / find methods for a particular type?

I’ve done a fair amount of Julia programming and understand that “method” means something very different in Python vs Julia, however there are similarities too in that a method has type specificity (in Python always “self” whereas in Julia much more flexible thanks to multiple dispatch.

If I don’t know what methods are available for a particular type in Python, say an ndarray called x, I go into Jupyter and type x.<tab> and get a list of potentially relevant methods. And since names are near-always preserved between the Object-oriented and functional interface, it usually requires no documentation trip to figure this out even if I end up using a functional style.

In Julia, I often struggle to find what functions I can call on a type, sometimes there are patterns, like to change types usually I call convert. But not always. Sometimes you need to call Tuple first, other times collect, float(x), or maybe Float64.(x). Sometimes a Unitful integer works exactly as a normal integer, other times dispatch fails. It’s particularly tough since the ecosystem is so new, documentation is often lacking or out of date and I resort to looking at the tests or the source code, hoping I can stumble upon useful functions.

It’s often not easy to track down such discovery issues at the boundaries between packages. When I do hit cases where a function doesn’t work, I often find it time-consuming to figure out how to convert “fancy types” to the more primitive types, like Array{Float64}. For example, with Images.jl sometimes you need a gray() or sometimes convert(Array{Float64},x) works etc.

Functional programming patterns do suffer from this challenge in general, but it’s arguably easier in languages like Python, that has relatively few types, and it’s more consistent (but not easier…) in Haskell, which has rich types that are combined using common patterns, like Monads or MonadTransformers.

I don’t mean to pick on Unitful or Images—I think they are best-in-class packages and I love using them both. I just happen to be using them right now and examples came to mind.

Is there a workflow that I’m missing to make learning the ecosystem easier?

You may be looking for methodswith.

3 Likes

YES! thank you :slight_smile:.