# OOP-like dot notation in Julia

**URL:** <https://discourse.julialang.org/t/oop-like-dot-notation-in-julia/120971>\
**Category:** Internals & Design\
**Created:** [October 6, 2024, 11:18am UTC](https://discourse.julialang.org/t/oop-like-dot-notation-in-julia/120971 "2024-10-06T11:18:07Z")\
**Posts on this page:** 5\
**Page:** 3

<div class="post-metadata">

**Author:** ![bertschi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bertschi/32/33462_2.png) [@bertschi](https://discourse.julialang.org/u/bertschi)\
**Post date:** [October 7, 2024, 10:15pm UTC](https://discourse.julialang.org/t/oop-like-dot-notation-in-julia/120971/41 "2024-10-07T22:15:19Z")

</div>

100% agree with @Benny that solutions like `obj.<tab>` which work fine with class based OOP languages are not a good fit for Julia (which for good reason imho is not OOP). Instead, we need to be open for other and potentially totally different solutions. For inspiration, Haskell has [Hoogle](https://hoogle.haskell.org/) allowing to search for functions by type signature. Again, this is most likely not directly transferable to Julia which is much more dynamic and less reliant on strict type signatures … admittedly, the best solution for Julia has not been found yet, but good building blocks like `methodswith`, `JET` etc are are already there and could be better integrated. I’m convinced though that the solution will not be retrofitting `obj.<tab>` in some way?!?

---

<div class="post-metadata">

**Author:** ![co1emi11er](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/co1emi11er/32/206849_2.png) [@co1emi11er](https://discourse.julialang.org/u/co1emi11er)\
**Post date:** [October 8, 2024, 12:02am UTC](https://discourse.julialang.org/t/oop-like-dot-notation-in-julia/120971/42 "2024-10-08T00:02:52Z")

</div>

> [@bertschi](#):
>
> 100% agree with @Benny that solutions like `obj.<tab>` which work fine with class based OOP languages are not a good fit for Julia (which for good reason imho is not OOP). Instead, we need to be open for other and potentially totally different solutions.

I agree as well. The `obj.<tab>` syntax doesn’t seem to mesh well with julia. I do think `obj |> <tab>` (if pipe had more capabilities) and `?(obj <tab>` provide use cases for both ways of writing julia code.

> [@Benny](#):
>
> I don’t expect dependents to be able or willing to take the maintenance burden of extending Inventory’s list of important methods, and I don’t want to see other package’s methods mixed in any more than people would want functions outside classes to be listed among member methods.

The `@lsp ::MyType = [foo, bar, baz]` idea was just trying to imagine a way to get that manual support if you truly didn’t want to write an explicit method in your codebase. The more I think about the idea though, the more I like it due to the fact that this can live in your package/script and not the maintainers. It doesn’t have to look like the syntax above. It could even be in a .toml or .json file.

The main idea with this is I can tailor lsp to show functions for my needs. So yes you get the function list after tab for the explicit functions (you will then see explicit methods after you type out said function), but like you said

> [@Benny](#):
>
> “what methods in this other package could I try this type in?”

I think this allows me to do that discovery/navigation and then document it for myself to use and benefit from the lsp. Because I often forget and I have to rediscover and navigate again.

I think this also simplifies things a bit. Everyone gets a nice function list for the object on `<tab>` for the explicit functions. The other functions that you want are not free, but you can get them added how you want.

Thoughts?

---

<div class="post-metadata">

**Author:** ![jlapeyre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlapeyre/32/4514_2.png) [@jlapeyre](https://discourse.julialang.org/u/jlapeyre)\
**Post date:** [October 12, 2024, 4:02am UTC](https://discourse.julialang.org/t/oop-like-dot-notation-in-julia/120971/43 "2024-10-12T04:02:25Z")

</div>

I misremembered above. In fact, I _did_ add a feature to allow rearranging the order of the arguments. To get the order that Python uses for `split`, you do this:

```julia
julia> using CBOOCall
julia> @eval Base import CBOOCall;
julia> @eval Base CBOOCall.@cbooify String (split = (x, y) -> split(y, x),);
julia> "a,b,c".split(",")
3-element Vector{SubString{String}}:
 "a"
 "b"
 "c"

```

To use the original order of the Julia method, you do:

```julia
@eval Base CBOOCall.@cbooify String (split,)

```

and then `",".split("a,b,c")`

This is not meant to be a useful example. In fact, it’s an example where the natural ordering of arguments is not clear.

I still haven’t decided on what new name, if any, to choose. I’d like to hear opinions, although this thread may not be the best place.

I pushed a repo that changes the name to [DotCall.jl](https://github.com/jlapeyre/DotCall.jl)  
Here is the original [CBOOCall.jl](https://github.com/jlapeyre/CBOOCall.jl) (it has more tests and minor corrections.)

`DotCall` is more descriptive. But “`@cbooify`” somehow seems “punchier” than “`@dotcallify`”.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [October 12, 2024, 4:18am UTC](https://discourse.julialang.org/t/oop-like-dot-notation-in-julia/120971/44 "2024-10-12T04:18:48Z")

</div>

Did you register the package?

---

<div class="post-metadata">

**Author:** ![jlapeyre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlapeyre/32/4514_2.png) [@jlapeyre](https://discourse.julialang.org/u/jlapeyre)\
**Post date:** [October 12, 2024, 5:08am UTC](https://discourse.julialang.org/t/oop-like-dot-notation-in-julia/120971/45 "2024-10-12T05:08:53Z")

</div>

CBOOCall is registered. The new one DotCall is not registered. I am considering registering it and deprecating CBOOCall.

[Previous page](https://discourse.julialang.org/t/oop-like-dot-notation-in-julia/120971.md?page=2)
