Re: [PHP] Re: if syntax

2002-07-12 Thread Chris Earle

> > >PHP will tell you you have a syntax error on the very last
> > line of your
> > >file, and you have no option but to go back and laboriously
> > hand match all
> > >of your braces -- and with each ellipsis representing maybe
> > tens (or even
> > >hundreds!)
> >
> > Don't be ridiculous.  Any decent editor will tell you where
> > the missing { or
> > } is.  No need to search for it by hand.
>
> Well, yes, but not the full story.  If the only clue you have is that
> there's probably a brace missing somewhere in the 600 lines of your file,
> and some of your structures nest 7 or 8 levels deep, that's still an awful
> lot of braces that you potentially have to check for matching partners,
even
> with a helpful editor to ease the task.  (And we know that some people
don't
> have helpful editors -- just look at the requests in this list for
> recommendations!!)  If, on the other hand, you get a parse error at line
234
> in one of the deeper levels of nested structures, your search is
immediately
> much more focussed.  This is just a plain fact, surely...?

I've never had a problem where it didn't give me a close estimate to where
the "{" or "}" was missing.  And I'm one of those ill-suited NotePad guys
(my Visual Studio copy is at work and I reformatted this computer recently).
:)

> > Not to mention that if you've indented properly, it's trivial
> > to find it,
> > even in something as ill-suitable for Programming as NotePad.
>
> Ah, indeed -- but, again, not everyone indents properly!!

I'm not sure that's a fair argument to make because you can say the same
thing about code with the if (exp): endif; code, I'm sure a lot of people
use it's simplicity (I do use it on occasion, but I indent like { }) and
then don't indent.

> > >Now PHP will throw an error at the endwhile, because it
> > knows there's an
> > >endfor missing -- and you've already cut out a large chunk
> > of your code to
> > >check; better yet, as you're checking you can see at a
> > glance what each
> > >"end" should be matching.  And every "end" has to be there, too -- no
> > >cursing yourself for that lazy day when you left out a few
> > comments on some
> > >"unimportant" closing braces!
> >
> > None of my closing braces have comments.  I never have a problem with
> > "missing" ones.

If I miss one the PHP parser gives me a big enough clue for me to find it
within 30 seconds.  I can definitely understand that though and I bet that
that is easier, especially in harder to read, uncommented code (that's a
general statement, not a shot at anyone).

> You must have much keener eyesight than me, then.  I often have difficulty
> telling which } lines up under which { (when I'm reading code written in
> that style, that is!), especially if they're on different pages of a
> listing.  When I code in a braced language, I *always* comment my closing
> braces for this reason.   Even in PHP using end* statements, I often add
> comment to tell me *which* "if" an "endif" matches, just to be sure.  (I
do
> the same in VB, too!)

I've got the same idea as him, but I wear glasses (not bad vision though ...
next up from 20/20).  I never added VB comments to my "End If" statements, I
might comment inside about what's going on, but never what's being matched.
I have the feeling your code is very readable, which is a good thing, but I
like my way for my own selfish reasons (much of which cannot be explained to
mere mortals!).

> > YMMV.
>
> I guess.  But I think other people's probably varies more, and the number
of
> occasions on this list when I think "but if you'd used alternative syntax
> style you'd *know* where the problem was" grows by the week.

You're probably right, but it is a religious and huge experience thing.
I've been working with { } for quite, especially a while outside of PHP and
I rarely have a problem (except when moving to ASP ... that normally takes a
quick relearning curve because of the VB syntax).

> Oh dear, I see I've got into rant mode once more.  Right, I'll shut up
now,
> and that really will be my last word on the topic.  Well, at least until
> someone else brings it up again.

Oops.

> Cheers!
>
> Mike
>

-Chris



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




Re: [PHP] Re: if syntax

2002-07-12 Thread Chris Earle


"Mike Ford" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > -Original Message-
> > From: Chris Earle [mailto:[EMAIL PROTECTED]]
> > Sent: 11 July 2002 18:28
> > To: [EMAIL PROTECTED]
> > Subject: Re: [PHP] Re: if syntax
> >
> >
> > > when it would be just as easy, and more functional, to
> > write this (even
> > > saves a few characters, too!):
> > >
> > >if (x):
> > >   while (y):
> > >  ...
> > >   endwhile;
> > >   ...
> > >endif;
> >
> > You're adding characters...
> >
> > "{" + "}" opposed to ":" + "endif;"
>
> No, no, no!  Look again -- I was contrasting this with:
>
>if (x) {
>   while (y) {
>  ...
>   } // end while
>   ...
>} // end if
>
> which I see quite often in other people's scripts.
>
> Then the difference is " {" and "} // end if" as opposed to ":" and
> "endif;", and indeed you are saving characters -- and it's more
functional,
> because the PHP processor is getting to check the end* statements match
the
> correct block opener, rather than just matching back to the next unclosed
> "{" regardless of whether it's on an appropriate block opener or not.  To
> me, this is such a huge advantage that I just can't understand why people
> insist on sticking with the all-braces style, and that's regardless of the
> fact that I just think it's more readable.

Oh, just as the other guy said, I don't comment my braces because I tab in
everything evenly (each if is another tab with the nested code tabed one
further).  I do comment my functions end braces because they can get pretty
big and they're all at the same level of tabbing.

I think that most people (like me) use it because of their backgrounds in
other programming languages.  I learned PHP after I was doing a lot of C++
work ... so it came very naturely.

> Cheers!
>
> Mike
>
> -
> Mike Ford,  Electronic Information Services Adviser,
> Learning Support Services, Learning & Information Services,
> JG125, James Graham Building, Leeds Metropolitan University,
> Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
> Email: [EMAIL PROTECTED]
> Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211



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




RE: [PHP] Re: if syntax

2002-07-12 Thread Ford, Mike [LSS]

> -Original Message-
> From: Richard Lynch [mailto:[EMAIL PROTECTED]]
> Sent: 11 July 2002 23:38
> 
[]
> 
> I apologize profusely to the fans of the "alternative syntax" 
> who are still
> using it.
> 
> I personally find the endxxx; to be more of an eyesore, but that's a
> religious argument. :-)

Oh, yes, absolutely -- to me, braces all over the place are an eyesore, but
I wouldn't argue your right to program the way you like.  That's one of the
plus points of PHP, it lets both of us do what we think is the beautiful
thing!

> >I've pretty much lost count of the number of times I've seen 
> code written
> >like this:
> >
> >   if (x) {
> >  while (y) {
> > ...
> >  } // end while
> >  ...
> >   } // end if
> 
> Never in my code.

Glad to hear it -- nevertheless, it *is* fairly common in my experience.

> If you can't tell from the logic structure of the code what } 
> matches what
> {, you're in trouble from the get-go. :-)

Well, yes.  But not everyone writes that logically -- or even writes
consistently-indented code!

> >Another advantage to the alternative syntax is that it can 
> improve error
> >reporting (slightly).  Consider the following:
> 
> >PHP will tell you you have a syntax error on the very last 
> line of your
> >file, and you have no option but to go back and laboriously 
> hand match all
> >of your braces -- and with each ellipsis representing maybe 
> tens (or even
> >hundreds!)
> 
> Don't be ridiculous.  Any decent editor will tell you where 
> the missing { or
> } is.  No need to search for it by hand.

Well, yes, but not the full story.  If the only clue you have is that
there's probably a brace missing somewhere in the 600 lines of your file,
and some of your structures nest 7 or 8 levels deep, that's still an awful
lot of braces that you potentially have to check for matching partners, even
with a helpful editor to ease the task.  (And we know that some people don't
have helpful editors -- just look at the requests in this list for
recommendations!!)  If, on the other hand, you get a parse error at line 234
in one of the deeper levels of nested structures, your search is immediately
much more focussed.  This is just a plain fact, surely...?

> 
> Not to mention that if you've indented properly, it's trivial 
> to find it,
> even in something as ill-suitable for Programming as NotePad.

Ah, indeed -- but, again, not everyone indents properly!!

> >Now PHP will throw an error at the endwhile, because it 
> knows there's an
> >endfor missing -- and you've already cut out a large chunk 
> of your code to
> >check; better yet, as you're checking you can see at a 
> glance what each
> >"end" should be matching.  And every "end" has to be there, too -- no
> >cursing yourself for that lazy day when you left out a few 
> comments on some
> >"unimportant" closing braces!
> 
> None of my closing braces have comments.  I never have a problem with
> "missing" ones.

You must have much keener eyesight than me, then.  I often have difficulty
telling which } lines up under which { (when I'm reading code written in
that style, that is!), especially if they're on different pages of a
listing.  When I code in a braced language, I *always* comment my closing
braces for this reason.   Even in PHP using end* statements, I often add
comment to tell me *which* "if" an "endif" matches, just to be sure.  (I do
the same in VB, too!)

> YMMV.

I guess.  But I think other people's probably varies more, and the number of
occasions on this list when I think "but if you'd used alternative syntax
style you'd *know* where the problem was" grows by the week.

Oh dear, I see I've got into rant mode once more.  Right, I'll shut up now,
and that really will be my last word on the topic.  Well, at least until
someone else brings it up again.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

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




RE: [PHP] Re: if syntax

2002-07-12 Thread Ford, Mike [LSS]

> -Original Message-
> From: Chris Earle [mailto:[EMAIL PROTECTED]]
> Sent: 11 July 2002 18:28
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] Re: if syntax
> 
> 
> > when it would be just as easy, and more functional, to 
> write this (even
> > saves a few characters, too!):
> >
> >if (x):
> >   while (y):
> >  ...
> >   endwhile;
> >   ...
> >endif;
> 
> You're adding characters...
> 
> "{" + "}" opposed to ":" + "endif;"

No, no, no!  Look again -- I was contrasting this with:

   if (x) {
  while (y) {
 ...
  } // end while
  ...
   } // end if

which I see quite often in other people's scripts.

Then the difference is " {" and "} // end if" as opposed to ":" and
"endif;", and indeed you are saving characters -- and it's more functional,
because the PHP processor is getting to check the end* statements match the
correct block opener, rather than just matching back to the next unclosed
"{" regardless of whether it's on an appropriate block opener or not.  To
me, this is such a huge advantage that I just can't understand why people
insist on sticking with the all-braces style, and that's regardless of the
fact that I just think it's more readable.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

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




Re: [PHP] Re: if syntax

2002-07-11 Thread Richard Lynch

>> The "alternate syntax" with the colons is passe -- I think 
>> you'd have to dig
>> pretty deep to find a script old enough that uses it for 
>> anything other than
>> demonstration purposes.  (Rasmus?)
>
>What utter tosh!  *All* my scripts use the "alternative" syntax, as I think
>braces are an eyesore and an abomination, and cause more problems than they
>solve.

I apologize profusely to the fans of the "alternative syntax" who are still
using it.

I personally find the endxxx; to be more of an eyesore, but that's a
religious argument. :-)

>I've pretty much lost count of the number of times I've seen code written
>like this:
>
>   if (x) {
>  while (y) {
> ...
>  } // end while
>  ...
>   } // end if

Never in my code.

If you can't tell from the logic structure of the code what } matches what
{, you're in trouble from the get-go. :-)

>Another advantage to the alternative syntax is that it can improve error
>reporting (slightly).  Consider the following:

>PHP will tell you you have a syntax error on the very last line of your
>file, and you have no option but to go back and laboriously hand match all
>of your braces -- and with each ellipsis representing maybe tens (or even
>hundreds!)

Don't be ridiculous.  Any decent editor will tell you where the missing { or
} is.  No need to search for it by hand.

Not to mention that if you've indented properly, it's trivial to find it,
even in something as ill-suitable for Programming as NotePad.

>Now PHP will throw an error at the endwhile, because it knows there's an
>endfor missing -- and you've already cut out a large chunk of your code to
>check; better yet, as you're checking you can see at a glance what each
>"end" should be matching.  And every "end" has to be there, too -- no
>cursing yourself for that lazy day when you left out a few comments on some
>"unimportant" closing braces!

None of my closing braces have comments.  I never have a problem with
"missing" ones.

YMMV.

-- 
Like Music?  http://l-i-e.com/artists.htm

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




Re: [PHP] Re: if syntax

2002-07-11 Thread Chris Earle

> when it would be just as easy, and more functional, to write this (even
> saves a few characters, too!):
>
>if (x):
>   while (y):
>  ...
>   endwhile;
>   ...
>endif;

You're adding characters...

"{" + "}" opposed to ":" + "endif;"

Don't go for the fuzzy Math from the Al Gore campaign!



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




RE: [PHP] Re: if syntax

2002-07-11 Thread Ford, Mike [LSS]

> -Original Message-
> From: Richard Lynch [mailto:[EMAIL PROTECTED]]
> Sent: 11 July 2002 10:54
> 
> The "alternate syntax" with the colons is passe -- I think 
> you'd have to dig
> pretty deep to find a script old enough that uses it for 
> anything other than
> demonstration purposes.  (Rasmus?)

What utter tosh!  *All* my scripts use the "alternative" syntax, as I think
braces are an eyesore and an abomination, and cause more problems than they
solve.

I've pretty much lost count of the number of times I've seen code written
like this:

   if (x) {
  while (y) {
 ...
  } // end while
  ...
   } // end if

when it would be just as easy, and more functional, to write this (even
saves a few characters, too!):

   if (x):
  while (y):
 ...
  endwhile;
  ...
   endif;

Another advantage to the alternative syntax is that it can improve error
reporting (slightly).  Consider the following:

if () {
;
while () {
;
for () {
;

}

}


PHP will tell you you have a syntax error on the very last line of your
file, and you have no option but to go back and laboriously hand match all
of your braces -- and with each ellipsis representing maybe tens (or even
hundreds!) of lines of code and/or HTML, that's a big job.  Now suppose you
wrote it like this instead:

if ():
;
while ():
;
for ():
;

endwhile;

endif;


Now PHP will throw an error at the endwhile, because it knows there's an
endfor missing -- and you've already cut out a large chunk of your code to
check; better yet, as you're checking you can see at a glance what each
"end" should be matching.  And every "end" has to be there, too -- no
cursing yourself for that lazy day when you left out a few comments on some
"unimportant" closing braces!



Just my two penn'orth.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

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