My coding problem would be trying to follow the simple rule : less code is better.
This would make me try to squeeze way too much into a single line, everything in a single file.
You can imagine that more compressed does not necessarily mean less code but it certainly means less readable and less reusable.
I am trying to cure myself of this disease but there's certainly no quick way.
Keep telling yourself that readability is key, not compactness. Eventually your brain will re-learn.
Create a set of strict and exact rules you try to keep. F.i. two of mine are that classes declarations should have three blank lines between them and there is always two linefeeds above a scope keyword and one below.
class Example1
{
private:
void method1();
void method2();
void method3();
void method4();
public:
void method5();
void method6();
void method7();
};
class Example2
{
};
class Example3
{
};
Also, while not as quantifiable, try to enforce that only things logically belonging together should not have linefeeds between lines.
void Function()
{
DoTypeAThing_step1();
DoTypeAThing_step2();
DoTypeAThing_step3();
DoTypeBThing_step1();
DoTypeBThing_step2();
}
Try to keep things only of the same level of abstraction/granularity in the same function. This will mean you will start to compose more functions. This is OK, and good.
void BadFunction()
{
MakeBreakfast();
SeasonPancakes();
for (Food::iterator i = food.begin(); i != food.end(); ++i)
{
if (!i->tooHot())
i->eat();
}
}
void GoodFunction()
{
MakeBreakfast();
SeasonPancakes();
EatFood();
}
These rules introduced strictness, space and logical structure to your code and helps enormously with readability.