Liste des Groupes | Revenir à l c |
On 23/04/2025 19:43, bart wrote:On 23/04/2025 16:31, David Brown wrote:[...]>
>
We are all going to have different first-glance opinions on different
bits of code.
What's your initial opinion of this 500-line example:
[...]
You missed the bit where I said I am not interested in examining bad
code. Nor am I interested in Lisp, so I have no interest in looking at
that.
Here's one of the functions from it:
>
lval rest(lval *h, lval *g) { lval *f = h-1; lval r = 0; for (;
f>=g; f--)
r = cons(h, *f, r); return r; }
Presumably that makes sense to the people who wrote the code. But it
makes no sense to me.
That is /not/ because of some syntax or
formatting issue, or the missing clause in the "for" loop - it is
because I don't know the types, the functions (or macros) used, the
purpose of this function, the way memory and resource management is
handled in this code, the meaning of the single-letter identifiers, or
anything else about it.
How the code is formatted is a drop in the ocean in the effort needed to
understand the code, what it does, and where it fits with everything
else in the code base.
Here's what my visualisation tool produces:
>
global function rest(ref i32 h, g)i64 =
ref i32 f
i32 r
>
f := h-1
r := 0
while f >= g do
r := cons(h,f^,r)
f--
od
return r
end
Yes, you might apply a C formatter too, and keep it in C, it won't fix
that for-loop though.
The for-loop is basically irrelevant for understanding the code.
I fully agree that your "visualisation" here - or a re-factoring in C to
use a "while" loop rather than a "for" loop - makes the code easier to
read and makes it more obvious what the mechanics of the function are.
And if I were writing the same function myself, I'd use a while loop
rather than a for loop.
So don't misunderstand me here - I am not a fan
of the way that function is written. But I can't judge the format
without a lot more context, and such judgement would be highly
subjective. And the formatting is a very minor aspect of understanding
the code.
Les messages affichés proviennent d'usenet.