[chbot] C Coding Style

Charles Manning cdhmanning at gmail.com
Sun Sep 25 19:37:21 BST 2016


Here is a real example of why I dislike inflexible coding styles

Here is the same code written using a mix of coding styles (ie. breaking
the rules)

    for(i = 0; i < BYTES_PER_CHUNK; i++) {
        uint32_t bit = 1 << i;

        if (*p32_in & P32_L1IX) l1_out->am |= bit;
        if (*p32_in & P32_L1IY) l1_out->bs |= bit;
        if (*p32_in & P32_L1QX) l1_out->cm |= bit;
        if (*p32_in & P32_L1QY) l1_out->ds |= bit;
        if (*p32_in & P32_L2IX) l2_out->em |= bit;
        if (*p32_in & P32_L2IY) l2_out->fs |= bit;
        if (*p32_in & P32_L2QX) l2_out->gm |= bit;
        if (*p32_in & P32_L2QY) l2_out->hs |= bit;
    }


Here is the same code rewritten to make the coding style Gestapo happy:

    for(i = 0; i < BYTES_PER_CHUNK; i++) {
        uint32_t bit = 1 << i;

        if (*p32_in & P32_L1IX){
            l1_out->am |= bit;
        }
        if (*p32_in & P32_L1IY){
            l1_out->bs |= bit;
        }
        if (*p32_in & P32_L1QX){
            l1_out->cm |= bit;
        }
        if (*p32_in & P32_L1QY){
            l1_out->ds |= bit;
        }
        if (*p32_in & P32_L2IX){
            l2_out->em |= bit;
        }
        if (*p32_in & P32_L2IY){
            l2_out->fs |= bit;
        }
        if (*p32_in & P32_L2QX){
            l2_out->gm |= bit;
        }
        if (*p32_in & P32_L2QY){
            l2_out->hs |= bit;
        }
    }

Which is easier to read/understand?
Which is more likely to harbour bugs?

Unfortunately the important things like legibility are hard to measure
whereas more trivial things like tabs or where the braces are placed are
easy to measure.




On Sun, Sep 25, 2016 at 7:28 PM, Volker Kuhlmann <list0570 at paradise.net.nz>
wrote:

> On Sun 25 Sep 2016 13:49:50 NZDT +1300, Charles Manning wrote:
>
> > Does anyone have suggestions for an editor that stores differentiles" and
> > allows you to quickly move between "profiles" for different editing.
> >
> > For example, I tend to do quite a bit of stuff in the Linux kernel (or
> > associated code), so I like my editor set up that way (indent = tabs, not
> > spaces: tab width 8 spaces). But then I will likely also work on someone
> > else's codebase too where it is indent = 4 spaces, stored as spaces.
> >
> > First prize would be an editor that supports that with one click/key
> combo
> > and does require that you go change all the settings.
>
> nedit will do all that. All the editor settings can be changed from its
> macro code, so you collect up all the settings you want (easy, the
> integrated help is good) and bind it to a keyboard shortcut and/or
> menu entry.
>
> I said before that nedit has other issues, but I'm still looking for
> something better. All the KDE/gnome stuff sucks, and I'll put my flame
> suit on before saying that the GNU stuff (emacs, viXYZ) sucks even more.
>
> One big advantage of nedit is that it is an X11 editor that runs
> extremely well over ssh (forget KDE/gnome stuff) and only needs basic
> X11 libraries, so it doesn't fire up all the desktop stuff. And it's old
> style, so no being-smart rubbish turning into being-smartalec useless.
> What it shows you is what is in the file. File type? Type? What??
>
> Volker
>
> --
> Volker Kuhlmann
> http://volker.top.geek.nz/      Please do not CC list postings to me.
>
> _______________________________________________
> Chchrobotics mailing list Chchrobotics at lists.linuxnut.co.nz
> http://lists.ourshack.com/mailman/listinfo/chchrobotics
> Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> Meetings usually 3rd Monday each month. See http://kiwibots.org for
> venue, directions and dates.
> When replying, please edit your Subject line to reflect new subjects.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ourshack.com/pipermail/chchrobotics/attachments/20160926/23d0f706/attachment.html>


More information about the Chchrobotics mailing list