Re: [dev] [sbase] style

From: Bobby Powers <bobbypowers_AT_gmail.com>
Date: Mon, 17 Nov 2014 14:10:49 -0800

Hello,

FRIGN wrote:
>> tests (boolean)
>> ===============
>> do not test against NULL explicitly (e.g. if (!p) instead of if (p == NULL))
>> do not test against 0 explicitly (e.g. if (!strcmp(p, q)) instead of
>> if (strcmp(p, q) == 0)) (discuss)
>
> Yes, yes, yes. See the patches I sent in a few days ago.

By default I read if (!functioncall()) as 'if the function call
failed'. I like the (strcmp(p, q) == 0) idiom because I don't fall
into the trap of reading the statement as 'if the string comparison
failed'. It is the one case I can think of where I prefer an explicit
comparison to zero.


>> early returns/exits
>> ===================
> I have no problem with goto. It often simplifies things dramatically
> and there's no reason to regulate it or punish its use.

Agreed - goto's for cleanup when there is local state or allocations
to roll back are a godsend - otherwise use an early return.

Everything else I agree with well enough.

yours,
Bobby
Received on Mon Nov 17 2014 - 23:10:49 CET

This archive was generated by hypermail 2.3.0 : Mon Nov 17 2014 - 23:12:09 CET