Liste des Groupes | Revenir à cl c |
On 21/04/2025 19:43, Kaz Kylheku wrote:On 2025-04-21, bart <bc@freeuk.com> wrote:>On 21/04/2025 04:16, Kaz Kylheku wrote:- Because they are not gathered in one place, not only is it less>readable, but we cannot use while write a macro such as:>>
for_sqlite_hash (p, &pSchema->trigHash) {
if (some_condition_over(p))
continue; // doesn't stupidly repeat for the same p!
}
I can't write such macros at all. I'm not even sure what this does.
Have you never worked with a large codebase written by someone other
than you?
How large are we talking about?
I've delved into largish apps in the context of getting my C compiler
working. I would describe that experience as 'brutal'.
If you need to
debug someone else's codebase, not to find bugs in that program, but to
find why your implementation is failing, then you want as conservative a
coding style as possible.
>
>When you open a random file in an unfamiliar code base, pretty>
much any function call that is not in the standard library triggers
the "I don't know what this does" response.
Yes, a function call. Macros are in an entirely different, evil category.
The Lua sources (only a mere 30Kloc), use macros extensively, but also
have a habit of giving them ordinary looking names in lower case so that
they look like function calls.
Preprocessing such code doesn't help either, since a simple function
call can expand into a horrendously complex expression that can be 100s
of characters long and have parentheses nested 10 deep.
>You have to learn some of that program's definitions in order to>
effectively work with that program. At least those which are relevant to
your intended task. You set up your "jump to definition" editor-fu and
start reading.
A loop macro like for_sqlite_hash (p, &pSchema->trigHash) is so obvious
Please humour me: What Does It Do?
that the only reason you'd look at its definition is to confirm that>
it's not doing something stupid (which can be defined as just about
anything different from what it *looks* like it is doing).
I'd call that a win!
Now you're calling the inability of the programmer to implement a
nice space-saving notation over something verbose a "win".
If so, why isn't "for (a; b; c)" also a "win" over "do i = x, y".
Your example is just this:
>
X(Y, Z)
>
and you're claiming it is something wonderful. Is it?
I don't know. I
might guess from its name that it is something to do with loops.
So what do X and Y represent, and what do they expand to?
>
What I might deduce, is that in C if you have a block of code like this:
>
{body}
>
You can turn that into a loop by putting a for-header to its left:
>
for(...) {body}
>
That for-header can come from a macro, so can be used to apply a loop to
such a block, without the code block itself needing to be a macro argument.
>
I will admit that is a useful side-effect of how a for-loop works, so
that it becomes a helpful feature if you ever need to write such macros.
I can't do that in my language; the macros are too simple, and the loop
body would need to be an argument, requiring closures etc. But then, the
existing loop features are adequate, and it is also easy to add new ones
by changing the language.
A macro solution would anyway be poor in terms of nice syntax, error
reporting and so on.
(I'm just remembered I have a visualisation that can turn C syntax into
my syntax (but it's not good enough to compile). It turns:
>
>
for(p=sqliteHashFirst(&pSchema->trigHash); p; p=sqliteHashNext(p)){
sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p));
}
>
into:
>
p := pSchema^.trigHash.first
while p do
sqlite3DeleteTrigger(db, ref Trigger(p^.data))
p := p^.next
od
>
You can now see that the C version involves macros. The increment has
now also been resolved into a simple member access.
>
Turning it into decent syntax and GETTING RID of macros has produced
cleaner looking code!)
Les messages affichés proviennent d'usenet.