[chbot] return value or status from function

Jasper Mackenzie jasper.mackenzie at gmail.com
Wed Feb 10 06:54:45 GMT 2016


Thank you all for your input.
 I went for option 3 after all the advice.
Volker can you explain WHY to never return 1 as fail.
Usually I leave return type as uint8_t reserving 0 for success and any
positive number being a failure where the value is specific to the
function. So in this case failure is !0 8)

No much refactoring to do next holidays...

On 8 February 2016 at 17:55, Volker Kuhlmann <list0570 at paradise.net.nz>
wrote:

> On Fri 05 Feb 2016 19:09:06 NZDT +1300, Col wrote:
>
> > Return TRUE or FALSE to make code more structured and readable
> >
> > eg
> >
> > if( readSomePIN(...) )
> >       //process result
> > else
> >       //deal with error
>
> 1) Do not return TRUE or FALSE, return PASS or FAIL. (And
> define one as 0, and the other as !0 - never define as 1.)
>
> 2) If you need more than binary status, return error code enum (note:
> OK == 0 in this case) and make your function return type err_t:
>
> typedef enum {
>         E_OK,
>         E_WHATEVER
> } err_t;
>
> 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/20160210/18181438/attachment.html>


More information about the Chchrobotics mailing list