# Object-oriented syntax in julia

**URL:** <https://discourse.julialang.org/t/object-oriented-syntax-in-julia/90017>\
**Category:** General Usage\
**Tags:** discussion\
**Created:** [November 10, 2022, 1:57am UTC](https://discourse.julialang.org/t/object-oriented-syntax-in-julia/90017 "2022-11-10T01:57:28Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![bgroenks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bgroenks/32/21784_2.png) [@bgroenks](https://discourse.julialang.org/u/bgroenks)\
**Post date:** [November 10, 2022, 1:36pm UTC](https://discourse.julialang.org/t/object-oriented-syntax-in-julia/90017/7 "2022-11-10T13:36:34Z")

</div>

Please also see [my answer](https://discourse.julialang.org/t/why-there-is-no-oop-object-oriented-programming-in-julia/86723/58) to a related discussion that came up somewhat recently.

Also see this [discussion on inheritance vs. composition](https://discourse.julialang.org/t/composition-and-inheritance-the-julian-way/11231/14).

But to summarize briefly, any inheritance structure can be restructured in terms of composition, and in many cases _should_ be, even in OOP languages. Inheritance often seems like a natural and intuitive way of structuring code but almost always creates problems in the long-run; in my experience, the most common anti-patterns are fragile base classes, subclass repetition, and god-types, all of which are typically rampant in inheritance-heavy code. Composition has its own pitfalls but is generally a much more scalable pattern and is also better for encapsulation.

As for the `obj.func()` syntax, no this will not happen. And I disagree that this is ever really a helpful way of writing code. There is simply no reason to arbitrarily group together functions and data like in OOP. It’s just not necessary and is rarely helpful (outside of maybe the convenience of tab-completion). Any time you have an “object” which you think of as _doing_ something, you could always alternatively think of it as an independent _action_ which is applied to that object. And this is, in fact, the better and more scalable way to think about it in most use cases, especially the scientific and mathematical ones for which Julia excels as a language.

---

_[View the full topic](https://discourse.julialang.org/t/object-oriented-syntax-in-julia/90017)._
