On 04/12/2019 18:22, Serhiy Storchaka wrote:
In these files (symtable.c, compile.c, ast_opt.c, etc) there are
sequences of calls for child nodes. Every call can return an error, so
you need to check every call and return an error immediately after the
call. With inline functions you would need to write
if (!VISIT(...)) {
return 0;
}
if (!VISIT(...)) {
return 0;
}
if (!VISIT(...)) {
return 0;
}
instead of just
VISIT(...);
VISIT(...);
VISIT(...);
Can I just say as a C programmer by trade that I hate this style of
macro with the burning passion of a thousand fiery suns? Code like the
second example is harder to comprehend because you can't simply see that
it can change your flow of control. It comes as a surprise that if
something went wrong in the first VISIT(), the remaining VISIT()s don't
get called.
It's not so bad in the case you've demonstrated of bombing out on
errors, but I've seen the idiom used much less coherently in real-world
applications to produce code that is effectively unreadable. It took me
a long time to wrap my brain around what the low-level parsing code in
Expat was doing, for example. I strongly recommend not starting down
that path.
--
Rhodri James *-* Kynesim Ltd
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/IRNQHQUE7PX5RM63IHXGFOODBOFCZGAI/
Code of Conduct: http://python.org/psf/codeofconduct/