6 ms·
- 9 ways to do same thing in PHP api - worst way to do templating - weird mental model of putting all logic and templating in one file
by techsin101 4y ago
- 9 ways to do same thing in PHP api
- worst way to do templating
- weird mental model of putting all logic and templating in one file
- Octoth0rpe 4y ago> weird mental model of putting all logic and templating in one file That's up to you though. You're welcome to put all your logic in one file and your templating in some other file.
- techsin101 4y agoI guess but that brings to next point, varying approaches to this problem in the wild, and since all are valid, codebases seem to have all of them.
- ipaddr 4y agoLike a react component?
- techsin101 4y agoi dont like react but even in react there is clear distinction, I've found tons of logic within templates of php like from <?php to ?>.. anything at anytime could cause anything. Kinda gives me global variable vibes
- bigtunacan 4y agoThat's an issue of design. You can't really blame the language for bad programming practices
- lmm 4y agoYou absolutely can and should. The language is responsible for the programming practices it promotes.
- bigtunacan 4y agoThis is just so far from the truth. I can just as easily push tons of logic down into templates in erb/jsp/jinja etc... at some point it boils down to the programmer's level of expertise, but also to the programmers' opinions as there are still a lot of varying opinions on what exactly are best practices.
- lmm 4y ago> I can just as easily push tons of logic down into templates in erb/jsp/jinja etc... Not just as easy if they don't allow you to insert arbitrary code at arbitrary points as PHP does. Personally my preferred approach is Wicket where you can't have any logic in your markup at all, all of your logic lives in code and the only thing you can put in the template is IDs for where the code can insert child components or plain text. (OK, it's not quite that strict, but it gets pretty close in practice). > at some point it boils down to the programmer's level of expertise, but also to the programmers' opinions as there are still a lot of varying opinions on what exactly are best practices. That's neither here nor there; "programmer's level of expertise" is just abdicating responsibility, when in fact a programmer at the same level of expertise might produce much better code in one language than another.
- bigtunacan 4y agoYou seem to think that you refuted my argument, but instead you reinforced it. By using Wicket you are making a choice to opt in to a template system that encourages best practices. This is the same reason people in the PHP ecosystem opt in to Twig/Blade/Mustache, or how people on Ruby opt out of ERB for Slim or Haml.
- lmm 4y agoHow many of them, and how well does the ecosystem support them in doing so? It's theoretically possible to write good code in any language, sure, but in practice the language (not just the formal syntax, but the tooling, ecosystem and community, the whole culture of the language) has a lot of influence on whether people write good or bad code in it.