Learn generics.
It has improved my programs in many ways. Every programming language now offers generic containers like List<Type> or Dictionary<Type, key>
Organize your instances in containers and give each one a unique key that you can for exampe generate as a GUID.
When you want to do something with them you can simply iterate with a foreach loop or pick a single element via its key.
Organizing your data that way has many advantages over the usual for(int i=0, i<n, i++) method, the speed is also almost the same, and it is very easy to read. It's a bit like having your own database of objects.
Once you understand that stuff you can also deal a bit in polymorphism (it is related to generics), though I would not go overboard.
Don't create complicated inheritance hierarchies (a common beginners mistake). Inheritance is very helpful in ccertain situations but often is not needed. I have seen too many programs where the few interesting things were buried in endless casts, for no benefit.
The most important thing as a programmer is to develop a toolset of things that you can you use for everything you need. Not premade solutions or complicated shit like Java beans.
I mean simple stuff like string replace, or how to easily store data without using anything premade again (like using data binding in cointainers that stuff is usually way too complicated).
An example how I generate different versions of my output fles, without writing a whole program with lots of string constants.
I simply store a template in a file and variables in %VARIABLE%
Load the string from a file and use string replace on all instances of %VARIABLE% and then save the modified string.
So much easier than doing it in the program, when most of the work can already be done in a text editor.
Here an example how I generate a rather complex-looking LISP file
Template:
Code:
(defun %MNL_FUNCTION%(/ mms_local_Mode)
(setvar "modemacro" "Stift%PENCIL_ID% - %PENCIL_NAME%")
(setvar "USERS2" "(%MNL_FUNCTION%) ")
(setq mms_local_Mode (getenv "ModeDraw"))
(if (= mms_local_Mode "0")
(progn
(COMMAND "_-RUN" "Mms.PenObjs.New_PidSelScr" %PENCIL_ID%)
)
(progn
(mms_modeswitch_draw)
(if (= mms_global_result 1)
(COMMAND "_-RUN" "Mms.PenObjs.New_PidHdl" %PENCIL_ID% mms_global_newhandle)
)
)
)
)
And here how I modify it (simplified), with just a few lines of code
Code:
string text = readTemplate(path); //path is the prepared template
text = text.Replace("%PENCIL_ID%", pencil.Id);
text = text.Replace("%PENCIL_NAME%", pencil.Name);
text = text.Replace("%TB_NAME%", toolbar.Name);
...
writeFile(path2, text); // output file
extra methods like readTemplate(path), writeFile(path, text) must of course be coded separately but they are not difficult, and pretty universal.
Another tip is to use abstract class with static members that you can use like global variables.
Like
Code:
public abstract class Configuration
{
public static bool keyboardControl = true;
public static bool isDebug = true;
public static bool showToolTips = false;
public static bool optimizedDoubleBuffer = true;
}
or
public abstract class Program
{
public static Stopwatch Stopwatch = new Stopwatch();
public static ProgressBar ProgressBar = new ProgressBar();
}
The big advantage is that you can use
Configuration.keyboardControl
or Program.ProgressBar
from anywhere in the program without getting an instance of Configuration or Program.
Abstract classes have only 1 instance and can be accessed anytime in the program, just like a global variable.
The reason is it is very easy to come to despair over global variables in OOP. I have seen many programs who needed to pass instances of such basic classes around and it completely wrecked their code. You cannot make it global but the abstract scope does the trick. It's a breeze to use once you know what you would have to do otherwise (where can I get my instance of Configuration again .. complex code changes ensue)
Another example would be a sound library where every sound file is in such a scope, and can simply be called from anywhere.
Code:
public abstract class Sound
{
public static Sound beapSound = new Sound("beep.wav")
public static Sound clickSound = new Sound("click.wav")
}
Last tips, use Copy%Paste, STRG+H etc instead of typing whenever you can! Make all variables according to a schema and not confuse yourself.