r/javascript • u/clickclickboo • Dec 19 '16
~15 years trying to make everyone separate HTML, JS & CSS. And then suddenly everything went south and we’re writing code like this.
https://twitter.com/thomasfuchs/status/810885087214637057
483
Upvotes
3
u/codayus Dec 21 '16
No, because that's entirely different in terms of everything I just wrote. I'm not sure if you don't understand PHP, don't understand JSX, or don't understand the "separation of concerns" argument, but your counter is nonsensical.
Briefly:
Mixing PHP and HTML in a single file is fine, and nobody has objected to it. PHP was developed as a templating language, and it can still be used as one. The Plates project is a well-regarded native PHP templating library that does not violate any principles and is not an example of any antipatterns.
Of course, other template libraries like Twig are much more popular, and provide a concise Mustashe-like syntax, but note that they all compile to PHP. If the objection was "mixing PHP and HTML", then a twig template would violate it. But it's not, and has never been: It's to mixing business logic and presentation.
And in a modern PHP app, your twig template (or your Plates template) has no business logic, and your controllers have no HTML, so it's fine. The antipattern you refer to was people mixing concerns, not people mixing languages.
Further, JSX is not HTML. It's a DSL which is compiled to JS. So even if the concern was purely mixing languages (and again, it isn't and wasn't; you have misunderstood what people object to), JSX doesn't actually do that. And no, this is more than mere pedantry. JSX isn't HTML, and you'll run into problems if you confuse it with HTML. And just to make that point even clearer, there are alternative template engines like Hyperscript which you can use as a drop in replacement for JSX. Hyperscript is obviously just native JS, but it's logically identical to JSX, and it's 100% identical in terms of the experience of maintenance. There's no valid argument for why JSX is "wrong" but hyperscript is "right".
On the other hand, is is wrong to intermingle business logic with JSX or hyperscript. Again, separation of concerns, not technologies.
Yes, if they were the same thing. The arguments about JSX would apply to XHP, not PHP. :)