Phillip Susi wrote:
I'd just like to chime in here with my opinion.
About a year ago I had
the idea of introducing macros for error handling instead of explicit
gotos. We had some discussion on the matter, and I read several papers
on the web, and came to agree that use of macros that change flow
control is anathma. It makes the code completely unreadable and
unmaintainable.
In win32k i use macros for flow control in the NtUser syscalls
(functionally like a try/finally block) where its very important that
some cleanup (release a lock) is always done:
BOOL NtFunc()
{
DECLARE_RETURN(BOOL);
Lock();
if (Stuff) RETURN(FALSE);
....
RETURN(TRUE);
CLEANUP:
Unlock(Stuff);
DPRINT1("NtFunc returned %i\n", _ret_);
END_CLEANUP;
}
At first it seemed like a great idea to hide the "nasty" gotos and have
to type less while hammering out the code, but in the end, even when you
are familliar with the macros, it looks ugly, and for someone who isn't
familliar with the macros, it is utterly unreadable.
If we should only invent stuff that ppl _already_ understand we just had
to stop inventing.
Recently I was reading over some apache code and they make extensive use
of macros for flow control. I found myself becoming frustrated to no
end because I could not figure out what the hell was going on. They
looked like nice, neat function calls, but I could not for the life of
me figure out where the code was that was being called.
So if they had been function calls and not macros it would have been
easier??? Or should we stop using functions also? ;-P
It wouldn't
have looked so deceptively simple if they coded out what was going on
explicitly instead of using macros, but it would have been easy to
understand, and why should something look deceptively simple when it
really isn't?
If you cant find a macro (simple text search) you probably wouldnt have
understod the code _without_ the macros either;-P
But off course you have to learn how the macros work to understand and
utilize them, but that goes for any code. I cant see how learning a
function call with 10+ params (typical nt syscall func) should be any
easier than learning a simple macro. Thats just being lazy.
G.