> Now why no one bats an eye at node/react doing this very thing and calling it JSX is beyond me but...
Hey don't drag Node into this, you aren't forced to do any of that.
React to me feels like SPA developers discovering the idea of PHP and thinking they invented it. This shouldn't be surprising, since React came from Facebook, and Facebook historically is a PHP shop.
Mixing your business logic and presentation is a bad idea, but it's very attractive when you don't have the informative scars
You might say, doesn't Facebook have the scars to avoid designing React? Well, when you have a hammer, everything looks like a nail.
PS: I would suspect the down voting is just the "LOL", otherwise it's a fair comment.
It works great, it's fast and you don't have to learn a new templating language or dialect every 2-3 years. Or try to figure out how to do trivial things like loops in loops.
I don't quite get the use of templating engines in PHP because PHP is a templating engine itself.
In PHP, “HTML" is string concatenation; in React, “HTML" is an HTML-flavoured bit of syntax sugar over HTML-generating functions (and you are still welcome to call the functions yourself, if you want your HTML-generation code to avoid looking like HTML). Aside from looking kind-of similar if you squint, I’d say the differences and pros and cons are fairly significant (For example the IMO worst thing about the PHP approach, the ease of shooting yourself in the foot with XSS holes, is a non-issue in JSX).
It did make total sense at the time. Consider we are talking a time where you had static html.
It is obviously good to be able to automate generating web pages based on say the state of a database. As this gives you up-to-date pages without someone having to manually build them.
And if that - automatically build web-pages from a database - is your goal and your current state of the art is static pages, then creating a language you can interject into your static pages, to build the page dynamically is a no brainer.
> PHP mixed with HTML was one of the "bad ideas" that hurt PHP. It was a bad practice that got out of hand.
So what, JSPs are just the same. In the end what matters is the speed to Get Things Done, and there's utterly nothing competing with PHP, closely followed by Tomcat+JSP as you can use the insane amount of interfaces with just about everything that the Java world has.
> PHP mixed with HTML was one of the "bad ideas" that hurt PHP. It was a bad practice that got out of hand.
If you think of PHP as prototype-only, mixing tags and HTML is very convenient, like it is with the other thousand templating tools. And obviously it's more a problem of XSS through badly sanitized inputs more than the mix in itself, blah blah blah
It's PHP in production a bad practice that got out of hand.
You're getting downvotes, but that genuinely puzzled me the first time I saw JSX. ("This looks a lot like 'include("form.php")' in old-school PHP. What am I missing?")
Turns out I wasn't missing much. I've mentally pegged it as an example of "the pendulum swings" - thin client vs thick client, centre vs edge, tight coupling vs loose coupling, etc.
zer00eyz|2 years ago
The fact that I can't tell if this comment is sarcasm or snark or serious says a lot.
PHP mixed with HTML was one of the "bad ideas" that hurt PHP. It was a bad practice that got out of hand.
Now why no one bats an eye at node/react doing this very thing and calling it JSX is beyond me but...
rezonant|2 years ago
Hey don't drag Node into this, you aren't forced to do any of that.
React to me feels like SPA developers discovering the idea of PHP and thinking they invented it. This shouldn't be surprising, since React came from Facebook, and Facebook historically is a PHP shop.
Mixing your business logic and presentation is a bad idea, but it's very attractive when you don't have the informative scars
You might say, doesn't Facebook have the scars to avoid designing React? Well, when you have a hammer, everything looks like a nail.
PS: I would suspect the down voting is just the "LOL", otherwise it's a fair comment.
FriedrichN|2 years ago
It works great, it's fast and you don't have to learn a new templating language or dialect every 2-3 years. Or try to figure out how to do trivial things like loops in loops.
I don't quite get the use of templating engines in PHP because PHP is a templating engine itself.
Shish2k|2 years ago
In PHP, “HTML" is string concatenation; in React, “HTML" is an HTML-flavoured bit of syntax sugar over HTML-generating functions (and you are still welcome to call the functions yourself, if you want your HTML-generation code to avoid looking like HTML). Aside from looking kind-of similar if you squint, I’d say the differences and pros and cons are fairly significant (For example the IMO worst thing about the PHP approach, the ease of shooting yourself in the foot with XSS holes, is a non-issue in JSX).
bemusedthrow75|2 years ago
Indeed.
pintxo|2 years ago
It is obviously good to be able to automate generating web pages based on say the state of a database. As this gives you up-to-date pages without someone having to manually build them.
And if that - automatically build web-pages from a database - is your goal and your current state of the art is static pages, then creating a language you can interject into your static pages, to build the page dynamically is a no brainer.
mschuster91|2 years ago
So what, JSPs are just the same. In the end what matters is the speed to Get Things Done, and there's utterly nothing competing with PHP, closely followed by Tomcat+JSP as you can use the insane amount of interfaces with just about everything that the Java world has.
mrkeen|2 years ago
PHP receives its share of criticism, and HTML lives on relatively unscathed.
So if mixing PHP/HTML is a problem, you'd probably throw out the PHP and keep the HTML.
Also, isn't this use case PHP's origin? A dev wanted some programmable HTML?
crabmusket|2 years ago
Because it's not "this very thing". HTML around PHP is output directly to stdout. JSX is just syntax for literals.
foul|2 years ago
If you think of PHP as prototype-only, mixing tags and HTML is very convenient, like it is with the other thousand templating tools. And obviously it's more a problem of XSS through badly sanitized inputs more than the mix in itself, blah blah blah
It's PHP in production a bad practice that got out of hand.
flir|2 years ago
Turns out I wasn't missing much. I've mentally pegged it as an example of "the pendulum swings" - thin client vs thick client, centre vs edge, tight coupling vs loose coupling, etc.