[chbot] C Coding Style

Charles Manning cdhmanning at gmail.com
Wed Sep 21 20:56:29 BST 2016


As a consultant I see a lot of different coding styles. Every different
group seems to have a preferred coding styles and thinks theirs is best.

IMHO coding style is about the least important thing about code. What is
more important is that it is easy to read and you can make a dog's
breakfast of any coding style.

Coding style is just something relatively trivial that is easy to argue
about and get outraged about. The more important things like design are
very much more abstract than coding style and are harder to quantify.

I use code-style insistence as a weathervane: the more people get uptight
about coding style, the less they understand about real code quality.

Get hold of GNU-indent and run your code through that with different
options until one strikes your fancy.

-- Charles



On Thu, Sep 22, 2016 at 12:04 AM, Volker Kuhlmann <list0570 at paradise.net.nz>
wrote:

> On Wed 21 Sep 2016 22:47:06 NZST +1200, Richard Jones wrote:
>
> > Offers anyone?
>
> There are as many opinions as there are C programmers...
> The main thing is to be consistent. Beyond that, take your personal
> pick. I always tell people if they expect the rest of the world to
> format to their personal preference they're going to be onto a loser,
> like when they have to read other peoples' code.
>
> By and large I like the Linux kernel style, it's verbose enough to be
> legible and doesn't waste screen real estate. Some people get hyper on
> this:
>   if (something == 45)
>   {
>     for (i = ...)
>     {
>       a += 5;
>     }
>   }
>   else
>   {
>     do something else;
>   }
> I find it idiotic. Lots of space for not doing much. The more of the
> code I can see at once the less time I have to flick around.
>
> The arduino one looks OK at a glance, but contains some nonsense too.
>
> If you want to get really serious, check what Jack Ganssle has to say
> about it.
>
> More practically speaking, I'd say stick to something you have a source
> formatter for, so you can reformat, fix up, and enforce. Basically there
> is astyle (command line and library), which offers a number of options,
> all with their tuning. It can be a little confusing because there's a
> difference between what it'll tolerate and what it'll forcefully change,
> and I found it not totally elaborate enough in some cases. It's
> integrated into codeblocks, a general purpose IDE that supports AVR (all
> FOSS). Worth a look, but I found the editor still sucks too much. The
> style formatter it good though (within astyle's limits). No reason to
> only use one editor for a project. I find all suck, just in different
> ways.
>
> The best formatter is in eclipse. The interface looks a bit like astyle
> but it must have its own.
>
> If there are other (Linux, not interested in MS whatsit studio)
> formatters I'd like to hear.
>
> HTH,
>
> 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/20160922/017d03dc/attachment.html>


More information about the Chchrobotics mailing list