Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-dev: Re: [Wireshark-dev] Style question passing boolean parameters

From: Bill Meier <wmeier@xxxxxxxxxxx>
Date: Wed, 20 Jun 2012 11:46:00 -0400
On 6/20/2012 1:12 AM, Joerg Mayer wrote:
The following commit retriggered an allergic reaction to controlling function
behaviour via booleans:

         if (cf_save_packets(&cfile, file_name8->str, filetype, FALSE/*compressed */, FALSE/*discard_comments */, FALSE/* dont_reopen */) != CF_OK) {

To me, this is sort of unreadable without the comments and ugly looking with
the comments. My favourite nightmare in this regard in wireshark source is
dissect_ieee80211_common which has 4 boolean parameters and no comments anywhere
where it is called.

What ways are there to fix this? Is replacing the boolean types by an enum with
speaking elements a valid solution? As an example, the above might read:

         if (cf_save_packets(&cfile, file_name8->str, filetype, NOT_COMPRESSED, DONT_DISCARD_COMMENTS, DONT_REOPEN) != CF_OK) {

What would be good names for the elements in the enums?


I have the same "allergic reactiuon" as described above.

Using enums would help; Unfortunately they all share a single namespace, so something like CF_SAVE_PACKETS_NOT_COMPRESSED, etc might be required; this seems just a bit clumsy (but doable).