BuddyJoe
BuddyJoe

Reputation: 71171

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?

Upvotes: 1

Views: 416

Answers (5)

Yngve Hammersland
Yngve Hammersland

Reputation: 1674

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();

Upvotes: 1

user166390
user166390

Reputation:

"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.)

Upvotes: 6

Mik Lernout
Mik Lernout

Reputation: 11

It seems very similar to a Builder

Upvotes: 1

Keith Adler
Keith Adler

Reputation: 21178

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

Upvotes: 1

Dexygen
Dexygen

Reputation: 12561

Reference oriented programming?

Upvotes: 1

Related Questions