Fixing Lua OOP

  Рет қаралды 29,305

sleitnick

sleitnick

Күн бұрын

Пікірлер: 135
@sleitnick1
@sleitnick1 Жыл бұрын
Clarification: I am proposing this methodology _instead of_ OOP. I am not saying that this is the "correct" OOP design (it's not).
@cirel0114
@cirel0114 Жыл бұрын
So what is use of metatables in oop, inheritance and just it?
@LastLevelStudios
@LastLevelStudios Жыл бұрын
Seems on the path towards data-oriented programming (DOP), other than the data still being mutable. DOP definitely has its place, and I think where there's a lot of sending across the wire, storing and reading, it makes total sense (i.e. online multiplayer games). That said, I do like the convenience of using self and calling methods on the object, it's sometimes annoying to keep passing it in as the first argument. I think you have to trade simplicity in one area to gain simplicity in another, which makes it a little more case-by-case for me. Some games and systems might involve tons of method calls on a particular object, but don't need to store the object or send it over the wire at all - in these cases the metatable setup can be really handy.
@workindad
@workindad 8 ай бұрын
I started learning OOP a couple of months ago and it's taken months for that click that happens in my mind so I can fully understand the concept. I was to understand that OOP was what advanced coders did in Roblox, am I wrong? If not, in which direction (coding style) should I learn about to progress further than my already understood functional programming style?
@Scudmaster11
@Scudmaster11 8 ай бұрын
Lua is kinda both oop and dop... it doesnt really matter how you do it... either way... im ganna program Lua in such a way it bahaves like OOP in parallel entiry procession
@Smurfis
@Smurfis 2 ай бұрын
Couldn’t you just create a function that returns the first name + last name and have that as the full name the whole point of being a programmer is to find the solution right? 4:03
@itsmeklc
@itsmeklc Жыл бұрын
you either die a fan of oop or live long enough to see yourself return to functional
@execute214
@execute214 Жыл бұрын
I lived long enough to see myself return to functional
@rumory
@rumory 11 ай бұрын
maybe the true oop was the variables we plugged in along the way
@r0lfu_
@r0lfu_ 9 ай бұрын
this is actually relatable, ive been programming oop for many years and recently i just started doing things without over complicating them for no reason. and most of the time functional is simpler without downsides
@okeanskiy
@okeanskiy Жыл бұрын
thank you. ive been an advocate of this for a few years now. the explicit nature makes it easier not only to read but to WRITE as well. no need to make some sort of middleman wrapper to get objects to work across the client/server boundary. works better with typed luau as well, the type system has an easier time when you separate the helper functions from the object type. i still call it 'object oriented' but i make it clear that there is a distinction between this and what the majority of developers are writing.
@KashTheKingYT
@KashTheKingYT Жыл бұрын
i agree, this method of oop is super underrated
@lazyboio.
@lazyboio. Жыл бұрын
this!
@ImUkoo
@ImUkoo Жыл бұрын
then why didn't u say anything? u have a KZbin Channel for a reason broski...
@okeanskiy
@okeanskiy Жыл бұрын
@@ImUkoo u know ur good when ppl mad u dont upload
@googoogaagaayt
@googoogaagaayt 9 ай бұрын
Can anyone tell me how you would do inheritance I want to adopt this obvious system
@MaximumADHD
@MaximumADHD Жыл бұрын
This take isn't wrong can respect not binding stuff to a metatable as long as there's strong typing to back it. What often makes this pattern convenient for me is that it allows for shorthand member function calls through `self`. I prefer an observer model where state can be reconstructed from a view shared by the server and client, rather than assuming tables being passed over the wire are safe and validated. I also see metatable binding as a contract that says the data was constructed and validated by a direct source. I guess I can see where it could be seen as redundant given how nice Luau's typechecker is now. Sometimes I just prefer `object:SomeMethod()` instead of `MaybeVeryLongClassName.SomeMethod(object)`
@crockpotdev
@crockpotdev Жыл бұрын
i agree.
@MonzterDEV
@MonzterDEV Жыл бұрын
The first time I’ve seen someone feel the same way about metatables as myself, I love it!!!
@umamidayo
@umamidayo Жыл бұрын
This is great. I've been exporting types for a couple of months after learning more about it, because it just doesn't really make sense for games to complicate their data with metatables. It just makes everything so much more readable and easier to work with, and I think this method is underrated.
@friedavi
@friedavi Жыл бұрын
Personally, I think of this method as the purest form of object oriented programming
@lockefair
@lockefair Жыл бұрын
At the end of the day, Lua(u) doesn't have built in classes so what we see used is just a popular OOP idiom that allows us to mimic that behaviour and assign functions to our objects. Like you alluded to towards the end, your approach is just plain old tables with some typing to add some structure around their use and then utility tables with functions that mutate the passed in tables data. Personally, I like to keep the environment and native libs in mind when developing within an ecosystem. Roblox uses the classic OOP idiom of having a class table with a constructor and destructor method and objects have state and logic associated with them so I like the idea of mimmicing that and mainting consistency. As others have mentioned in the comments, I also prefer being able to call methods on 'self'. There's nothing wrong with different approaches though, everything has its ups and downs and like you say, you can pass these tables over the network without losing any metatable association because you're not using any metatables.
@Ozzypig
@Ozzypig Жыл бұрын
Good video, sleitnick! Moving away from metatable usage or otherwise removing access to methods from the object certainly has its benefits, though I mainly see this as a workaround for bad tooling. Luau really should be able to "just handle" idiomatic Lua OOP patterns, including inheritance patterns. That, and there's really no robust serialization libraries available in the Roblox ecosystem - the best we have out of the box is just...well, JSON serialization, as mentioned. How this pattern could work with inheritance would be a good topic for a follow-up video, I think! Also, I propose the term POLT: plain-old Lua table - in the same spirit as POJO from Java. Just to move away form struct terminology as it is used in C/C#.
@solderet_wav
@solderet_wav Жыл бұрын
ah yes more knowledge to devour from one of the masters
@LeehamsonTheThird
@LeehamsonTheThird Жыл бұрын
I like this solution a lot and I think it is very convenient for when you're trying to pass data over the network. However, I also feel this idea just won't work in all situations as the larger a class is the more inconvenient this seems to use.
@Fezezen
@Fezezen Жыл бұрын
Before I learned about metatables and wrote Love2D games, this is how I did "objects" in Lua
@emilybendsspace
@emilybendsspace Жыл бұрын
The LocalScript change you make at 6:30, will work exactly as expected with your original metatable-equipped Person class that used self inside Person:GetFullName() :-) It seems to be that what you're advocating for here is using the single-dot syntax on either side of remote object passing, for consistency. Valid, but you lose class functionality like being able to have a class with operators (e.g. a custom math type with +, *, < etc.). For that, you need your original hack of re-assigning the metatable.
@emilybendsspace
@emilybendsspace Жыл бұрын
Also, with regard to what's serialized over a RemoteEvent passing, the metatable is kind of a red herring in this example. None of the member functions will be serialized and sent, metatable or not. This is why you still have to use the Person module to access the function like a static member function. This isn't really a Lua OOP problem, it's a Roblox-specific table serialization issue with anything that's held by reference.
@clipnoir
@clipnoir 9 ай бұрын
quite an elegant way of fixing the oop issue
@googoogaagaayt
@googoogaagaayt 9 ай бұрын
But how would you do inheritance?
@offandsphere6788
@offandsphere6788 8 ай бұрын
@@googoogaagaayt idk lol can't composition basically completely replace inheritance (albeit very messily sometimes)
@googoogaagaayt
@googoogaagaayt 8 ай бұрын
@@offandsphere6788 No it cant
@berendberend702
@berendberend702 5 ай бұрын
@@googoogaagaayt you would have to make some sort of function that makes an "object" inherit methods and properties
@jamesmann260
@jamesmann260 Жыл бұрын
Reminds me of struct's in C with functions you pass it into to change or read the state of the struct. It removes a lot of abstraction of hiding the methods with the data and instead focuses on the data inside the object instead of the object itself by making the methods modular. For most things this is appropriate, because most things don't involve complex data structures with specific requirements and unique actions that require a level of abstraction beyond the initial state. But even for that you can generally avoid metatable magic with closures and it basically does the same thing. Although I haven't worked with closures much in lua, so I'm unsure if there's any limitations to be aware of, but I know they're there and they work.
@sleitnick1
@sleitnick1 Жыл бұрын
Yes, using closures is another alternative that works great, especially if you want to maintain encapsulation with your data and behavior. Only downside is duplication of functions, but I believe a recent Luau update optimizes that a bit and reuses closure functions if it can.
@kingtaco1725
@kingtaco1725 Жыл бұрын
@@sleitnick1Closures re-use functions and constants even in vanilla lua. The only thing that gets duplicated is upvalues.
@freddie224
@freddie224 4 ай бұрын
This has many hidden benefits. First, you will get accurate suggestions! No more typing the names of variables by hand. Second, it's way cleaner to build the objects this way. You don't have to input in 100 argument in the constructor function. It also makes simulating private methods more intuitive. And, you also get rid of the boilerplate you often get with metatable OOP. On top of that, you're also saving memory. I really like this method. I recommend everybody to use it!
@homelessdorito2263
@homelessdorito2263 Жыл бұрын
What about having events in your proposed solution, like Person.NameChanged? Do you think a different approach should be used for events? I'm interested in hearing your thoughts on that.
@mr_griffolukegriffiths9166
@mr_griffolukegriffiths9166 Жыл бұрын
I am not sure I am 100% sold on the idea, but still a big thumbs up for the video. Has certainly given a lot of food for thought. not sure why this video has taken so long to fall into my feed lol but hey better late than never i guess😅
@cirel0114
@cirel0114 Жыл бұрын
So whats the point of using metatables for oop?
@opstube
@opstube 7 ай бұрын
lookup metatable functions, there are plenty of useful things outside this basic "People" example. the extra line with setmetatable he showed first, is much better and a very clean way, instead of not using a core concept of the language. stuff like "Vector.add(a, b)" instead of "a+b" and "people.people" etc, throughout your entire project, ... vs that one line? :-)
@boonytoons7968
@boonytoons7968 2 ай бұрын
I have no idea what i am talking about, nor do i know how any of this actually works. BUT I really like these changes because it reminds me more of Golang. I love how golang uses structs and methods on those structs.
@rybakostis
@rybakostis 5 ай бұрын
So, you have basically implemented Anemic Domain Model. It isn't bad, but you have to be aware of its cons, like a poor cohesion, maintainability, testability and increased complexity. It will work fine for your use case, but if you have more complex model, like multiple types of Person, then you'd have hard time managing it all.
@Jaysinxe_
@Jaysinxe_ 7 ай бұрын
I’ve come to this conclusion as well. It lowers code complexity and as seen in the video is compatible with serialization. Great vid!
@googoogaagaayt
@googoogaagaayt 9 ай бұрын
How would you do inheritance?
@Spez_art
@Spez_art 9 ай бұрын
You can't, he's literally wrong, lmao I legit think he's confused about how metatables work. He says he's been using his method for 8 years. It feels like he took one look at metatamethods years ago, couldn't understand who's controlling who, and just refused to learn how they work.
@JandAVideoGames
@JandAVideoGames Ай бұрын
I used to code oop like this before i knew about metatables lol
@DriftHyena
@DriftHyena 10 ай бұрын
I'm in the process of writing a helper module script to serialize and deserialize OOP tables. You'll just have to register the class table with a name in the serializer's registry, and then it'll insert detected functions within the metatable, place them in a table called __methods, and the class name in __class. Then once the client or server receives the stripped out table, it can reconstruct it with the proper methods via the registry and helper methods.
@blendedphoenix
@blendedphoenix 9 ай бұрын
The only counter I have to this is, some patterning makes for very clear logic switching and explicit filtering. There is something to be said in the ease of it, but in my experience that ease leads to bad habits. Why not build a top level class of all your classes with a built in flatten class functionality, that can be overwritten to customize for that class? That can just easily be reconstituted. My biggest issue I've seen is that more often then not, devs don't have a root class that all other classes should be inheriting from. So that you can homonogize behavior better. just thoughts
@bubbybumble616
@bubbybumble616 Ай бұрын
Good idea, but how would inheritance work in this method?
@opstube
@opstube 7 ай бұрын
the first approach looks very intuitive and not hacky at all. would also change "OnReceivePerson(person)" to e.g. "OnReceivePerson(personData)" then it's clear the callback works with a serialized object, and you would expect setting metatable exactly at that point. having all that duplicate syntax not using self and ":" seems a huge drawback for that one additional line...
@Marisol-Channel
@Marisol-Channel Жыл бұрын
I'm guessing this should use composition over inheritance, since I can really not see how inheritance is good with this.
@wav8518
@wav8518 11 ай бұрын
HOW DID YOU DO THAT
@whupass
@whupass 5 ай бұрын
In summary, by using this approach you gain the benefits of: - Being able to send an object across the client-server boundary without having to set its metatable on the other side. At the expense of: - No longer being able to use functions with ":" notation. - Having to manually pass the table into each method. - Having to manually label all attributes in a table, as opposed to using a constructor, where you aren't prone to misspelling. Personally, I think this is a lot more "dirty" than using metatables, especially considering it's pretty bad practice to send more complex data structures in their entirety across the server-client boundary.
@pestik.
@pestik. Жыл бұрын
Me personally, i wouldn't use it for two reasons: 1. I like LUAU OOP the way it is, and the way everyone uses it, because it simplifies life a lot. 2. Replicating tables WITH FUNCTIONS, hell naah, i'll never replicate tables in my life. I'd rather do proper replication with the maximum of serialization that i can do.
@Tenandrobilgi
@Tenandrobilgi Жыл бұрын
"Fixing Lua OOP" *proceeds to change it from OOP to Functional* While this is a very good method for some projects, my OOP model heavily relies on metamethods so I can't really use this method. Still, a pretty good video.
@kam1034
@kam1034 9 ай бұрын
so the solution is to expose your module code to exploiters instead of figuring out how to interact with objects created on the other side of the client-server boundary
@xm_ani5597
@xm_ani5597 11 ай бұрын
Seems very useful, but can it be applied on real games? All of my OOP classes that I have on my server are there because they are specific to the server, and I have their client counterpart seperate from the server for the same reason
@savafilipovic8059
@savafilipovic8059 10 ай бұрын
True OOP makes sense if you are extending or implementing objects, if not (and I didn't see a lot of people do that in roblox) it doesn't make sense. To make this easier on me I make a base object class with extend, implement and some other useful methods already in it and I just extend the base object whenever I am doing OOP.
@extracub1974
@extracub1974 Жыл бұрын
Finally, I've always hated the metatable aspect of it. It just never seemed necessary to me
@remyxk
@remyxk 11 ай бұрын
I've never really understood metatables but I've always used them for OOP since I didn't know there was any other way. What even was the point of using metatables in the first place and why hasn't everyone been doing this all along?
@ftgodlygoose4718
@ftgodlygoose4718 9 ай бұрын
Because this way means that you are not working with any objects. It just depends on what you prefer.
@crockpotdev
@crockpotdev Жыл бұрын
what about situations where you don't want the client to access certain information?
@fables5091
@fables5091 Жыл бұрын
you can have guards in various utility functions to check for that.
@maxwell_edison
@maxwell_edison Жыл бұрын
Is that do/end for the player wait.. necessary? that's like... can you explain that one? That's the weirdest part about this whole code, while you have an extra do/end ...
@maxwell_edison
@maxwell_edison Жыл бұрын
Also is this not just how everyone does it? I've never used a meta table in my life, this is just.. normal module script and argument usage? Y'all fancy coders are funny. Making problems that don't exist just to solve them!
@sleitnick1
@sleitnick1 Жыл бұрын
Not necessary. A 'do end' is just a block of scoped code. I did it just so I could collapse the block and hide it
@Tenandrobilgi
@Tenandrobilgi Жыл бұрын
​@@maxwell_edison Not really. You should look up what OOP truly is and how it's done in Lua first.
@marcus0277
@marcus0277 11 ай бұрын
So, the title is misleading. You're not *Fixing Lua OOP*, you're removing the OO from Lua OOP. The point of this video should've focused on the fact that when an object is serialized, you're no longer working with an object... you're only working with its data. If you want to use that data on the client side as a Person, you need to create a new Person object using the serialized data. Based on this, your 'OnReceivePerson' function should've become 'OnReceivePersonData', and it might look something like this: local function OnReceivePersonData(pdata) person = Person.new(pdata.FirstName, pdata.LastName, pdata.Age) print("PERSON", person:getFullName()) end Now you've used your 'class constructor' so it's obvious that you're working with a Person object and you didn't have to directly modify your metatable in the OnReceive function.
@Ranakade
@Ranakade 5 ай бұрын
I dont use roblox at all, but this was still a super useful insight to Lua OOP in general. Thanks for this!
@over8087
@over8087 Жыл бұрын
You can still call GetFullName as a method, even if declared as a function
@williamhorn363
@williamhorn363 6 ай бұрын
The issue is, most people try to use OOP in situations where they just want to create a library for a specific thing. Maybe they even want individual instances of that library with an internal state. That's all fine, but that's not the purpose of OOP. If you are not using all of the fundamental concepts of OOP (encapsulation, abstraction, polymorphism, and inheritance), then you really have no business structuring your code as such.
@Vortex-qb2se
@Vortex-qb2se Жыл бұрын
Personally, I don't use either of these methods 😂 Never felt the need to use OOP is Roblox, maybe my projects were never complex enough, but I really don't see the benefits and it gives me headache.
@harryvpn1462
@harryvpn1462 8 ай бұрын
As a metatables hater, I laughed so hard when you showed that just doing functional programming us better
@planeman4453
@planeman4453 8 ай бұрын
Yes!! This is exactly what i needed to fix my game and i wasnt even purposely looking for this 😂. It's so frustrating with the normal oop approach that you lose your methods when sent to the client, which makes everything so much more complicated and ultimately makes oop useless for that scenario. How would you go about using inheritance though with this format?
@pepperdayjackpac4521
@pepperdayjackpac4521 8 ай бұрын
this doesn't really matter if you're not passing metatables across the network, no?
@dungusberryrocks
@dungusberryrocks 6 ай бұрын
wonderful video
@hellforag13
@hellforag13 Жыл бұрын
were waiting for the brush update (tree gen plugin)
@nleantnlant
@nleantnlant Жыл бұрын
While this is totally OK, its not OOP. For the examples you used it works totally fine, but when you get more in depth with OOP and use it for what its actually meant for this method is unreliable. Eg. Your making multiple AI's, you want them to function the same but each as their own object so they compute individually. You can still accomplish this with this method, but it is not as optimized.
@nizar7126
@nizar7126 4 ай бұрын
i dont think this is a good pattern anyways since you'd have to send a full on object with its methods as well a better way to do it ( + it also countradicts the self referencing function feature ) is to assign a user id for each person and only send that user id over the wire which is WAY MORE faster since you're only sending between 1 and 8 bytes ( since its a number ) of data and you dont have to send a copy of the constructor and methods of the table
@ftgodlygoose4718
@ftgodlygoose4718 9 ай бұрын
This is one of those things that boils down to preference. Pros and Cons on both sides so you just got to pick your poison because LuaU doesn't support real OOP. What actually SUCKS is inheritance. I'll die on the hill of composition, the only problem I have with it is the stack of calls needed to get the components.
@henriquebigolin2006
@henriquebigolin2006 5 ай бұрын
this looks more simple and natural, but anyway i mus know about metatables beacuse a lot of people use this way
@bigometer
@bigometer Жыл бұрын
This doesn't support proper inheritance right? In the child type you can include the parent type but you won't be able to inherit functions from the parent that aren't added in the child. Like if the parent had a function parent.printName(parent : Parent) and the child didn't implement that function, the only way to call that function from the child would be to use the parent class which may be inconvenient or just not a valid solution in some cases
@sleitnick1
@sleitnick1 Жыл бұрын
I cut out a lot from this video. One part I cut out was regarding inheritance. My take is that inheritance is a very bad part of OOP and should be avoided. You'll get into muddy waters with inheritance over time. For more info, look up info regarding "composition over inheritance" for a better approach.
@bigometer
@bigometer Жыл бұрын
K, I'll look into composition, thanks@@sleitnick1
@jamesmann260
@jamesmann260 Жыл бұрын
A solution could be to set the __index property of the metatable of the child utility functions to the parent functions. That way if and when it can't find child.printName(child: Child), it will automatically call the parent function of that name parent.printName(child: Parent | Child) instead. That's done under the hood though using metatable magic, so it might not be ideal. Also, it can make the code more confusing if you can't follow with your eyes where and what is being called. But for something simple like this it probably wouldn't be a big issue.
@baconfbi2142
@baconfbi2142 Жыл бұрын
One of the points of oop is to make sure you don't have to do exactly what you showed. With the way you presented it, you have to write person 2 times, which doesn't look very nice.
@sleitnick1
@sleitnick1 Жыл бұрын
That's kinda an illusion, since I was still using the 'Person' table to define list of behavior methods. But in reality, the whole point is to split the state and the behavior. The state can now live on its own. Then the developer can define various desired functions to act upon the data if so desired (which I did thru the Person table). These functions could exist anywhere. Also--for functional programming purposes--these functions can turn into pure functions that simply return new versions of the state if modifications are desired, which wouldn't be practical in OOP.
@finchasaurus
@finchasaurus Жыл бұрын
I thought people used both methods depending on situations...........
@officialjasonlamb
@officialjasonlamb 9 ай бұрын
Gonna entirely disagree with you. Sending raw data over the network is dangerous enough. Sending the means to manipulate that data is an absolute security nightmare. You're telling anyone who can sniff the data passing between the client and server precisely how to access an arbitrary location in memory. If you can ensure you have no buffer errors in your code, you probably would never need to worry about Lua's access to system functions. Otherwise you may as well have a giant neon arrow flashing "Attack Vector!" sitting right over that chunk of code. Your "hacky" method that "feels wrong", is right.
@boxingspace2984
@boxingspace2984 11 ай бұрын
"Sleitnick, your Knit framework has been a lifesaver for my Roblox Lua projects, and I'm truly grateful. On top of that, your KZbin content is gold! Your programming skills are exceptional, and you definitely deserve more subscribers. Here's to more success and growth for your channel! 🌈💻 #ThanksSleitnick #RobloxDev #SubscribeNow"
@CRT_YT
@CRT_YT 7 ай бұрын
dead internet theory
@boxingspace2984
@boxingspace2984 7 ай бұрын
@@CRT_YT 😂
@МаринаКраснова-н9д
@МаринаКраснова-н9д 9 ай бұрын
Hah, you did not fix Lua OOP, hou just stop to use it. I expect you will propose someething like copying all prototypes fiels to derived object on creation, but no...
@kokobroxd
@kokobroxd 10 ай бұрын
not sure why you would send oop over the wire
@Spez_art
@Spez_art 9 ай бұрын
It's not necessarily that you're sending objects over the wire, but say you're playing an RPG... A wizard player wants to summon something, like a zombie. You run the code to create the zombie on the client, then pass all the info related to the zombie to the server in one big chunk; a table containing its name, health, position, current action, etc. The server doesn't want to do anything with the zombie, because there might be tons of similar NPC objects all running code and slowing down the server, so it just sends that info to the other clients. That info may also contain code associated with the object itself, which doesn't get sent over the wire, which is why it needs to be set to another metatable in order to work. This guy seriously misunderstands the self keyword and the difference between .functions and :functions and how to use metamethods, which is why he claims it "feels dirty" Setting up a metatable using info sent over the wire essentially just changes that info from read-only to a more active format. I'm really not sure what this guy's issue is lmao
@kokobroxd
@kokobroxd 5 ай бұрын
@@Spez_art the example you gave is pretty bad... sending health of anything directly to the server is very vulnerable to exploits, and it would be a pain in the ass to make every client update the server how much damage they wanna deal to the zombie (if it was a pvp game of some sorts). even if you were to sanity check what the client sent, you would be better off just creating the objects on the server.
@mogaming163
@mogaming163 Жыл бұрын
Learning time!!
@danielphillips3156
@danielphillips3156 Жыл бұрын
I need to sit down and think
@KelvenOne
@KelvenOne Жыл бұрын
Isn't that data oriented programming?
@pokruk0
@pokruk0 Жыл бұрын
Guy just completely forgot about inheritance lol And btw, it's not really so often you need both sides be able to run methods of given class
@sleitnick1
@sleitnick1 Жыл бұрын
I cut that part out of the video, but I'm very against inheritance. Inheritance should not be used.
@nikos4677
@nikos4677 6 ай бұрын
​@@sleitnick1Yes its always a trap
@rodrigosimoes7103
@rodrigosimoes7103 Жыл бұрын
I feel personally attacked.
@joelb6456
@joelb6456 Жыл бұрын
local Person = {} Person.__index = Person export type Person = { FirstName: string, LastName: string, Age: number, } function Person.new(firstName: string, lastName: string, age: number) local person: Person = { FirstName = firstName, LastName = lastName, Age = age, } local self = setmetatable(person, Person) return self end function Person:GetFullName() return `{self.FirstName} {self.LastName}` end -- local constructorPerson = Person.new("John", "Doe", 30) local declaredPerson: Person = { FirstName = "Jane", LastName = "Doe", Age = 30, } print(constructorPerson:GetFullName(), "==", "John Doe") print(Person.GetFullName(declaredPerson), "==", "Jane Doe") setmetatable(declaredPerson, Person) print(declaredPerson:GetFullName(), "==", "Jane Doe") return Person
@xangelical3970
@xangelical3970 Жыл бұрын
So, it's like moving from C++ to C, from object-oriented to imperative. I'm all for it. 👍
@execute214
@execute214 Жыл бұрын
Object oriented is imperative
@pruzae
@pruzae Жыл бұрын
i love you
@0wQ
@0wQ 5 ай бұрын
yesss i hate when matatables are used that way :)
@thechosenone729
@thechosenone729 11 ай бұрын
I agree metatables are cancer anyway this is way better.
@Wurfeln
@Wurfeln Жыл бұрын
Niceeee....
@lolmanurfunny
@lolmanurfunny Жыл бұрын
Too many devs OOP too close to the sun.
@yarik_superpro
@yarik_superpro Жыл бұрын
I like this way of OOP becouse i hate metatebles kinda xD.
@Dimayuplay
@Dimayuplay 7 күн бұрын
#ihatemetatables
@MounirDevGaming
@MounirDevGaming Жыл бұрын
Coming from C# , Lua is not an object oriented language and this is just a joke not a real OOP .
@jamesmann260
@jamesmann260 Жыл бұрын
What is real OOP? Is it well defined? Is it simple encapsulation, or inheritance? If it looks like OOP, smells like OOP and tastes like OOP, is it still not OOP because it wasn't meant to be? Is OOP in the room with us? Will the real OOP please stand up?
@MounirDevGaming
@MounirDevGaming Жыл бұрын
learn c# and you will see the difference between a real programming language and lua crap @@jamesmann260
@Tenandrobilgi
@Tenandrobilgi Жыл бұрын
​@@jamesmann260Object Oriented Programming is basically a class system with objects created from it. This video Sleitnick made is not actually OOP, it's more like functional programming, where the Person's functions are pure.
@d0cteroof308
@d0cteroof308 Жыл бұрын
OOP is a paradigm, so you don't need to have a specific keywords that *help* you create an OOP structure. As long as the language can represent objects, usually through dictionaries or structures, they can utilise OOP.
@chibisayori20
@chibisayori20 Жыл бұрын
@@jamesmann260 i understood the reference
@honkhonk8009
@honkhonk8009 8 ай бұрын
BOOOORINGGGG Its roblox. Code like a noob and stop putting brainpower on how "readable" it is. Its infinitely more readable if you have it in the most basic coding style roblox intended you to have it as.
@windy6191
@windy6191 5 ай бұрын
bad advice
@Marisol-Channel
@Marisol-Channel 5 ай бұрын
Roblox RECOMMENDES their own style, however there's no reason everyone should follow it, especially when it's rather outdated.
@fitmotheyap
@fitmotheyap 3 ай бұрын
Better yet, write in the way most familiar to you.
@skaruts
@skaruts Жыл бұрын
I don't use Roblox, but this kinda seems like a Roblox problem that they ought to fix.
@SilverSuperGamer
@SilverSuperGamer 9 ай бұрын
I thought you were gonna do table.clone 💀 this is even worse
@miffclick3358
@miffclick3358 Жыл бұрын
roblox oop is a lie 😲😲
@miffclick3358
@miffclick3358 Жыл бұрын
time to abandon OOP 👎
What is Object Oriented Progamming?
13:27
GnomeCode
Рет қаралды 47 М.
Object Oriented Programming is Good | Prime Reacts
31:30
ThePrimeTime
Рет қаралды 331 М.
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 23 МЛН
This Is What 2 Years Of Scripting Looks Like
45:59
Ludius
Рет қаралды 35 М.
Why Is Lua So Popular?
8:03
Awesome
Рет қаралды 103 М.
Where Lua Is Actually Used
9:25
Tortellini Soup
Рет қаралды 23 М.
Andrew Kelley   Practical Data Oriented Design (DoD)
46:40
ChimiChanga
Рет қаралды 153 М.
Functional Programming Introduction
21:22
sleitnick
Рет қаралды 16 М.
Making a Game in Lua with No Experience
5:52
Goodgis
Рет қаралды 374 М.
Object-Oriented Programming in Roblox Studio!
23:12
Crusherfire
Рет қаралды 13 М.
STOP Using Classes In JavaScript | Prime Reacts
14:02
ThePrimeTime
Рет қаралды 258 М.
A Guide to BlenderAddonPackageTool
29:43
Xinyu ZHU
Рет қаралды 41