MyBB Community Forums

Full Version: Development Standards - Ternary Operators
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

To quote the development standards page:
Quote:Control structures include if, for, while, and switch statements. Curly braces should always be used even in situations where they are optional. Ternary operators are not permitted and should not be used.

Excerpt of the code:
my_setcookie("mybbuser", $user['uid']."_".$user['loginkey'], ($mybb->input['remember'] == "yes" ? null : 0), true);

Version: MyBB 1.6
File: portal.php
Line: 86

Would be nice if you could fix this.
I've never understood the hatred of ternary operators. They can be useful, and if someone can't read them they should go get a book that properly teaches the language they're trying to use.
(2010-08-16, 04:48 PM)Firestryke31 Wrote: [ -> ]I've never understood the hatred of ternary operators. They can be useful, and if someone can't read them they should go get a book that properly teaches the language they're trying to use.

Tell that to the team, not me. I just pointed a contradiction within the code Toungue
I use them all the time when its simple code. If the true/false return values are complex, I will use expanded code, but otherwise they are easy to read and require fewer lines of code. The above code is a prime example of this.
Not that big of a deal, TBH. We just don't like ternary operators because they are not as easy to read the logic.

This probably won't be fixed. These standards were written many years after our initial codebase was in, including this bit of code.
(2010-08-16, 06:12 PM)Ryan Gordon Wrote: [ -> ]Not that big of a deal, TBH. We just don't like ternary operators because they are not as easy to read the logic.

This probably won't be fixed. These standards were written many years after our initial codebase was in, including this bit of code.

It says in the Wiki that they're not permitted. But you use them and you're saying that it's not a big deal?
Well, if you think that contradicting yourself is not a big deal..okay.

Maybe remove the not permitted part and leave the should not be used there?
Please vent somewhere else.