Sujet : Re: C23 thoughts and opinions
De : malcolm.arthur.mclean (at) *nospam* gmail.com (Malcolm McLean)
Groupes : comp.lang.cDate : 24. May 2024, 00:06:53
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v2oi6f$1vfk7$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla Thunderbird
On 22/05/2024 20:50, David Brown wrote:
On 22/05/2024 21:10, Malcolm McLean wrote:
But even boolean type and const.
Const documents the code, makes the action of a function clearer to the reader, and helps catch mistakes.
These are all things that make the language better, and have done so for the past 25 years.
Of course quite alot of the functions don't actually change the structures they are passed. But is littering the code with const going to help? And why do you really need a boolean when an int can hold either a zero or non-zero value?
>
And don't you just want a pared down, clean language?
>
I want a language with the features I need and that help me to write good clear code. Minimal is not helpful, any more than needlessly complex is helpful.
So the code I'm working on at the moment.
It's an implemention of XPath (a subset, of course). XPath is sort of query language for XML. You pass a query string like "/bookstore/book//title" and that selects all children of [root]/bookstore/book with the element tag "title".
Now querying the document shouldn't change it. So in C++ it should bepassed in as a XMLDOC const &. In C, declaring the pointer a const XMLDOC * conveyes the intention, but doesn't actually achieve the safety you want and get with C++.
However the algorithm I have just moved to needs a bit associated with each node it can turn on and of. Now in fact I did this via a hash table. But it is very tempting and far more efficient to simply add a hacky field to the XMLNODE structure - after all, I wrote the XML parser. And in C++ "mutable" is designed for just this. But in C,
were're either const or not. And isn't it maybe better to leave the const qualifier off the document pointer?
In fact, wouldn't we just be better off without const? After all, you need to read the function specifications anyway, and they should say that querying for a path will not alter the document.
-- Check out Basic Algorithms and my other books:https://www.lulu.com/spotlight/bgy1mm