Question

Maybe this answer already exists here, but I do not know if there is any technical term for that.

I'm starting to develop in C ++ and as the program grows in size, it gets harder to move through the source code.

However within the code there are several parts that are already 'solved', that is, I do not need to change them anymore, but they are there, in the middle of the source code, and I have to go through them all the time, which disturbs the concentration and often confuses.

For example, a simple "if" can occupy a whole screen (more or less 30 to 40 lines). I do not need to mess with it anymore, but it's not a function, it's not a class, just a part of the code that has to be there.

Some editors allow me to collapse the part of a code, for example the if, something I already do, sometimes it gets lost and the code reappears.

Maybe I cut the program into logical parts and put it in separate files, then inserting them into the main source code through an 'include', but that would be ugly ...

Anyway, I come here to ask: how to deal with large source codes in the best way?

Was it helpful?

Solution

For example, a simple "if" can occupy a whole screen (more or less 30 to 40 lines). I do not need to mess with it anymore, but it's not a function, it's not a class, just a part of the code that has to be there.

Have you heard of functions? They are these wonderful little guys that can stand in for piles of code that you're sick of looking at. Give the pile of code a name, stuff it in a function with that name, and then just call it by name. Now you don't have to collapse anything to hide these tedious but necessary details.

I bet you'll find them addicting. The more you use them the smaller they get until you have all these wonderfully tiny functions that hide all the boring stuff behind well thought out names that ensure that when you do bother to look inside them you find pretty much what you expected.

Licensed under: CC-BY-SA with attribution
scroll top