MyBB Community Forums

Full Version: Double Quotes instead of Single Quotes for strings
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello All,

First of all, hats off to the MyBB team for the excellent software. I have used it for sometime, and really liked the look and feel of it. I went through the code and found that, at a lot of places, strings are enclosed within double quotes instead of single quotes. But enclosing strings within double quotes makes the php interpreter look inside the string for variables. This creates an unnecessary overhead for the interpreter. So, even if the difference is not much significant, isn't it a better programming practise to make better use of single quotes wherever possible? Afterall, it doesn't have any disadvantage Smile
MyBB used to use double quotes as a standard, but since a few years ago the coding standard was allowed to include single quotes. Currently it is up to the developer's preference; I know Chris Heart double quotes Wink
But considering the performance factor, isn't it better to make this the preferred programming standard? Maybe even change the current files. All it requires is a few find and replaces Smile

Anyways I will be surely doing that before I upload it to my site Smile
Personally, I prefer single quotes, but since most are double quotes, I stick to the standard.
As you said, it's really not that big an issue. Many other languages will only accept strings inside double quotes, so maybe you could consider it good programming practice elsewhere? Dodgy

Thanks for the suggestion anyway Toungue

(2008-08-25, 05:20 PM)JoyceBabu Wrote: [ -> ]Anyways I will be surely doing that before I upload it to my site Smile
:O Have fun...
wiki.mybboard.net/index.php/Coding_Standards

Quote:Standard strings with no use of variables are to be written using single quotes:

Dodgy

(2008-08-25, 05:20 PM)JoyceBabu Wrote: [ -> ]But considering the performance factor,

What performance factor? Toungue

http://www.phpbench.com/ (scroll down to "Quote Types")

The other benchmarks I've seen basically say the same thing... insignificant difference. But I do agree that it's a good coding practice.

Replacing most double-quoted strings shouldn't be too hard with a regex search/replace. You just need to ignore strings that contain dollar signs, backslashes, or single quotes so you don't create any new bugs.
I wouldn't suggest to make the replacement to the current code, the speed difference is really not important at all, and your time for coding it doesn't worth it.

But I would suggest to the MyBB team that from now, use single quotes.

Anyway this is my humble opinion
Big Grin