]>
git.saurik.com Git - wxWidgets.git/blob - docs/doxygen/strategies.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Strategies page of the Doxygen manual
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
12 @page strategies_page Programming strategies
14 This chapter is intended to list strategies that may be useful when
15 writing and debugging wxWidgets programs. If you have any good tips,
16 please submit them for inclusion here.
18 @li @ref reducingerrors
21 @li @ref debugstrategies
25 @section reducingerrors Strategies for reducing programming errors
27 @subsection useassert Use ASSERT
29 It is good practice to use ASSERT statements liberally, that check for conditions
30 that should or should not hold, and print out appropriate error messages.
32 These can be compiled out of a non-debugging version of wxWidgets
33 and your application. Using ASSERT is an example of `defensive programming':
34 it can alert you to problems later on.
36 See wxASSERT for more info.
38 @subsection usewxstring Use wxString in preference to character arrays
40 Using wxString can be much safer and more convenient than using wxChar *.
42 You can reduce the possibility of memory leaks substantially, and it is much more
43 convenient to use the overloaded operators than functions such as @c strcmp.
44 wxString won't add a significant overhead to your program; the overhead is compensated
45 for by easier manipulation (which means less code).
47 The same goes for other data types: use classes wherever possible.
51 @section portability Strategies for portability
53 @subsection usesizers Use sizers
55 Don't use absolute panel item positioning if you can avoid it. Different GUIs have
56 very differently sized panel items. Consider using the @ref sizer_overview instead.
58 @subsection useresources Use wxWidgets resource files
60 Use .xrc (wxWidgets resource files) where possible, because they can be easily changed
61 independently of source code. See the @ref xrc_overview for more info.
65 @section debugstrategies Strategies for debugging
67 @subsection positivethinking Positive thinking
69 It is common to blow up the problem in one's imagination, so that it seems to threaten
70 weeks, months or even years of work. The problem you face may seem insurmountable:
71 but almost never is. Once you have been programming for some time, you will be able
72 to remember similar incidents that threw you into the depths of despair. But
73 remember, you always solved the problem, somehow!
75 Perseverance is often the key, even though a seemingly trivial problem
76 can take an apparently inordinate amount of time to solve. In the end,
77 you will probably wonder why you worried so much. That's not to say it
78 isn't painful at the time. Try not to worry -- there are many more important
81 @subsection simplifyproblem Simplify the problem
83 Reduce the code exhibiting the problem to the smallest program possible
84 that exhibits the problem. If it is not possible to reduce a large and
85 complex program to a very small program, then try to ensure your code
86 doesn't hide the problem (you may have attempted to minimize the problem
87 in some way: but now you want to expose it).
89 With luck, you can add a small amount of code that causes the program
90 to go from functioning to non-functioning state. This should give a clue
91 to the problem. In some cases though, such as memory leaks or wrong
92 deallocation, this can still give totally spurious results!
94 @subsection usedebugger Use a debugger
96 This sounds like facetious advice, but it is surprising how often people
97 don't use a debugger. Often it is an overhead to install or learn how to
98 use a debugger, but it really is essential for anything but the most
101 @subsection uselogging Use logging functions
103 There is a variety of logging functions that you can use in your program:
104 see @ref logfunctions.
106 Using tracing statements may be more convenient than using the debugger
107 in some circumstances (such as when your debugger doesn't support a lot
108 of debugging code, or you wish to print a bunch of variables).
110 @subsection usedebuggingfacilities Use the wxWidgets debugging facilities
112 You can use wxDebugContext to check for
113 memory leaks and corrupt memory: in fact in debugging mode, wxWidgets will
114 automatically check for memory leaks at the end of the program if wxWidgets is suitably
115 configured. Depending on the operating system and compiler, more or less
116 specific information about the problem will be logged.
118 You should also use @ref debugmacros as part of a `defensive programming' strategy,
119 scattering wxASSERTs liberally to test for problems in your code as early as possible.
120 Forward thinking will save a surprising amount of time in the long run.
122 See the @ref debugging_overview for further information.