How many lines of code is too many for the computer to handle?

I know different functions take different amounts of processing power, but I was wondering, how many lines of code is too many? Is it okay to create a game with a planned 4,000-6,000 lines of code?

It’s not about the pure amount of lines of code. You can use very different approaches for one goal, one might be better, one might be less good. Searching for 1500 gameObjects each frame with Find() requires little more than 3 lines of code, but will definitely make your game unplayable. It’s more about code design, maintainability and so on, so there definitely is no rule about how many lines of code you should implement.

Aside from running out of RAM, but that would require, what, hundreds of millions of lines? :wink:

–Eric

Let’s just assume the majority of Unity developers don’t have an army of chimps in their basement doing all the coding with the main goal of crashing the RAM by putting in lines of code. :wink:

Nah, you could do it yourself with copy/paste. And just think how fast you could make it when you guarantee that all loops are completely unrolled!

–Eric

Mm… Careful here. It’s important to note that all lines are not equal. For example, a coder who writes:

if(condition)
{
    DoSomething();
}

can get 3-4 times as many lines of code in as someone who writes:

if(condition) DoSomething();

As Glockenbeat said, some lines of code may be doing some very performance heavy stuff…

For Instance, I’m sure these two lines would crash your game

for(int i = 0; i <= long.MaxValue ; i++)
    Instantiate(someGameObject, somePosition, Quaternion.identity);

Also keep in mind that function calls, may contain several more lines that you didn’t write, with the code branching out.

Funny. A single line can stop any computer.

Question to anyone: What’s the maximum number of lines of code you’ve implemented?

60-80,000

There is of course thousands more lines of code which you can’t see from libraries and unity, os, etc. Quit fooling around with what doesn’t matter and just carry on making games.

I have a library I have written over the years which is 80,000+. Link Here
And this library only provides a very small feature of an application, taking into account everything else the number of lines can easily be into millions if you count all the third party libraries used.

I would not worry about the performance hit from lines, a single texture will take as much if not more RAM than your code.

Generally long code doesn’t mean that your program is awesome, in most cases it means the opposite. What I would get from it, is that you’re not reusing code and not following object oriented principles.
If you have classes that are over 500 lines of code, it probably has more than one responsibility and you can break it up into more classes. Just a rule of thumb, I’m not saying this is always the case…

guess u can make on line of “fork” code to make unity crash.
or a billion line of other code, that runs smoth.
it all depends of how often each line is called by the program. and what calculations the code does

at first because i been coding for a while i found the question absurd now you actually have a good question do, i never though about it, but yes in reality it would be how things are coded lol, and on the other hand i don’t think i can repeat a line of code because technically if i say one line inside the update and try to repeat it it should play the same because it would be excecuting the line by frame when using the update function.

Because it would teach you why number of lines isn’t important :smile:

Software I work on has over 4 million.

its a cu** to remember where stuff is.

5 234 552 exactly.

What are you working on?

while (true);

Gah!!! I wrote the 5,234,553rd line just now! What do I do!!!

–Eric