RE: [PHP] Re: Better standards in PHP-coding

2002-04-23 Thread Ford, Mike [LSS]

 -Original Message-
 From: michael kimsal [mailto:[EMAIL PROTECTED]]
 Sent: 21 April 2002 04:17
 
 Second, *HOW MANY* PHP statements can be followed by a { ?
 
 I can think of three
 
 if (foo) {
 function foo () {
 class foo {
 
 Maybe there's one more that I'm missing [...]

Off the top of my head:

for
foreach
while
do
switch

... and I'm bound to have missed at least one!

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




[PHP] Re: Better standards in PHP-coding

2002-04-20 Thread michael kimsal

Frank wrote:
 
snip

For starters, just because GNU says something is what should be done
doesn't mean it's the right way.  They don't believe software should be
licensed in particular ways, and I happen to believe it's up to the 
developer(s) of a package to decide that.

Second, *HOW MANY* PHP statements can be followed by a { ?

I can think of three

if (foo) {
function foo () {
class foo {

Maybe there's one more that I'm missing, but it seems pretty darn
obvious to me that if I write

if (foo) {
if (bar) {
   echo bar;
}
}

that when I see a } I can immediately trace it back up to the 
corresponding column and see the keyword IF.  The indentation still 
keeps things in order.

Guess what other benefit *I* derive from this?  I can see more lines
on the screen at the same time.  Sorry - I usually always see ~35.
What I'm seeing are more *useful* lines of PHP code, not extra line 
breaks intended to satisfy some GNU standards definer.

Personally, I enjoy being able to see more useful code than line breaks, 
and I am intelligent enough to be able, using intelligently indented 
code, to follow a } up the the statement which opened the { on the same 
line.

As teacher I know from experience that programmers has a harder time 
tracking their own block with a number of {s dancing far out of sight 
in the right side of the screen.

Maybe they should be breaking up their IF logic into multiple lines
(PHP's OK with whitespace issues) so that things aren't 'dancing' off 
the right side of the screen.

if ($myvarirable1*myvariable2 = myvariable3*myvariable4+114)  {
   oneStatement;

The only people I've come across that like to use this oneStatement
trick are smart enough not to type { in the first place.  Myself, I
never use that oneStatement style, and always put a { and matching } 
immediately below it when coding.  Then I go back and put the logic
between the { and } markers.

 Why, then, are functions not written as
 
  function foo(parameter1, foo(parameter1, parameter2, ... parameterN) {
   statements
   ...
  }
  

We write our functions like that.  It seems many user comments
in the PHP manual use the same style, as do many of
the code snippets and samples on Zend.

Trying to base if block {} usage on the supposed uniformity of
function block {} usage doesn't hold much weight.  :(


I have yet to see anybody write

if expression begin
   statement;
   ...
   ...
end;


I'm not sure if you're trolling, or just don't go back very far in 
computers, or what...

BASIC seemed to be full of this stuff, and it made a decent
name for itself as a computer language.  Example:
(note carefully the placement of IF and THEN and END IF)

FOR i% = 1 TO 10
   IF yourScore% = playerscore%(i%) THEN
 FOR ii% = 10 TO i% + 1 STEP -1  'Go backwards (i%  10)
   playername$(ii%) = playername$(ii% - 1)
   playerscore%(ii%) = playerscore%(ii% - 1)
 NEXT ii%
 PRINT Congratulations! You have made the top 10!
 INPUT What is your name? , yourName$
 playername$(i%) = yourName$
 playerscore%(i%) = yourScore%
 EXIT FOR
   END IF
NEXT i%

(taken shamlessly from 
http://www.geocities.com/SiliconValley/Bay/5707/qbasic.html as I can't 
remeber much BASIC these days!)


As an amusing result of the weird practice it has been necessary to
recommend a standard where the { }-pair is always used, even though
there is only one statement following an if:

I don't find it amusing that, as a programming standard,
one is encouraged to *ALWAYS* use { and }, regardless of if there's
only oneStatement (see above).  We teach PHP courses, and trying
to explain to people that, well, sometimes you can use { } blocks
but you don't always need them is just confusing as all get out
to people just starting out with the language.  Giving them a
standard use {} blocks makes more sense to them and us.

BTW, in the classes, we do show both

if (foo) {
   echo foo;
}

and

if (foo)
{
echo foo;
}

styles.  I'd say about 60% or so wind up using option one, even though
option 2 is presented more, and the examples generally use style 2.

We can only hope that some major standard-setters for PHP should make a
rational decision about what standard to choose and not just keep what
we are used to for the disadvantage of future generations of programmers.

What if there IS a forthcoming 'rational decision' about {} usage from
all the core PHP team, and they choose the way you don't like?  Should
they codify the parser to not work with certain styles?  Why must
there be some magical consensus on something which, ime, doesn't have
as much impact on the language as ISAPI support, or better object 
handling, or stronger memory handling, or a myriad of other topics?


Michael Kimsal
http://www.phphelpdesk.com


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