Is OOP in Luau Actually a Bad Practice?

I’ve been working with Lua for a while now, and I keep running into this debate: Is using OOP in Lua considered bad practice?

I see a lot of conflicting opinions in the community, and I’m trying to figure out the right approach for my projects.

Lua doesn’t have native OOP support. Unlike languages with built-in classes, we have to implement OOP using metatables and table manipulation. This feels like we’re forcing a paradigm onto a language that wasn’t designed for it. Some specific issues I’m worried about:

  • Performance: Does the metatable lookup chain create significant overhead?
  • Memory usage: Am I wasting memory by giving each instance metatable references?
  • Complexity: Am I overengineering solutions by building class systems when simpler approaches exist?

But I Also See Benefits

On the other hand, for larger projects, OOP seems to provide:

  • Better organization and encapsulation
  • Clear interfaces and responsibilities
  • Code reuse through inheritance or composition
  • Natural modeling of game entities (players, enemies, items, etc.)

Many problems just feel object-oriented. Game entities, UI components, state machines—these seem to map naturally to OOP patterns.

My Questions

  1. Is OOP in Lua generally considered bad practice, or is it just a matter of when and how you use it?
  2. What are the actual performance implications? Are we talking negligible overhead or something that matters in production?
  3. When should I use OOP vs other paradigms in Lua? Are there clear guidelines or is it purely subjective?
6 Likes

I don’t really engage in this discussion, but personally I try not to use OOP as much as possible out of pure preference, mostly due to..

Here’s a good read (devforum post) on the topic though, could give you a lot of insight. It’s kinda neutral (discusses what you can gain beyond OOP), ending off with a heavy emphasis on considering what you’re willing to gain and lose.

3 Likes
uhm...


I’ll just assume you did this to get a more concise post.

please note this is mostly relevant to metatable OOP
To put it bluntly - it brings more drawbacks than benefits.

Yes. Compared to standard lookups, there is a lot of overhead within metatable lookups. This can be seen in the Luau source code, along any table read path - compared to a single path involving luaH_get and variants, there is a very long winded path for metatable searches when compared.

Tables are referenced in Luau, so it should not be that bad as they are not cloned. The table itself is quite a large structure though, especially if you include the pointed array part and node structures.

Quite possibly, though it does really depend on what it is you are trying to build. It’s always good to plan any program before you even open the text editor - it gives you a clear idea of what you need, and how you can do it - it’s really good for preventing over-engineering.


Many, if not all of these, are completely doable using other paradigms which are more efficient in Luau, an example being Entity Component Systems (ECS). The end result is often cleaner and more performant than if it was done with OOP.

Readable and performant code is always possible. It’s good to keep that in mind.

3 Likes

It sure is hard to debug.. Once everything is that way it better be set in stone.

2 Likes

people only use OOP to organize

but OOP is not for Luau, metatables cause lag, use ECS instead

Yes, it does add a bit of overhead, though usually not very significant, 10,000 calls only adds a few microseconds.

It’s strongly recommended to avoid deep index chains and index functions however.

For this to be effective, it’s crucial that __index in a metatable points to a table directly. For performance reasons it’s strongly recommended to avoid __index functions as well as deep __index chains; an ideal object in Luau is a table with a metatable that points to itself through __index .
From: How we make Luau fast | Luau

Typically, metatables save on a bit of memory when you’re creating objects that have shared methods, not much but not negligible if you create many objects. I wouldn’t use this as a primary reason to use OOP though.

It heavily matters when and how you use it, unfortunately many people fall into the trap of shoving OOP into everything for the sake of it.

It depends when and how much you use it, if it’s something like a car then sure it might be more readable that way, but don’t use it in useless places.. cough roblox’s movement and camera modules cough

and if you’ll use it, it’s better to have it JUST a table and store all the functions and properties in it instead of using metatables

(btw OOP is not a real thing in lua and luau)

also, is this post AI?

2 Likes

OOP is very useful, some systems require it to work properly.

Don’t use OOP all of the time, but don’t try and avoid it. In my opinion the benefits outweigh the downsides.

There is a select group of ECS programmers who consistently whine about OOP usage, and there is a select group of OOP users who whine about ECS, don’t listen to either of these groups.

In my opinion, it is best to use a combination of OOP and ECS depending on what you want to accomplish.

2 Likes

The default Roblox PlayerModule is bad in many ways, the pointless use of OOP for singletons is one thing, the CameraModule returning an empty table instead of its singleton (thus ruining the whole modularity point) is another.

2 Likes

what about the pointless amount of calculations and functions? Fun fact: The movement manager (player:Move()) has a second parameter for the movement being camera “based”, which is uselessly calculated in roblox’s top tier module..

when you require multiple objects to store their inner state and carry it with them - you use OOP
when you require multiple objects to be processed in a similar way - you call functions on them
when you require your whole infrastructure to be parameterized with content unknown in compile time - you use dependency injection

you need OOP when:

  • objects are release-and-forget with different state outcomes for each
  • your program benefits from local states

you use functions when:

  • all objects must be processed with a predictable outcome
  • your program benefits from a global state

those are very different structural paradigms

development without OOP is expensive for large systems, with debugging being even more expensive; development of small systems doesn’t require OOP at all; multithreaded environments benefit from OOP, single-threaded suffer from overhead

2 Likes

yeah, i used AI cuz my english sucks lol

1 Like

IA​:fire::fire::fire::fire::fire::fire:

No paradigm is inherently bad practice. Problems usually come from applying a paradigm inappropriately or using it incorrectly. While Luau doesn’t have native or classical OOP, that doesn’t make OOP-style patterns inherently bad, it just means they should be used selectively and in a way that fits the language’s semantics and constraints.

How to avoid misuse of OOP in Luau:
Under any circumstances, do not create subclasses.
Do not create thousands of objects → switch to ECS
Avoid metatables if possible. objectHandler.destroy(object) instead ofobject:destroy()

Anyone who tells you that OOP entirely in luau is bad is a script kiddie who will not be able to reason, because they glaze someone else’s opinion with no understanding why.

Don’t use ECS and OOP where not needed, it’s really easy to have ECS as overkill

Here is road of complexity and scale:
OOP → DOD → ECS
Use OOP for smallest things, DOD for bigger scale, and ECS when game has hundreds of entities, projectiles, etc.

if i wanna code a combat system, should i use ECS, OOP or another method for a better performance??

ECS is an overkill, doesn’t really have todo anything with entities, OOP can be fine in this situation.

2 Likes

everything depends on the context and how its implemented.

you don’t need rust for a scraper
you don’t need oop for a basic obby

And why are you spreading lies buddy?
Each object having it’s own methods is extremely expensive, imagine having 100 objects with the same method destroy that gets called on self? Pure memory waste

__index lookup might be slower cause it has to look in the object and the class itself, but at least this doesn’t cost memory.

Your solution is only applicable to singletons, but even at that point you’d hardcore the object and not construct it (assuming it’s not public package)

I don’t even know why your post is marked as a solution, this is probably the worst reply in this thread

1 Like

did I say to copy the methods?
You can just add the functions by doing

Function = AlreadyExistingFunction

and use self, wow!

OOP is a terrible practice in Luau.
https://devforum.roblox.com/t/%CE%B4-the-lost-art-of-optimization-what-do-we-gain-when-we-drop-oops-training-wheels/4123198/1
It is not a requirement for scaling. It is not a requirement for organization.

@Yarik_superpro Packgod humble him

2 Likes