4 ms·
I dislike PHP, but why did they purposely make the PHP example as horrible as possible? Like, they skipped short-tags, wrapped closing PHP tags, didn't use non-
by stevencorona 14y ago
I dislike PHP, but why did they purposely make the PHP example as horrible as possible? Like, they skipped short-tags, wrapped closing PHP tags, didn't use non-brace syntax (which is useful in templates), and didn't use a foreach loop like they did in the Python example.
<?php
for($i = 0; $i < $len; $i++) {
?><p>Foo <?echo $i?></p><?
}
?>
vs
<? foreach($foo as $i): ?>
<p>Foo <?= $i ?> </p>
<? endforeach ?>
I understand you want to sell your project, but don't make the examples deceiving.
- godDLL 14y agoI don't… I don't see much difference. ~$ python >>> A = "<?php for($i = 0; $i < $len; $i++) { ?><p>Foo <?echo $i?></p><? } ?>" >>> B = "<? foreach($foo as $i): ?> <p>Foo <?= $i ?> </p> <? endforeach ?>" >>> L = [A,B]; import re >>> map(len, L) [68, 65] >>> map(lambda x: len([s for s in x if re.match('\w', s)]), L) [23, 29] Isn't it about the same amount of alphanum vs noise? About the same length too. I'm not sure B is more readable than A in any way. Maybe more 'idiomatic', meaning 'way humans think'; but I'm not sure about that.
- chc 14y agoB is just a bit more cleanly organized. Somewhat like the difference between code that uses sensible indentation and code that uses deceptive indentation — they both look statistically similar, but the organization helps us read it.
- deleted 14y ago[deleted]
- chc 14y agoShort tags are widely frowned upon. IIRC they are deprecated in the current release of PHP and are due to be removed in the next major release. Not using them seems quite fair to me. (Incidentally, though, the <?= tags are now considered a fundamental feature and not part of the short tags syntax, so you can use those everywhere.)
- AdrianRossouw 14y agobecause they picked <? without realizing that those were being proposed/used as the xml parsing directives. hence they clash(ed) with xhtml.