Soo, OOP is powerfull tool, For example i can share the same functionality over many different objects/systems and simply write Module:DoSomething(), but my question is where i should use it? and where should i use functional programming? I have problem with telling when to use one or another
To clarify, OOP isn’t a tool, but a paradigm which is like a template to how to follow code through via certain imperatives.
Ik, simply organization following specific rules, but when should i use it over FP?
OOP is like, very good for organizing your modules. You can assign all the important instances to self and use them throughout the script anytime. While you should use OOP when your modules get complex or large (e.g. a Controls Module or a ToolbarModule), i personally use it all the time since so many other programming languages are built off of it and I just find it super convenient. My only complaint is that it a bit tedious to set up and fairly advanced (like srsly, module.__index = module
?).
In summary, use OOP when modules get complex and you need a quick and easy way to organize it.
I know what OOP is, but is there any advantage of using in specific situations, specific cases, than Functional Programming?
You can handle many instances and create a reusable code.
I know, but i want to know when to use it, in specific cases, for example for what kind of stuff, for what kind of games or systems inside them, i have dillema to choose OOP, FP or something inbetween
Look, for OOP you can handle more complex systems, however it’s not always necessary, for simple scripts you can use the traditional methods for scripting.
If you have a big game, you should go with OOP as it will let you organize your game better.
Soo, let’s say, for example framework should be made in OOP as you can expand it, but micro-modules or class’s functions should be made in mixed | FP way?
Precisely. Like i said above, use OOP for core stuff like movement and FP as a more general approach . EX:
-- Helicopter control module
local controls = {}
-- Set up the oop
function Forward()
return self.helseat.CFrame.LookVector
end
-- So on
FP:
function double(x)
return x*2
end
function UseDouble(double, list)
local result = {}
for _,v in ipairs(list) do
table.insert(result, double(v))
end
return result
end
print(UseDouble(double,{1,2,4,4})
Thats true.
dontmindthis
Thx, soo OOP for cores, and FP for it’s components, thx very much
A quick note:
I do feel FP is redundant because the function is global and be used regardless. Like in my FP ex above you could simply call the double function without needing it as a param. Like KingVamp said, traditional methods would be ideal over FP (not to say don’t use it, but consider it)
What is the difference between FP and traditional then?
-- Traditional
function Subber(str)
local r
for i = 1,len(str) do
r = string.sub(str,1,i)
end
return r
end
function Duck()
print(Subber('I am a duck')) -- In FP you would prob pass subber as a param
end
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.