Is there an ideal, better way to organise scripts?
Is it recommended to create many name spaces, or not really?
I'm wondering because the way I'm scripting seems very untidy. I hav to search within each script for a while to find certain sections of code. I have lessened a lot of code by writing dynamic methods with parameters so they can be recycled over and over. But I really want any tips anyone has on keeping scripts nicely organised. Is it better to attach individual scripts to many objects, or better to save them as variables in one script?
Sorry Im full of questions like this. I just want to know an ideal and efficient way of creating scripts >.< Thanks!
asked May 28 '12 at 08:53 AM
To add to @whydoidoit answer:
Regions can be used every where in the script. They are completely ignored by the compiler but in good editors (I use only Visual Studio but MonoDevelop should support this as well) you can collapse the whole region and it just displays the text behind the region statement.
Also keep in mind that you can also collapse any function or class body. Regions can also be used inside a function to seperate parts of code.
When using regions, don't overuse them, this will make a search even more complicated. Use exact and descriptive region names. If you search for a piece of code and you don't know in which region you have to look, the names are bad choosen. Also you should check the color highlighting of regions / preprocessor tags. Use a very signalling color (I use plain cyan) so a collapsed region doesn't get lost between the lines.
Just in case you can't find where you can collapse a region / function / class, there is a "-" sign infront of the code line. When you collapse a section it turns into a "+" sign
A final note: endregion tags can also have additional text behind it. It isn't used somewhere, but for very long regions (or nested regions) it helps to have the same text on both the region and the endregion tag.
answered May 28 '12 at 11:19 AM
Ok, first of all if you are using MonoDevelop it has a search for symbol keyboard shortcut, CMD + . on Mac that lets you start to type a class name, a variable name, anything really and then it auto completes, fantastic way of navigating your solution if you can remember any part of the thing you want to go to. Go to definition when the cursor is over something and return from that with (Mac) CMD+D and CMD+SHIFT+D
Its down to style, but I use this method: