Should i keep my if statements in a single line?

should i keep my if statements in a single line?

doing this does reduce the amount of lines of code drastically, but for the trade off of being harder to understand what the code does, and the length is quite long

and for my if statements compares conditionals, i basically made the condition to the exact opposite
like > would be <= and then return

here’s my code

	local function addPlayer(Player)
		local addPlayer = table.find(partyPlayersList,Player)
		if addPlayer or #partyPlayersList >= maxPlayers then return end --if player not in part or if party is less than max players
		table.insert(partyPlayersList,Player)
		updatePlayer()
		if #partyPlayersList < minPlayers or timerConnect.Connected then return end --if party is greater or equal to min players or the timer isn't running
		debounce = time() timerConnect = RunService.Heartbeat:Connect(timer)
	end

	local function removePlayer(Player)
		local removePlayer = table.find(partyPlayersList, Player)
		table.remove(partyPlayersList, removePlayer)
		updatePlayer()
		if #partyPlayersList >= minPlayers then return end --if party is less than min players
		timerConnect:Disconnect()
		teleporter:SetAttribute("Time", timerValue)
		updateTimer()
	end

here my code originally before i changed it

	local function addPlayer(Player)
		local addPlayer = table.find(partyPlayersList,Player)
		if addPlayer then return end
		if #partyPlayersList < maxPlayers then
			table.insert(partyPlayersList,Player)
			updatePlayer()
			if #partyPlayersList >= minPlayers then
				if timerConnect.Connected then return end
				debounce = time() timerConnect = RunService.Heartbeat:Connect(timer)
			end
		end
	end

	local function removePlayer(Player)
		local removePlayer = table.find(partyPlayersList, Player)
		if not removePlayer then return end
		table.remove(partyPlayersList, removePlayer)
		updatePlayer()
		if #partyPlayersList < minPlayers then
			timerConnect:Disconnect()
			teleporter:SetAttribute("Time", timerValue)
			updateTimer()
		end
	end

does it event matter? or not?

It has no effect on the script itself or performance as compiled language will drop all that formatting anyways. The only time I personally one-line statements like that is for assertions like you’re doing with if addPlayer then return end
Since it’s just hopping out of the function if those conditions are met I generally one-line it and put it at the very beginning of the function blocked together + away from further logic.
debounce = time() timerConnect = RunService.Heartbeat:Connect(timer)
this line I don’t like as those are dissimilar statements and blend together when skimming code.
Debugging can get annoying if you get an error on a line where a lot of stuff is piled together.

1 Like