Usefull programming patterns?

I was programming my game when I noticed a large ammount of if statements plastered everywhere to check for conditions on my functions that step stuff every frame.

I would like to know any usefull programming patterns to write better code, so far I know OOP and State Machine

3 Likes

if a portion of code is repeated twice or more, create a local or module function for it.

Have appropriate names for instances/objects.

4 Likes

a lot of the time if you have a lot of if statements consider making a table for them and grabbing it out of there

1 Like

Many people find less nesting to be more readable. For example:

local c0: boolean;
local c1: boolean;

if c0 then
	--[[
		big code block
		
	]]
	
	if c1 then
		--[[
			another big code block
			
		]]
	end
end

can be written as:

local c0: boolean;
local c1: boolean;

if not c0 then return; end

--[[
	big code block
	
]]

if not c1 then return; end

--[[
	another big code block
	
]]
2 Likes

just to add on to this post in case anyone finds it in the future, Read this website, it is highly usefull, I am not joking

Game Programming Patterns

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.