Login  Register

Re: RS_Painter::toGui crashes

Posted by sand1024 on Mar 20, 2025; 11:58am
URL: https://forum.librecad.org/RS-Painter-toGui-crashes-tp5726734p5726743.html

The main point regarding rules I'd like to express - is that they are not a "silver bullet" or set in stone, requiring blind adherence.

Instead, it is important to consider their applicability to each specific situation. Any design pattern (such as RAII, singleton, etc.) should be used only when it makes sense and provides practical benefits.

For almost any rule, counterarguments exist, which makes finding the right balance between code readability, ease of maintenance, and performance essential. Trade-offs are always necessary.

For example, here are some illustrations:

NR.1: Don’t insist that all declarations must be at the top of a function – this can lead to repetitive code when accessing a variable’s value (e.g., foo()->bar() instead of creating a variable var = foo()->bar() and using var later).

NR.2: Don’t insist on having only one return statement in a function – this can make step-through debugging more difficult.

NR.5: Don’t use two-phase initialization – while this is generally a good practice, it may not be possible when an object needs to be created first and initialized later.

NR.7: Don’t make all data members protected – this is acceptable, but only if inheritance from the class is not needed. It works well if the class is not part of a library and can be modified. Protected getter/setter methods for private fields can also be used, but this may not always be necessary.

Design patterns and guidelines are beneficial, but blindly following them without considering their applicability to the situation is problematic if:

The pattern reduces code readability
It complicates maintenance and modification
It introduces unnecessary overhead
It negatively impacts performance

In all cases, the balance between priorities must be carefully considered. In some situations, readability may be the most important factor; in others, performance or minimizing overhead may take precedence.

So it's just a question of balance of priorities.