Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

If a script with 2000 lines was all put onto 1 line, would it run more efficiently?

So let me show a small example, if a code like this:

while true do
	print("hi")
	print("1")
	print("2")
	print("3")
	print("4")
	print("5")
	wait()
end

was put into a script like this:

while true do print("hi") print("1") print("2") print("3") print("4") print("5") wait() end

would it run more efficiently or make no change at all?

3 answers

No.

Programs must be written for people to read, and only incidentally for machines to execute

  • Abelson & Sussman

The representation of Lua as code that you write is for humans.

The first step the computer does in executing a script is scan the whole thing once, and turn it into bytecode which is extremely dense and computer readable. The first step, called lexing, breaks your code into words and eliminates space.

So there's absolutely not different in the output between the two.

Write your code for humans. Don't worry about "microoptimizations" like this. A) if they were real, the computer would probably do it for you. B) you're going to get more by making your code do less rather than do the same faster. Optimization comes from eliminating chunks of code, not tweaking names or other tiny things.

This wouldn't change at all! Although it would be easier to understand/read. If you did it in multiple lines. But that's my opinion :3.

This discussion is preserved as it was. New answers, comments, and votes are closed.