Re: [PATCH RFC 1/3] NFQUEUE: introduce CPU fanout

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tuesday 2013-03-19 22:34, Holger Eitzenberger wrote:

>> http://www.braceless.org/Various/The%20Else%20Statement%20Considered%20Harmful
>> 
>> Something like
>> 
>> +static unsigned int
>> +nfqueue_tg_v3(struct sk_buff *skb, const struct xt_action_param *par)
>> +{
>> +	const struct xt_NFQ_info_v3 *info = par->targinfo;
>> +	u32 queue = info->queuenum;
>> +
>> +	if (info->queues_total == 1)
>> +		return NF_QUEUE_NR(queue);
>> ...
>> +}
>
>having read through the webpage - and using 'goto' for error handling
>in own code quite often - I don't see why your code above should be
>more readable.

It was only coincidental that the webpage also mentioned goto.
The general idea (and google keywords) was called something like
"Else Considered Harmful", and the lesson consisted of early
exclusion of simple cases from the flow of the remainder of the
function. Perhaps to illustrate it better:

	list_for_each_entry(thing, &yourlist, anchor) {
		if (thing->property == MAGIC) {
			do_stuff;
		}
	}

=>

	list_for_each_entry(thing, &yourlist, anchor) {
		if (thing->property != MAGIC)
			continue;
		do_stuff;
	}

Code may become more readable as one gains one level of indent and
have some more freedom in arranging the giblets inside the do_stuff parts.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux