Skip to main content
2 of 6
Add "More (kinda) trivial" section...
user avatar
user avatar

DRY

In create_win() there are two calls to XCreateWindow(), each having a long, long list of parameters.
Turns out, only one of the parameters is different.

While each branch of the if/else performs different preparatory work, please find a way to use a stack variable to distinguish root from *parent. (It feels like the datatype Window hides its nature; being a pointer. Hidden 'splats' are an anathema.) This could eliminate one instance of a monster function call.


Trivial

Many of the 2D token names are based on Height and Width, but then others use x and y (which refer to "width" and "height" respectively.) Note how the 'sequence' is subtly swapped.

Please stick to one convention. Perhaps int h = SOME_HEIGHT, w = SOME_WIDTH;.

Reduce the burden on the reader who is trying to determine which way is up in unfamiliar code.


Preprocessor macros or enums

The preprocessor is a wonderful "editing" tool, allowing tokens to be replaced by constants (and much more) before the compiler even sees the code.

The downside is that those tokens that can be read in source code are not available when debugging.

Suggestion:

 enum { POSX = 500, POSY = 500, WIDTH = 750, HEIGHT = 500, BORDER = 5, LINE = 4 }; 

These compile time token names are available within a debug build.


More (kinda) trivial

When working with code written/maintained by others, it's probably best to adapt to their conventions (as much as possible.)

// static Window create_win( // snake case static Window createWin( // camel case is, at least, half way to their standard 
user272752