View Full Version : Not an OGL question but...............................
09-30-2003, 03:05 AM
Sorry I disturb, but this is my favourite forum so.......
I have a colleague who hates this nice fry chip:
(x ? y : z)
it is the ternary operator and I like it to instantaneously solve big if statements.
Why that guy must hate and get pissed about it???
What do you think people??
as soon as you think of writing 'OT:' or 'offtopic' or 'Not an OGL question' in the header you really should post it somehere else..
i do know opengl, and im happy if im can help someone.. with opengl. I use delphi, we dont have that syntax so it doenst bother me, but this is just a matter of taste, what do you want as an anwer? a gallup?
09-30-2003, 05:19 AM
Yes... but thinking about it... it's not a good idea.... mmmmmm..... sorry.....
http://www.opengl.org/discussion_boards/ubb/frown.gif http://www.opengl.org/discussion_boards/ubb/smile.gif http://www.opengl.org/discussion_boards/ubb/frown.gif http://www.opengl.org/discussion_boards/ubb/smile.gif
09-30-2003, 07:18 AM
Yes, it is the famous ternary operator. Yes, most people don't like it, because it's somewhat easier to read an explicit if-else statement with proper indentation (particularly so if you're just skimming over code).
There are cases where it can be used nicely.
Eg, instead of
You could use
In the first snippet it's not immediately clear that the left hand sides of the assignment are equal. You need to look carefully. The second version doesn't require any comparison as the left hand side exists only once.
Good for dodging typos.
Yeah, most people who despise it just haven't used it much - it doesn't look like anything they've used before and it just doesn't sit well with them. Best thing to do is just suggest they give it a go for a while and see how they feel about it then. Everyone I've introduced it to has decided it's a very useful construct.
And to bring us back on topic, here's one good use for it:
glClear(GL_COLOR_BUFFER_BIT | (depthTestEnabled ? GL_DEPTH_BUFFER_BIT : 0)) ;
10-01-2003, 06:03 AM
I like that syntax. But then, I also enjoy using regular expressions in Perl... http://www.opengl.org/discussion_boards/ubb/smile.gif
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.