[Gs-devel] A small proposal about improving GS coding style : CheckRET
Igor V. Melichev
igor at artifex.com
Tue Jun 12 11:35:46 PDT 2001
This is very small proposal about improving GS coding style.
I'm tired of fragments like this :
int code = function(arguments);
if (code < 0)
return code;
They make code cumbersome and it cannot fit into display.
My old experience is to define macro :
#define CheckRET(a) { int temporaryvariable = (a); if (temporaryvariable <
0) return temporaryvariable; }
such that the code looks like this :
CheckRET(function(arguments));
I think that we don't need other predicates than '<0'.
If you think different, please explain.
I don't know, in which header file to insert this macro.
It must be globally accessible. Probably old GS developers can
choose a good place for it.
Yes, this thing is not perfect :
1. Sometimes other predicates wanted.
2. Incorrect code :
double temporaryvariable = 0;
CheckRET(function(&temporaryvariable));
3. Syntax error :
if (x)
CheckRET(function(arguments)); /* ' }; else' isn't valid syntax */
else
something();
4. Syntax error :
void f()
{ CheckRET(function(arguments)); /* Can't return value from void function
*/
}
But I use this thing during 4 years and I was very happy before I
entered GS. Now I'm unhappy because GS doesn't have it.
Lets define. Just try and you'll find it useful.
Of cause, one can propose multiple similar macros for problems 1-4.
But I believe that the power of my solution is to keep a single macro.
This is a discipline of mind (a kind of "structural" programming).
I don't propose to replace old code with this.
But I'd like to use it in new code.
But I don't like to define it locally multiple times.
Igor.
===== Igor V. Melichev, St.Petersburg, Russia. =====
===== business: mailto:igor at artifex.com =====
===== home: mailto:mlc at mlc.usr.pu.ru (no MIME please) =====
===== http://lissvr.math.spbu.ru/mlc/homepage.htm =====
More information about the gs-devel
mailing list