T
T
Toster_someone2019-07-02 18:53:59
Lua
Toster_someone, 2019-07-02 18:53:59

Which code option would be better?

I saw on the Internet two options for implementing OOP
First:

oop = {}
function oop:new()
  local oop = {}
  setmetatable(oop, self)
  self.__index = self; return oop
end
function oop:draw()
  --какой-нибудь код
end
function oop:update(dt)
  --какой-нибудь код
end
return oop

Second:
oop = {}
function oop.new()
  loсal oop = {
    update = function (self, dt)
      --какой-нибудь код
    end,
    draw = function (self)
      --какой-нибудь код
    end
  }
  return oop
end

And one thing is of interest, how it will be more correct and faster

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2019-07-02
@sim3x

more correctly
before writing code, write a test and see how it will be more convenient to use your code
faster
write a test to measure speed and compare

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question