Re: [PHP] Preferred Syntax

2011-12-15 Thread Tedd Sperling
On Dec 14, 2011, at 12:09 PM, Peter Ford wrote:
> 
> With respect to tedd and Al, you've misread the question: the important 
> PHP-related bit is about whether to embed variables in double-quoted strings 
> or to concatenate them. These are only two of the options, and each has it's 
> pros and cons. There has been (some time ago) plenty of discussion on this 
> list about this sort of thing, including (ISTR) a timed test of the 
> performance implications of various forms - that only really matters in big 
> loops, of course...
> 
> Horses for courses. I use whatever I feel like at the time, and mix various 
> styles, as long as it's readable!
> 
> Cheers
> Pete
> 

I didn't misread the OP's post. Realize that the OP provided two ways of doing 
the task and asked which way was best?

I responded with a recommendation to remove all style elements and my 
recommended solution to his problem.

He can either consider or not.

Cheers,

tedd

_
t...@sperling.com
http://sperling.com




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Preferred Syntax

2011-12-14 Thread Rick Dwyer
On Dec 14, 2011, at 1:53 PM,  > wrote:


The key thing to remember here is that this is a preference and not a
performance thing.


Thank you... this is basically what I wanted to know.  I was concerned  
that not breaking the VARS out separately from the echo'ed text might  
cause some sort of performance problem or confusion for PHP.   
Therefore, whenever I came across them, I was breaking them out with  
the . $var . technique.  Will no longer do that for existing code, as  
it appears not necessary, but I do prefer it for readability sake...  
expecially in BBEdit.  So will continue to write new code breaking it  
out.  And I too prefer a single quote for PHP and a double for HTML...  
even though the sample I displayed showed otherwise.


Thanks to all who responded.

--Rick



RE: [PHP] Preferred Syntax

2011-12-14 Thread admin
> -Original Message-
> From: Adam Richardson [mailto:simples...@gmail.com]
> Sent: Wednesday, December 14, 2011 2:19 PM
> To: Rick Dwyer
> Cc: PHP-General
> Subject: Re: [PHP] Preferred Syntax
> 
> On Wed, Dec 14, 2011 at 7:59 AM, Rick Dwyer 
> wrote:
> 
> > Hello all.
> >
> > Can someone tell me which of the following is preferred and why?
> >
> >  echo " > href='/mypage.php/$page_id'>$**page_name";
> >
> >  echo " > href='/mypage.php/".$page_id."**'>".$page_name."";
> >
> > When I come across the above code in line 1, I have been changing it
> to
> > what you see in line 2 for no other reason than it delineates out
> better in
> > BBEdit.  Is this just a preference choice or is one method better
> than the
> > other?
> >
> 
> I prefer sending arguments to the echo language construct (note, if you
> send more than one argument, you can't use parentheses.) I perceive
> this
> usage to be a clean presentation of the code's intent, easy to use in
> most
> IDE's, and it's very fast relative to the other options:
> 
> echo " href='/mypage.php/$page_id'>$**page_name";
> 
> echo " href='/mypage.php/".$page_id."**'>".$page_name."";
> 
> echo " href='/mypage.php/", $page_id, "'>", $**page_name, "";
> 
> And, for longer lines, I'll often break it up into separate lines by
> argument like below:
> 
> echo
> " href='/mypage.php/",
> $page_id,
> "'>",
> $**page_name,
> "";
> 
> That all said, I don't change code that uses another convention, as I
> think
> it's most beneficial to stay with the established conventions in any
> codebase (unless you're establishing a new convention and refactoring
> the
> entire code base.) This is just my general preference, and I don't
> believe
> there is consensus as to the most appropriate.
> 
> Adam
> 
> --
> Nephtali:  A simple, flexible, fast, and security-focused PHP framework
> http://nephtaliproject.com



Adam,
You are very correct, the last discussions and testing of theories
caused my head to hurt!!! 
Neither side gained ground in testing or discussion.
Having said that to me it is a preference only and not a performance
enhancing or degrading factor in syntax.





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Preferred Syntax

2011-12-14 Thread Adam Richardson
On Wed, Dec 14, 2011 at 7:59 AM, Rick Dwyer  wrote:

> Hello all.
>
> Can someone tell me which of the following is preferred and why?
>
>  echo " href='/mypage.php/$page_id'>$**page_name";
>
>  echo " href='/mypage.php/".$page_id."**'>".$page_name."";
>
> When I come across the above code in line 1, I have been changing it to
> what you see in line 2 for no other reason than it delineates out better in
> BBEdit.  Is this just a preference choice or is one method better than the
> other?
>

I prefer sending arguments to the echo language construct (note, if you
send more than one argument, you can't use parentheses.) I perceive this
usage to be a clean presentation of the code's intent, easy to use in most
IDE's, and it's very fast relative to the other options:

echo "$**page_name";

echo "".$page_name."";

echo "", $**page_name, "";

And, for longer lines, I'll often break it up into separate lines by
argument like below:

echo
"",
$**page_name,
"";

That all said, I don't change code that uses another convention, as I think
it's most beneficial to stay with the established conventions in any
codebase (unless you're establishing a new convention and refactoring the
entire code base.) This is just my general preference, and I don't believe
there is consensus as to the most appropriate.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


RE: [PHP] Preferred Syntax

2011-12-14 Thread admin
> -Original Message-
> From: Tamara Temple [mailto:tamouse.li...@tamaratemple.com]
> Sent: Wednesday, December 14, 2011 1:40 PM
> To: Tedd Sperling
> Cc: Rick Dwyer; PHP-General
> Subject: Re: [PHP] Preferred Syntax
> 
> Tedd Sperling  wrote:
> > On Dec 14, 2011, at 7:59 AM, Rick Dwyer wrote:
> >
> > > Hello all.
> > >
> > > Can someone tell me which of the following is preferred and why?
> > >
> > > echo " href='/mypage.php/$page_id'>$page_name";
> > >
> > > echo " href='/mypage.php/".$page_id."'>".$page_name."";
> > >
> > > When I come across the above code in line 1, I have been changing
> it to what you see in line 2 for no other reason than it delineates out
> better in BBEdit.  Is this just a preference choice or is one method
> better than the other?
> > >
> > > --Rick
> >
> > Neither.
> >
> > My advice, take all the style elements out of the anchor tag.
> >
> > echo("$page_name");
> >
> > Even the '' can be (perhaps should be) handled by css.
> 
> I think you may have missed the question. The OP was asking whether:
> 
>   "text $var text"
> 
> or
> 
>   "text ".$var." text"
> 
> was preferrable.
> 
> For me, I tend to use the first unless the second makes things clearer
> where they need to be. Syntax hilighing can easily be one of those
> times.
> 
> 
> --

The key thing to remember here is that this is a preference and not a
performance thing.






-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Preferred Syntax

2011-12-14 Thread Robert Cummings

On 11-12-14 01:10 PM, David Harkness wrote:

On Wed, Dec 14, 2011 at 4:59 AM, Rick Dwyer  wrote:


Can someone tell me which of the following is preferred and why?

  echo "$**page_name";

  echo "".$page_name."";



On Wed, Dec 14, 2011 at 9:09 AM, Peter Ford  wrote:


Horses for courses. I use whatever I feel like at the time, and mix
various styles, as long as it's readable!



I agree with Peter here. I would bet that the string with embedded
variables is parsed once when the file is loaded and turned into the same
bytecode as the second form.

If you are going to use the second style above, I would at least switch the
quotes around so you can use the double-quotes in the HTML as that to me
reads nicer and avoids the minor cost of scanning the string for embedded
code. I also put spaces around the dots to make the variable concatenation
easier to spot when skimming it.

 echo '' . $page_name .'';


+1 on the use of single quotes instead of double quotes. With a bytecode 
cache it's not really going to make a lick of difference, but using 
double quotes for HTML seems far more palatable to me. I too like to 
pull the variable out into code space. I also like to format my 
attributes for easy reading and commenting:


echo ''
.$page_name
.''
.'';

Although, I usually only do the above for tags that have lots of 
attributes. Otherwise the following is more likely:


echo ''
.'Something something'
.'';

As I said before though, a bytecode cache with any degree of 
optimization "should" make any particular style have zero impact on 
runtime (beyond original parse) by optimizing the strings into a minimal 
set of operations. For instance 'foo'.'fee' would be coverted to 
'foofee' by the bytecode engine.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Preferred Syntax

2011-12-14 Thread Tamara Temple
Tedd Sperling  wrote:
> On Dec 14, 2011, at 7:59 AM, Rick Dwyer wrote:
> 
> > Hello all.
> > 
> > Can someone tell me which of the following is preferred and why?
> > 
> > echo " > href='/mypage.php/$page_id'>$page_name";
> > 
> > echo " > href='/mypage.php/".$page_id."'>".$page_name."";
> > 
> > When I come across the above code in line 1, I have been changing it to 
> > what you see in line 2 for no other reason than it delineates out better in 
> > BBEdit.  Is this just a preference choice or is one method better than the 
> > other?
> > 
> > --Rick
> 
> Neither.
> 
> My advice, take all the style elements out of the anchor tag.
> 
> echo("$page_name");
> 
> Even the '' can be (perhaps should be) handled by css.

I think you may have missed the question. The OP was asking whether:

  "text $var text" 

or

  "text ".$var." text"

was preferrable.

For me, I tend to use the first unless the second makes things clearer
where they need to be. Syntax hilighing can easily be one of those
times.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Preferred Syntax

2011-12-14 Thread David Harkness
On Wed, Dec 14, 2011 at 4:59 AM, Rick Dwyer  wrote:

> Can someone tell me which of the following is preferred and why?
>
>  echo " href='/mypage.php/$page_id'>$**page_name";
>
>  echo " href='/mypage.php/".$page_id."**'>".$page_name."";
>

On Wed, Dec 14, 2011 at 9:09 AM, Peter Ford  wrote:

> Horses for courses. I use whatever I feel like at the time, and mix
> various styles, as long as it's readable!


I agree with Peter here. I would bet that the string with embedded
variables is parsed once when the file is loaded and turned into the same
bytecode as the second form.

If you are going to use the second style above, I would at least switch the
quotes around so you can use the double-quotes in the HTML as that to me
reads nicer and avoids the minor cost of scanning the string for embedded
code. I also put spaces around the dots to make the variable concatenation
easier to spot when skimming it.

echo '' . $page_name . '';

David


Re: [PHP] Preferred Syntax

2011-12-14 Thread Marc Guay
> BBEdit.  Is this just a preference choice or is one method better than the 
> other?

As far as I know it's just preference.  Your choice of editor could
influence your decision; one form might be given nicer highlighting.

Marc

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Preferred Syntax

2011-12-14 Thread Tedd Sperling
On Dec 14, 2011, at 7:59 AM, Rick Dwyer wrote:

> Hello all.
> 
> Can someone tell me which of the following is preferred and why?
> 
> echo " href='/mypage.php/$page_id'>$page_name";
> 
> echo " href='/mypage.php/".$page_id."'>".$page_name."";
> 
> When I come across the above code in line 1, I have been changing it to what 
> you see in line 2 for no other reason than it delineates out better in 
> BBEdit.  Is this just a preference choice or is one method better than the 
> other?
> 
> --Rick

Neither.

My advice, take all the style elements out of the anchor tag.

echo("$page_name");

Even the '' can be (perhaps should be) handled by css.

Cheers,

tedd

_
t...@sperling.com
http://sperling.com





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php