In [thread=710377]this thread about creating $_POST arrays[/thread] the question of when is it too early to bring up concerns such as separating business logic from presentation came up. I think it’s a valid concern for discussion here as this forum is a great place to learn about PHP and I’d like it to stay that way.
Often I don’t comment about such concerns when it’s clear that the OP is just coming to terms with the language. Some topics valuable to large scale dev are just, well, too much too soon in my opinion. That isn’t to say these concerns don’t need to be mentioned, but sometimes it’s best to gloss over them if they get brought up at all.
One reason I worry about it is that it can lead to the wrong impressions, and misapplying principles can be more harmful than not applying them. Take smarty for example.
Smarty templating is about the dumbest thing you can do to a PHP application. It introduces the concept of separating presentation from business logic but goes overboard by trying to separate PHP from HTML, a fool’s errand at best and a destructive influence on the lives of many programmers especially since it entirely misses the point – separate business logic from presentation.
Thing is, Display still has logic to it.
<? foreach( $table as $row ): ?>
<tr>
<td><?= $row['cell1'] ?></td>
<td><?= $row['cell2'] ?></td>
</tr>
<? endforeach ?>
This is quite valid, even necessary, but this basic example becomes an impenetrable mess in another syntax if smarty is used because smarty is, well, stupid.
When starting out though do we really need to worry about this sort of thing? Or perhaps, did we? I know I didn’t. It’s been a long 7 years getting to where I am now with this stuff, and while I’d like to save others from the painful stumblings I’ve had on the way, in the end those are necessary to truly grasp.
Yes, I once used smarty too :\
But anyway, I think it can be harmful to try to drive home this idea of “separate business logic from presentation” too early, especially before the student has a grasp of what constitutes “business” logic and “presentation” logic. Without that distinction the student conflates the two to “logic” from “presentation” then disasters like smarty happen.
And that’s not the only pitfall.
Don’t spare the novice the education of doing things wrong. Sometimes learning the details is useful. For example, I find my lessons in C++ data structures useful though I don’t code in C very often. While I use PDO now, the days of using my own Database interface on top of mysql (and later mysqli) was invaluable to me to understanding the language.
Just random thoughts this morning.