Jump to content

OOP or procedural programming?


Recommended Posts

Hello everyone,

I'm sort of new to MTA scripting and thus a beginner to Lua. I have programmed in Java before where I prefered trying to stay on OOP. I just found out that it's also possible to do that in Lua, but it looks kind of confusing to me. Moreover, it's a feature that was introduced in MTA 1.4 which seems not too long ago.

That's why I want to ask you what kind of programming you would prefer? OOP or procedural programming?

Thank you in advance!

Link to comment
  • Moderators

In lua I somehow do not really like OOP to the max. It doesn't feel like how it works in JavaScript(always OOP).

So I prefer a mix depending on the situation, but consisted.

Edited by IIYAMA
  • Like 1
Link to comment

Let's take a MySQL script with function() _query as an example. If I follow the OOP approach, then it would be a little bit messy because then I would have to create a new MySQL object for each script which would result in multiple connections. So I don't know how I can use the functions of the MySQL script in other scripts without doing OOP.

Link to comment

Lua doesn't really like OOP and it can make it it pretty slow an example of this is on the wikipedia page.

--OOP
start = getTickCount()
a = 1
for i=1,1000000 do
   a = localPlayer.position
end
stop = getTickCount()
print("variable", stop - start ) -- Time Taken: 1500ms

--Structural
start = getTickCount()
b = nil
for i=1,1000000 do
   b = getElementPosition(localPlayer)
end
stop = getTickCount()
print("structural", stop - start ) -- Time Taken: 200ms

 

Edited by Crossy101
  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...