# Is Julia's way of OOP superior to C++/Python? Why Julia doesn't use class-based OOP?

**URL:** <https://discourse.julialang.org/t/is-julias-way-of-oop-superior-to-c-python-why-julia-doesnt-use-class-based-oop/52058>\
**Category:** Internals & Design\
**Created:** [December 18, 2020, 4:32pm UTC](https://discourse.julialang.org/t/is-julias-way-of-oop-superior-to-c-python-why-julia-doesnt-use-class-based-oop/52058 "2020-12-18T16:32:10Z")\
**Posts on this page:** 7\
**Page:** 8

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 31, 2020, 4:07pm UTC](https://discourse.julialang.org/t/is-julias-way-of-oop-superior-to-c-python-why-julia-doesnt-use-class-based-oop/52058/144 "2020-12-31T16:07:30Z")

</div>

> [@ChrisRackauckas](#):
>
> For example `StatsBase.sample` is used all over the place, but the authors of Distributions.jl probably don’t know how Turing.jl has changed `StatsBase.sample` . It all works together though.

While I agree with your comments about the general principle, I don’t think this is a particularly good example — the uses of `sample` in Turing and StatsBase don’t have anything to do with each other, so it is just recycling the symbol for something completely different, not an example of generic programming. Technically fine, but not good style. See [this topic](https://discourse.julialang.org/t/what-is-the-difference-between-rand-and-sample/52297/).

Generally, defining & exporting a function `f` in a `...Base` package is useful if it is part of a generic interface other packages may extend, or just use without restricting to a particular type in mind. Nice examples include

> **[GitHub - JuliaPlots/RecipesBase.jl: Base package for defining transformation...](https://github.com/JuliaPlots/RecipesBase.jl)**
>
> Base package for defining transformation recipes on user types for Plots.jl - GitHub - JuliaPlots/RecipesBase.jl: Base package for defining transformation recipes on user types for Plots.jl

> **[GitHub - joshday/OnlineStatsBase.jl: Base types for OnlineStats.](https://github.com/joshday/OnlineStatsBase.jl)**
>
> Base types for OnlineStats. Contribute to joshday/OnlineStatsBase.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [December 31, 2020, 4:47pm UTC](https://discourse.julialang.org/t/is-julias-way-of-oop-superior-to-c-python-why-julia-doesnt-use-class-based-oop/52058/145 "2020-12-31T16:47:10Z")

</div>

Both are sampling points according to a distribution, one is just implicitly defined and the other is explicitly defined. I think more an more, a Turing model itself should be treated as a distribution. If the abstraction is done right then you should be able to use a Turing model as a prior distribution for another Turing model. The connection isn’t there yet but I don’t see a reason why it shouldn’t be in the future.

---

<div class="post-metadata">

**Author:** ![RogerP](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rogerp/32/17496_2.png) [@RogerP](https://discourse.julialang.org/u/RogerP)\
**Post date:** [December 31, 2020, 11:51pm UTC](https://discourse.julialang.org/t/is-julias-way-of-oop-superior-to-c-python-why-julia-doesnt-use-class-based-oop/52058/146 "2020-12-31T23:51:34Z")

</div>

> Is Julia’s way of OOP superior to C++/Python? Why Julia doesn’t use class-based OOP?

@vedasulo Your question hits the nail on the head – Java, C++ and (weakly) Python are Class-Oriented Programming (COP) languages, and COP requires multiple-layer inheritance with concrete class sub-classing to resolve the problems discussed above. Julia’s OOP is superior precisely because it’s not COP. If I am allowed to say that a `struct + methods = object` (and let’s not worry that an `object` is an instance of a `class`), in COP methods belong to a struct, whereas in Julia’s Method-Oriented version of OOP, the structs belong to the methods. Both are OOP. Both use a combination of methods and structs to describe behaviour of objects.

I ❤ Julia.

---

<div class="post-metadata">

**Author:** ![RogerP](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rogerp/32/17496_2.png) [@RogerP](https://discourse.julialang.org/u/RogerP)\
**Post date:** [December 31, 2020, 11:55pm UTC](https://discourse.julialang.org/t/is-julias-way-of-oop-superior-to-c-python-why-julia-doesnt-use-class-based-oop/52058/147 "2020-12-31T23:55:00Z")

</div>

Oh and Happy New Year everybody! 🥂

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 1, 2021, 6:20am UTC](https://discourse.julialang.org/t/is-julias-way-of-oop-superior-to-c-python-why-julia-doesnt-use-class-based-oop/52058/148 "2021-01-01T06:20:56Z")

</div>

> [@ChrisRackauckas](#):
>
> Both are sampling points according to a distribution, one is just implicitly defined and the other is explicitly defined.

Sure, but the signatures are so different that with the current design, it is very unlikely that one could use `sample` in generic code, like `+`. Which is what you would expect, as StatsBase’s is `sample` methods are low-level utility functions, while in Turing they are part of the high-level API.

Note that I don’t indend to single out Turing here — other packages do similar things, and I have done this myself. The idea that recycling a symbol for a completely different, non-conflicting signature [may not be a good design for Julia](https://discourse.julialang.org/t/function-name-conflict-adl-function-merging/10335/) evolved with practice and I think is a good principle to follow.

---

<div class="post-metadata">

**Author:** ![vedasulo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vedasulo/32/20324_2.png) [@vedasulo](https://discourse.julialang.org/u/vedasulo)\
**Post date:** [January 1, 2021, 8:27am UTC](https://discourse.julialang.org/t/is-julias-way-of-oop-superior-to-c-python-why-julia-doesnt-use-class-based-oop/52058/149 "2021-01-01T08:27:56Z")

</div>

🙂 I loved the syntax as easy as possible. Also I was quite learning about Meta programming and things, also found in `lisp` and like computerphile telling why was its popular language.  
I was quite surprised the power of Metaprogramming , data as code and things and also easy to write and know things.  
Only hurdle is , How fast is industries adopting julia knowing these powerful things?

---

<div class="post-metadata">

**Author:** ![kumarbalachandran](https://avatars.discourse-cdn.com/v4/letter/k/9f8e36/32.png) [@kumarbalachandran](https://discourse.julialang.org/u/kumarbalachandran)\
**Post date:** [October 11, 2021, 6:16am UTC](https://discourse.julialang.org/t/is-julias-way-of-oop-superior-to-c-python-why-julia-doesnt-use-class-based-oop/52058/150 "2021-10-11T06:16:44Z")

</div>

Quite similar to Call/CC in scheme. I could program it like a champ for the one simple example everyone likes to talk about, but after that you are left in the dust wondering how you get adept enough to speak it. And marvel and curse the folks who could. And then you have this epiphany that the whole thing was a scheme (pun intended) to confuse the heck out of you and you should never have bothered with it in the first place.

But there was this quirk in the RISC processor Sun Microsystems used that had this way to optimize tail calls by popping the stack all at once. It was very useful for recursion.

[Previous page](https://discourse.julialang.org/t/is-julias-way-of-oop-superior-to-c-python-why-julia-doesnt-use-class-based-oop/52058.md?page=7)
