SHort tags

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: SHort tags

Post by josh »

alternative syntax hurts my head. I recently made the mistake of selling code that had short tags, out of chance I emailed the guy to ask him how he was coming along and he was like "im still replacing all these tags", i was like man... find & replace.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: SHort tags

Post by alex.barylski »

Why does alternative syntax hurt your head?

In HTML templates it's way better than standard PHP, no?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: SHort tags

Post by Benjamin »

I've never really liked short tags. When you have static XML in your PHP you have to turn off short tags anyway. How would you like to remove all the short tags from every file in a large application just to get one page to work?

Ahhh.. I just think they are ugly anyway. They drive me nuts.

The first thing I think when I see a codebase with short tags is that the programmer was a newbie and inexperienced.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: SHort tags

Post by alex.barylski »

he first thing I think when I see a codebase with short tags is that the programmer was a newbie and inexperienced.
While that is usually the case, they are slightly more aesthetically appealing:

<?= $some_var; ?>

compared to

<?php echo $some_var; ?>

So I can understand why people use them in templates as it's nicer to look at inside a alt tag or something similar.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: SHort tags

Post by josh »

PCSpectra wrote:In HTML templates it's way better than standard PHP, no?
How, because it reminds you of the 60s? :D
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: SHort tags

Post by Benjamin »

Well I think regex is aesthetically appealing :)

Code: Select all

 
^.*/((.*?)\.txt)$
 
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: SHort tags

Post by josh »

I agree too, alt syntax reminds me of VB and is ambiguous with the existing syntax tho
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: SHort tags

Post by alex.barylski »

How, because it reminds you of the 60s?
Considering I wasn't born until 1979...no...not really. :lol:

If you don't use alternative syntax, how do you code your HTML templates? Do you use Smarty *gag* or do you use the more obfuscated inline PHP, likeso:

Code: Select all

<div>
  <?php
    if($a == $b){?>
    <strong><?php echo $title; ?></strong>
  <?php } ?>
</div>
When compared to:

Code: Select all

 
<div>
  <?php if($a == $b): ?>
    <strong><?php echo $title; ?></strong>
  <?php endif; ?>
</div>
 
Not only is it easier on my eyes (especially once you get into complex presentation logic) but IDE's that support code folding will recorgnize the open and close tags and allow you to hide entire sections, using the former syntax, causes all sorts of weird hilighting issues (in some IDE's) not to mention disabling code folding in many instances.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: SHort tags

Post by Eran »

Code: Select all

<?php if($a == $b): ?>
    <strong><?php echo $title; ?></strong>
  <?php endif; ?>
You used long tags in here.. the alternative syntax for control structures is not related to short/long tags. I use the same syntax inside templates
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: SHort tags

Post by alex.barylski »

I realize that, re-read the discussion and you'll see I said:
Short tags are nice in alternative syntax templates though...
TO which josh replied:
alternative syntax hurts my head.
So I asked why it hurt his head...I don't think either of implied that alternative syntax and short/long tags were the same thing, did we?

EDIT | The point was given the examples I gave above:

Code: Select all

<?php echo $title; ?>
Isn't as nice to lok at as:

Code: Select all

<?= $title; ?>
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: SHort tags

Post by Eran »

Again, the considerations of portability eliminate short-tags for me. For this reason, almost all external libraries use long-tags - and I don't like mixing too much such conventions. It leads to stupid mistakes and too much headaches.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: SHort tags

Post by josh »

PCSpectra wrote:If you don't use alternative syntax, how do you code your HTML templates? Do you use Smarty *gag* or do you use the more obfuscated inline PHP, likeso:
Neither.

Code: Select all

 
<table>
    <tr>
        <td colspan="2"></td>
        <?php
        foreach( $this->grid->getFields() as $field )
        {
            echo '<td><b>' . ucfirst( $field ) . '</b></td>';
        }
        ?>
    </tr>
    <?php
    foreach( $this->grid->getRows() as $model )
    {
        ?>
        <tr>
            <td><a href="<?=$this->getEditUrl( $model->getId() )?>">Edit</td>
            <td><a href="<?=$this->getDeleteUrl( $model->getId() )?>">Delete</td>
            <?php
            foreach( $this->grid->getFields() as $field )
            {
                $command = 'get' . ucfirst( $field );
                if( method_exists( $model, $command ) )
                {
                    ?>
                    <td><?=$this->escape( $model->$command() )?></td>
                    <?php
                }
            }
            ?>
        </tr>
        <?php
    }
    ?>
</table>
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: SHort tags

Post by Eran »

:offtopic:
By the way, on the topic of smarty: http://nosmarty.net/
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: SHort tags

Post by josh »

How is it offtopic?
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: SHort tags

Post by panic! »

Am I the only person who prefers the older curly brackets to the newer VB style if/endif syntax?
Post Reply