note 95804 added to control-structures.alternative-syntax
| From: | BoonHead dot nl at osu1 dot php dot net | Date: | Fri, 22 Jan 2010 15:04:07 +0000 |
| Subject: | note 95804 added to control-structures.alternative-syntax | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-165210@lists.php.net to get a copy of this message | ||
In reaction to spa's comment on 16-Oct-2007 11:40.. This is why you use indenting like this:
<?php
if (true)
{
while (condition())
{
echo("bla");
}
} // if (true)
?>
Notice that all sides of the "box"/code block have the same hight/indenting. This way you
can easily see where the code block should end, track if you are missing a bracket, and on top of
that, you don't even need to read the code to see if you're missing something. The closing
bracket should be on the same level as the opening bracket, etc..just by selecting one bracket and
scrolling downwards to the next.
In extreme cases you can put a comment line at the closing bracket like shown in the example but I
almost never need it because of good overview.
In my opinion, this kind of alternate syntax does not add to a language. I even argue that, having
multiple ways to do exactly the same thing, can make a language more messy, the parser a tiny bit
slower/bigger, beginners more confused, alternative parsers incompatible, etc..
mido_alone2001's example (07-Nov-2008 02:05) has two flaws. First, the use of } or endif; has
nothing to do with being able to use HTML within PHP or HTML outside of PHP code. Second, the HTML
in your second example contains PHP code not being high lighted because a short PHP open tag was
used; I believe this will still be parsed/compiled thus can not be considered one solid chunk of
HTML.
flyingmana (26-Mar-2009 09:43) made a very good point by comparing the two syntaxes. But I
don't agree this creates a better overview. In my opinion overview is create by everything but
the text/code, keeping a strict structure, like a book with a index, chapters, paragraphs,
punctuation, appendix, etc.. not by using different words to describe the same thing. Even a best
seller is lost without its structure.
Same goes for PHP functions like:
<?php
strpos(string $subject, mixed $find)
explode(string $delimiter, string $subject) // $subject is suddently the last argument.
strtr(string $subject, string $find, string $replace)
str_replace(string $find, string $replace, string $subject) // $subject is suddently the last
argument.
?>
Logic dictates the $subject is always the first argument. It's the only constantly supplied
argument we know. This way you would almost always know the sequence of the arguments, making far
less mistakes and makes not having to reference the manual as much as people would do now.
Humans are organic/psycho-logic, computers are binary/logic. Sure you can mix those two
together..But I would not recommend it.
----
Server IP: 69.147.83.197
Probable Submitter: 84.106.198.80
----
Manual Page -- http://www.php.net/manual/en/control-structures.alternative-syntax.php
Edit -- https://master.php.net/note/edit/95804
Del: integrated -- https://master.php.net/note/delete/95804/integrated
Del: useless -- https://master.php.net/note/delete/95804/useless
Del: bad code -- https://master.php.net/note/delete/95804/bad+code
Del: spam -- https://master.php.net/note/delete/95804/spam
Del: non-english -- https://master.php.net/note/delete/95804/non-english
Del: in docs -- https://master.php.net/note/delete/95804/in+docs
Del: other reasons-- https://master.php.net/note/delete/95804
Reject -- https://master.php.net/note/reject/95804
Search -- https://master.php.net/manage/user-notes.php