gtDMMB / RNAStructViz

Visualization, comparison, and analysis of RNA secondary structures via a cross-platform GUI
https://github.com/gtDMMB/RNAStructViz/wiki
GNU General Public License v3.0
17 stars 5 forks source link

Source code formatting: Should we run a ``make style`` operation on all the CPP/H files? #106

Open maxieds opened 2 years ago

maxieds commented 2 years ago

This topic drives me crazy every time I come back to this code! From platform to platform, terminal variant to terminal variant, and then even editor changes like vim on Linux back to MacVim on MacOS, the indentation in the source files ALWAYS gets mucked up. Case in point (from this file I just looked at to fix #105):

void DiagramWindow::drawWidgets(cairo_t *crDraw = NULL) {

    if(exportButton) { 
         exportButton->redraw();
    }
    if(m_cbShowTicks) { 
     m_cbShowTicks->redraw();
    }
    if(m_cbDrawBases) { 
     m_cbDrawBases->redraw();
    }
    if(baseColorPaletteImgBtn) {
     baseColorPaletteImgBtn->redraw();
    }
    if(baseColorPaletteChangeBtn) {
     baseColorPaletteChangeBtn->redraw();
    }
    for(int m = 0; m < 3; m++) {
        if(m_menus[m] != NULL && !m_menus[m]->active()) {
        m_menus[m]->redraw();
    }
    }
    if(crDraw != NULL) {
     cairo_save(crDraw);
     CairoColor_t::FromFLColorType(GUI_WINDOW_BGCOLOR).ApplyRGBAColor(crDraw);
     cairo_rectangle(crDraw, 0, 0, w(), h());
     cairo_fill(crDraw);
     cairo_restore(crDraw);
    }
/* ... REMAINDER OMITTED ... */

An option I am taking from the Chameleon Mini firmware is to create a make style target in our Makefile that makes all of this (and other configurable nit picky coding style habits) easy to update:

style:
        ## : Make sure astyle is installed
        @which astyle >/dev/null || ( echo "Please install 'astyle' package first" ; exit 1 )
        ## : Remove spaces & tabs at EOL, add LF at EOF if needed on *.c, *.h, Makefile
        find . \( -name "*.[ch]" -or -name "Makefile" \)                      \
            -exec perl -pi -e 's/[ \t]+$$//' {} \;                            \
            -exec sh -c "tail -c1 {} | xxd -p | tail -1 | grep -q -v 0a$$" \; \
            -exec sh -c "echo >> {}" \;
        ## : Apply astyle on *.c, *.h
        find . -name "*.[ch]" -exec astyle --formatted --mode=c --suffix=none \
            --indent=spaces=4 --indent-switches                               \
            --keep-one-line-blocks --max-instatement-indent=60                \
            --style=google --pad-oper --unpad-paren --pad-header              \
            --align-pointer=name {} \;

My only reservation is that the resulting commit post-style formatting operation will be large and involve most of the source files. Of course, this is reasonable because we are pushing the lines over by spaces everywhere. I thought I would get input before doing this: @ceheitsch Can you please weight in on the decision?