To create well-structured code you can’t do without a well-developed abstract mind. Remember the “pick an extra object” problem? Programming is largely based on this.
If you want to succeed in programming, you must be able to:
- Find patterns and dependencies, reflecting them in the code structure. Sure, you can write long and convoluted code that will solve a problem. But keep in mind that good code must also be maintainable, that is, it must be UNDERSTANDING, which is achieved by selecting clear logical structures, whose meaning is obvious without explanations (comments);
- to classify entities in the form of classes and modules with consistent interfaces. Choosing the wrong base class can lead to serious problems in the future. For example, in a game application the architecture can be structured in such a way that a different class is created for each game object;
- clearly separate the application by abstraction levels. Decide on the structure of the application. Use encapsulation as intended. In a well-organized application, you can’t have SQL code sampling from a database next to GUI code. Consider applying patterns (e.g., MVC);
- Define algorithms in the form of procedures and functions. Avoid side-effects and unnecessary dependencies that are potential bugs. Be guided by the principle of single responsibility.
A few tips to help you develop abstract thinking:
- Read books about object-oriented design and analysis. A good starting point is Object-Oriented Analysis and Design;
- Spend time studying standard architectural solutions. There is no point in wasting your time and effort on tasks for which you already know reliable solutions. I recommend reading the books: Design Patterns and Object Oriented Design Techniques;
- take an interest in the architectural solutions adopted in other people’s successful projects. Just knowing the patterns is not enough. You need to be able to combine them correctly and effectively. Incorrect use of patterns will only worsen the code structure in most cases. Learn from other people’s examples drawn from open-source projects and articles on their own creations by the authors themselves. I recommend the book Perfect Architecture. Leading experts on the beauty of software architectures;
- More Practice. You will only get a sense of confidence in software development if you have experience. Solve a variety of problems and strive to experiment.