Personal dialects and C++ overloading
Ulrich Ruede
ruede at boulder.Colorado.EDU
Fri Feb 2 13:36:37 AEST 1990
In article <4156 at helios.TAMU.EDU> john at stat.tamu.edu (John S. Price) writes:
>
>#define FORNEXT(x,y,x) for (x=y;x<z;++x)
>
>...
>FORNEXT(x,0,10);
>
>That is not standard C, and I feel that using this type of macro is
>bad coding style.
>
Well, knowing that the following program has to do with a graph (with
attributed nodes and edges) would you prefer to see an initialization
like
FOR_ALL_NODES_OF(a_mesh, this_node)
FOR_ALL_EDGES_OF(this_node, this_edge)
this_edge->component= 0;
END_ALL_EDGES
END_ALL_NODES
or rather
{
Node_Ptr this_node;
for(this_node= (a_mesh)->grd; (this_node) != NULL; (this_node)= (this_node)->next){
{ register Edge_Ptr this_edge= (this_node)->c,
_end= (this_edge)+((this_node)->num_edges);
for(; (this_edge)<_end; (this_edge)++){
this_edge->component= 0;
}
}
}
}
This has been produced by cb on the expanded result.
The macros enable me to define the data structures and the access to
these structures together, as one module. If I don't use macros, the
information how to access all nodes of the graph is dispersed throughout
the program. Changing the basic structure then means to rewrite
everything. If I have the macros, I need to change just the macro definition.
I am using m4, so everyone who prefers the expanded result, can easily
get it with all symbolic constants still in symbolic form.
I also think that changing the syntax of a language is not a bad thing by
itself. If you write a function, you have also changed the syntax
of the language by introducing a new terminal symbol at the expression
level. In some sense all programming consists in changing the syntax
of a given base language, until you have a *specialized language* in which
you solve your problem with a single statement like
work();
This view of programming may be more obvious users of languages like
Prolog or Forth.
I agree, that only because you dislike C syntax you shouldn't
do things like
#define BEGIN {
(if you can't see the braces, get a better terminal (:-) or
#define OR ||
just as you wouldn't introduce new names for printf and other standard
library functions. Writing your own subroutines, however, makes perfect
sense, just as I believe it makes sense to use macros as mine above.
It would still be better if these capabiltities were built into some language
(without sacrificing performance).
Ulrich Ruede
ruede at boulder.colorado.edu (until Friday)
ruede at infovax.informatik.tu-muenchen.dbp.de (next week)
More information about the Comp.lang.c
mailing list