Deutsch   English   Français   Italiano  
<v3bodm$23sno$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.nobody.at!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Malcolm McLean <malcolm.arthur.mclean@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: Against bool
Date: Fri, 31 May 2024 06:49:40 +0100
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <v3bodm$23sno$1@dont-email.me>
References: <v3a8p9$1osnv$1@dont-email.me> <v3bfq8$22mlu$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 31 May 2024 07:49:42 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="98adbfc9fb82bc6ff00114fd24e87629";
	logging-data="2224888"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+Hr2vHlgvsbr4M3xFkanY8hm5I73kZHUg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:lF6dL6R9RLbK10n3KgfI8yX38UI=
In-Reply-To: <v3bfq8$22mlu$3@dont-email.me>
Content-Language: en-GB
Bytes: 2862

On 31/05/2024 04:22, Lawrence D'Oliveiro wrote:
> On Thu, 30 May 2024 17:16:40 +0100, Malcolm McLean wrote:
> 
>> And so we want to abolish bool and replace it with a bool enum.
> 
>      bool is_array(XMLNODE * node, bool useattributes);
>      bool is_object(XMLNODE * node, bool useattributes);
>      bool is_field(XMLNODE * node, bool useattributes);
> 
> Seems to me, the use of “bool” helps make pretty clear what those
> arguments are for. What’s wrong with that?

if (is_array(node))
{
    /* node is an array, output jSON array */
}

very obvious. And bool make no difference. And isspace() returns an 
integer in standard C. The convention is that 0 = false, and non zero =
true. So comparing the result to 1 or to "true" is an error.

if (isarray(node, useattributes))

ok, not entirely obvious, but in fact whether a node should be a JSON 
array or not depends on whether the user wants to consider XML 
attributes or ignore them, and most pepole will get the idea.

if (is_array(node, true))

Now what the hell?


if (is_array(node, YES_USEATTRIBUTES))

Now were getting somewhere.

However if we do

#define YES_USE_ATTRIBUTES true

or some equivalent, then peple can just pass "true" and defeat the system.

So this is cuter

#define NO_USEATTRIBUTES 0
#define YES_USEATRRIBUTES 12345

int is_array(XML node *node, int useatrributes)
{
    assert(useattributes == NO_USEATTRIBUTES|| useattributes == 
YES_USEATTRIBUTES);
}

And now we're maybe tightening things up a bit.

But we need bool enums. If we are to have boolean types in C, they need 
to be done properly. Just defining sysmbols for true and false isn't 
adequate. Anyone can do that in two minutes.

-- 
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm