Required Names

A common design flaw in many older programming languages (for example, CeeLanguage, and to a lesser extent CeePlusPlus)--entities must be given names, even if they are only intended for use at the point of definition.

Consider the following C code...

 struct point {int x, y};

void draw (const point *from, const point *to);

....

/* Draw a line from (0,0) to (1023,767) */ { struct point p1 = {0,0}; struct point p2 = {1023,767};

draw (&p1, &p2);

}

In the above example, the variable p1 and p2 were created for no other reason than C doesn't allow the following:

 draw (&struct point {0,0}, &struct point{1023,767} );  /* or similar syntax */

In this case, the extra typing isn't so onerous. But if you declare a complex data structure with lots of indirection (pointers), it's impossible to initialize a pointer within a data structure to the address of a here-defined structure. (The one exception is you can initialize a char * member of a struct with a string constant.)

C++ makes things a little better if you use constructors... in C++ you could write

 draw (&point(0,0), &point(1023,767));

assuming that the point class has a suitable constructor. But this doesn't work for struct initialized with C-style syntax.

Another famous example is the lack of lambdas in C/C++ (though C++ can fake it with FunctorObjects).

More modern programming languages really ought to separate the definition/allocation of an object with its binding to a name. (And many of them do, fortunately).


EditText of this page (last edited November 4, 2004) or FindPage with title or text search