Hacker News new | past | comments | ask | show | jobs | submit login

- 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




> 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.


I 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.


Like a react component?


i 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


That's an issue of design. You can't really blame the language for bad programming practices


You absolutely can and should. The language is responsible for the programming practices it promotes.


This 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.


> 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.


You 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.


How 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.


Laravel is the top choice for PHP frameworks these days which auto opts you into Blade. And just from my my own personal experience (so not necessarily a great sampling) every non-legacy PHP codebase I've been involved with on various teams had adopted other template engines with Twig being most common.

Also, to be frank, it's a real shame that people look down their noses at PHP so much just because of the sheer amount there is that can be learned about the practical application of design patterns from spending some time in the Laravel code base.


Smarty was prime to takeover the templating space in 2004 what happened?

PHP has had solutions from the beginning or at least early times.

PHP lacked that cult figurehead and was always community based. Most new languages are corporate sourced (open source by corporations).


Smarty is still around and well supported, but Twig is the top choice these days. Symfony is the 2nd most used "framework" these days, Twig is part of Symfony; then on top of that Symfony is really just a set of components (that work hard to adhere to current PSRs) so even projects that aren't Symfony projects will usually incorporate Symfony components as best of breed. Even Laravel relies on Symfony components.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: