What style of programming is this called?
I don't have good name for this style of programming where the syntax is开发者_开发技巧 more succinct because of not having to pass the context into a function or call the functions off of a context object.
For example, some random OpenGL C code:
glBegin(GL_QUADS);
glNormal3fv(&n[i][0]);
glVertex3fv(&v[faces[i][0]][0]);
glVertex3fv(&v[faces[i][1]][0]);
glVertex3fv(&v[faces[i][2]][0]);
glVertex3fv(&v[faces[i][3]][0]);
glEnd();
But you could set the context in the "begin" call and release it in the "end" call. I have seen styles like this in C#, Java, and Ruby. Does it have a name?
"Procedural with global-state side-effects"?
(While OGL does use a stack to maintain various state, it is not used in this example and thus omitted from my reply.)
Reference oriented programming?
If you assume there is a "this" in front of the statements you could consider it a Fluent interface: http://en.wikipedia.org/wiki/Fluent_interface
Otherwise, it appears very much like a Stack-Oriented language such as PostScript:
http://en.wikipedia.org/wiki/Stack-oriented_programming_language
It seems very similar to a Builder
This looks sorta like a builder. What you have there is openGL calls and you are basically constructing a triangle (that is rendered). Your example rewritten in oo/builder terms:
TriangleBuilder b = new TriangleBuilder(); b.AddVertex(normal, faces[0]); b.AddVertex(normal, faces[1]); b.AddVertex(normal, faces[2]); Triangle t = b.Build();
精彩评论