   how to keep track of long codes
  i often find myself becoming overwhelmed quickly when code starts extending 100 lines or so is there a nice way to chunk it up so to speak so i can just focus on code that i need to? i have tried making separate files each having a specific function in the program but it always seems to have tons of hangups when i copy and paste it together. but that's probably the programmers fault :P   
  I tend to have a class definition per header, and a class implementation per source file. Or lots of similar classes together.So for example, I have an InputSystem.h and InputSystem.cpp which defines an InputSystem class. If I had free functions to do with the input system, I would put them in there.However, for (my small-ish roguelike game) I have lots of different tile classes: Tile, FloorTile, OpenDoorTile, WallTile, etc. Each of these doesn't need much code. So I just have a Tile.h and a Tile.cpp file for all of them, rather than lots of files.If you're using an IDE, you can often minimize function blocks.Commenting stuff can help.Or use the find command to search for a specific function.And 100 lines is not long at all. :P;  when you get into programming bigger things it's hard to keep files under 100 lines. but instead of copy pasting, you should consider splitting your code up in to headers and source files. for better organizing and smaller files   ;  Comments, they're extremely useful for this reason when wanting to overlook certain sections of code.  It's not like the compiler notices them so it doesn't add any extra bulk to the program itself, and you can always go back and delete any over-commenting you do for this reason.I'm not sure which language you're coding in, but I know in Visual Studio's IDE it automatically allows for the retraction(- sign) and extention(+ sign) of sections of code, so that if you're not currently working on that section or have no need to change anything you can retract all the code in that section without having to scroll through it. Very helpful.   ;Quote:i have tried making separate files each having a specific function in the program but it always seems to have tons of hangups when i copy and paste it together.+1 to MorDuc on this one. Don't copy+paste! Programming languages are designed to be broken up into files. Maybe this will help?[rant]Quote:by Christopher Loyd...but I know in Visual Studio's IDE it automatically allows for the retraction(- sign) and extention(+ sign) of sections of codeI just wish it worked more like VIM's "fold" feature. VS never seems to choose the folds I'd hope for. (2005 is really bad, 2010 is a lot better at it but not great)[/rant]   ;Quote:Original post by Christopher Loyd I know in Visual Studio's IDE it automatically allows for the retraction(- sign) and extention(+ sign) of sections of code, so that if you're not currently working on that section or have no need to change anything you can retract all the code in that section without having to scroll through it. Very helpful.that sounds perfect think you could tell me how to do it :P;Quote:Original post by 10booheeQuote:Original post by Christopher Loyd I know in Visual Studio's IDE it automatically allows for the retraction(- sign) and extention(+ sign) of sections of code, so that if you're not currently working on that section or have no need to change anything you can retract all the code in that section without having to scroll through it. Very helpful.that sounds perfect think you could tell me how to do it :POpen up Visual Studio and write some code - a function, a class definition, whatever. When you finish, you'll see a little minus sign in a box next to the beginning of the chunk you just wrote. Click it and see what happens :)   ;  Personally, I think hiding blocks of code isn't very effective. Why? Because it's a lot of hassle and it's pretty easy to overlook hidden things. Also, you're basically simulating a table of contents, while any decent IDE or even advanced text editor can show you a list of functions and classes in a document - giving you a much faster and easier overview.Now, 100 lines isn't much. Even a 1000 lines can still be pretty manageable. Personally - and this depends a bit on the language - I'm trying to stay below 1000-1500 lines, anything beyond that is usually a sign of a class that's taking on too much responsibilities, or a file that contains too many different functions. Basically, a file should contain a single class or a small set of related functions. I store related classes and function in a separate folder - for example, a game of reasonable scale would have a math, rendering, sound, game-logic and utility folder, each containing perhaps some 5-15 files.Another point that may be relevant here is to separate data from functionality. I've seen this a couple of times in the beginners forum: text-based RPG's that consist of huge functions, containing lots of text, switch-cases and loops and all that. In the end, there's a lot of data and very little distinct (but frequently duplicated) functionality, so most of these projects could do with, say, 20% of the code and a couple of text-files for the data. So if you're writing huge functions, scan for patterns and turn them into smaller reusable functions, and try to separate data from code, so you can call a single function with 10 different data-sets rather than having 10 times the same code, just with different values.And indeed, don't copy-paste code (you don't want to fix the same bug in 10 different places - you will forget a couple of places eventually!) - but I think you meant moving code, not duplicating it, right? You will need to read up on how to properly organize code across multiple files in your language of choice, but that's part of the learning process. It shouldn't be too hard to find articles about this subject, but if you have any specific questions, feel free to ask. Make sure you give sufficient information though, such as what language you're using and what you've tried so far. You can also show us your code if you want more specific help. Good luck with it! :)   ;  The #region/#endregion directive thingies are infinitely useful for me in this regard. I've only used them in C#, so I don't know if they work in C++/whatever you're using.   ;Quote:Or use the find command to search for a specific function.VS also has a function/class browser dropdown at the top of the text window where you edit your files.  It shows you the current function/class you are in, and you can use it to jump right to a function, or just see an outline of what is in the file.[rant]Quote:Personally, I think hiding blocks of code isn't very effective. Why? Because it's a lot of hassle and it's pretty easy to overlook hidden things. Also, you're basically simulating a table of contents, while any decent IDE or even advanced text editor can show you a list of functions and classes in a document - giving you a much faster and easier overview.VS doesn't block up code well, it seems to only grab function heads.I'm quite used to Vim's blocking, that folds on every {} pair.  So you can open a function, and get an overview of what control blocks you have in there.  It makes it really simple to actually "scan for patterns and turn them into smaller reusable functions" as you put it. Because you can distinctly see the blocks that could be separated.Vim also has special colors for the fold, so they are hard to overlook. The VS colorings can do something similar. The default colors, however, don't stand out, and changing them doesn't "pop" quite the same due to how it folds up the {...} section.Quote:The #region/#endregion directive thingies are infinitely useful for me in this regard. I've only used them in C#, so I don't know if they work in C++/whatever you're using.I'll be blunt, I personally find that feature useless. I'd rather have an editor that can block up code on syntax, than have to place special markers that clutter up my code, just so I can fold it.[/rant]   