note 95804 deleted from control-structures.alternative-syntax by danbrown

From: Date: Fri, 22 Jan 2010 15:19:49 +0000
Subject: note 95804 deleted from control-structures.alternative-syntax by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-165213@lists.php.net to get a copy of this message
Note Submitter: BoonHead.nl ---- 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.

« previous php.notes (#165213) next »