Home > Archive > PHP PEAR Questions and Answers > January 2005 > Re: [PEAR-QA] String values CS Coding Standards
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: [PEAR-QA] String values CS Coding Standards
|
|
| Alan Knowles 2005-01-19, 3:57 am |
| the speed issue between ' and " should have been pretty much removed
now, even though I've been using it for a long while, I'd be tempted to
suggest starting to follow other language standards:
eg.
'x' for single characters
"long strings" enclosed in double quotes.
Basically my PHP habits are a pain when working with C and C#..
But I'll survive if nothing changes ;)
Regards
Alan
bertrand Gugger wrote:
> Hi QA folks,
> So far I can check, PEAR's CS in manual dont give any advice for the
> string values.
> It gave some discussions about use simple ' or double "
> quotation mark.
> Obviously PHP kernel loose a little time with double.
> But it's quite no debate compared to what it does overall.
> Anyway the advice could be:
> Simple when it is static (expected never dynamic)
> as e.g. an associaive array index as $this->param['setting']
> or to initialize a string as $string = '';
> Double when content (is expected to) contain variable or escape (\n)
> to interpret.
> When not obvious (?) then free ' or "
> Some people mentioned to choose simple or double once for the whole
> script.
> I will not agree, and I believe it's making no difference for tokenizers.
>
> What should be a rule is the surrounding (brackets) around variables
> within double:
> never "Hello $name" but "Hello {$name}"
> because;
> - "Hello $name are you OK ?" could become "Hello $nameare you OK ?"
> but "Hello {$name}are you OK ?" still works (I18N)
> - or "Hello $name[$i]" should be "Hello {$name[$i]}"
> as $name can become $name[$i] or $this->name or ...
>
> It's awfull to type once but value for future maintenance.
> This advice is in PHP manual since a long time.
> Hope some of you can agree.
> Ã_+
| |
| bertrand Gugger 2005-01-19, 4:19 pm |
| Hi anatoly techtonik, you wrote:
>Just leave authors to decide their style and correct these " to ' only
>if package has a _serious_ speed bottlenecks because of such use at
>particular place. Should it be present in "Optimization" chapter of
>PEAR manual along with instructions how to run a benchmark?
>
>t
>
>
I should never have talked of performance, or use better english :'(
to explain that it's not there that PHP looses resources
but much more in the scripts' structure.
So, I agree no rule should be made about that
and each guy should use his/her own habits.
The rule that I required in my post was *bracket around included variables*
Somebody pro or against ?
Best
--
bertrand Gugger (toggg)
| |
| Martin Jansen 2005-01-22, 8:55 am |
| On Wed Jan 19, 2005 at 09:2040AM +0800, Alan Knowles wrote:
> the speed issue between ' and " should have been pretty much removed
> now, even though I've been using it for a long while, I'd be tempted to
> suggest starting to follow other language standards:
> eg.
> 'x' for single characters
> "long strings" enclosed in double quotes.
If the performance impact is negligent, then why not "allow" both
formats? Only the usage should be conistent throughout a package
then.
- Martin
| |
| bertrand Gugger 2005-01-22, 8:55 am |
| Hi Martin Jansen, you wrote:
>On Wed Jan 19, 2005 at 09:2040AM +0800, Alan Knowles wrote:
>
>
>
>If the performance impact is negligent, then why not "allow" both
>formats? Only the usage should be conistent throughout a package
>then.
>
>
It's exactly what everybody seem to agree on.
Alan was just giving as example, he could keep his old C-hacker habits ;)
I don't really understand consistant, here.
Do you mean only single or double within one pckg ?
I want both for fixed contents and expanded ones.
Just to recall, the thread deals with
*bracketing variables to expand in double quoted strings*.
à+
--
bertrand Gugger (toggg)
>- Martin
>
>
>
| |
| Martin Jansen 2005-01-22, 3:56 pm |
| On Sat Jan 22, 2005 at 01:0509PM +0100, bertrand Gugger wrote:
> Hi Martin Jansen, you wrote:
>
> I don't really understand consistant, here.
> Do you mean only single or double within one pckg ?
If the original author of a package has exclusively used either double
or single quotes, then future additions to the code should stick to
this style. That's consistency in my book.
> I want both for fixed contents and expanded ones.
I don't understand that.
- Martin
| |
| bertrand Gugger 2005-01-22, 3:56 pm |
| Hi Martin,
>
>I don't understand that.
>
>
I correct my first message in thread;
Single when it is static (expected never dynamic)
as e.g. an associaive array index as $this->param['setting']
or to initialize a string as $string = '<body>';
Double when content (is expected to) contain variable or escape (\n) to
expand.
Hope that make some sense.
à+
--
bertrand Gugger (toggg)
|
|
|
|
|