4 ms·
While you can theoretically get to this level of simplicity with various tools I think the difference isn't so much "can it be this simple?" so much as "does th
by seangrogg 7y ago
While you can theoretically get to this level of simplicity with various tools I think the difference isn't so much "can it be this simple?" so much as "does this level of simplicity fit my needs?" and that can be harder to quantify.
The same thing you wrote in PHP done in Node.js in an arbitrarily named file served from root:
require('http').createServer((_, res) => res.end('Hello World')).listen(80);
Zero configuration. You could trivially add some lines from 'fs' to get it to read files instead and whenever you update those files it'll automatically serve the new ones. The problem isn't that it can't be simple. It's that the people cutting checks (or at least the people informing them) also want SSL, non-static pages, sanitized inputs, an attractive interface, log retention, data persistence, ease-of-access, etc.
If people were paying me my current rate to send their users unstyled static text over HTTP I'd gladly walk away from all the process. But if they want me to maintain my sanity while writing a non-trivial web application I think integrating a type checker pays off after the first few thousand lines of code. And if I know things are going to get there from the outset then setting it up in advance isn't exactly insanity.
- deleted 7y ago[deleted]
- lhorie 7y agoEh, that's not a great example. It can be hard to appreciate the simplicity of PHP when one's fully bought into the stockholm syndrome of another language/framework :) Consider this: a hello world in PHP requires no knowledge of programming whatsoever: a file saying "hello world" is enough to get the text to show on a browser. Having two different pages requires no knowledge of if statements, nor of 404 handling. On top of that, PHP silently manages a lot of plumbing for you: it will also do caching and streaming out of the box and it won't crash the server due to OS ulimit errors when you have a high number of concurrent requests hitting the same file. Heck, you could stream result sets from a database to a streaming HTML document in like a dozen lines of PHP with no libraries 10 years ago. The equivalent machinery to achieve something similar in e.g. the latest Next.js today is beyond abysmal in comparison.
- egeozcan 7y agoDepending on what's serving PHP it can also get complicated. Everybody can't stop talking how easy it was to cobble up something in shared hosting days, but don't forget that back then only option was pretty much Apache and even that was enough to give you headaches because of different modules being activated, your htaccess file being incompatible and so on. Also: You are a kid, wanting to program something on your new (typically) windows pc you got for your birthday, is it easier to get started with PHP than other alternatives? What about html and js?
- lhorie 7y agoSure, PHP deployment could run into some issues back in the day - remember magic quote configuration issues in rando hosts? But even that was something you could get around relatively easily (mostly thanks to the stupidly beginner friendly docs). These days, hosts can easily drop in a PHP hosting pre-packaged solution, so you'd be hard-pressed to find a PHP host without a reasonable configuration. As for pure beginners, if your goal is to get pretty things on screen, HTML + CSS is fine. But if you asked me to pick between PHP and Node.js (or any other language, for that matter) for teaching a kid about server-side web programming, I'd pick PHP in a heartbeat. You can't even get past posting a form in Node.js without having to reach for NPM :) In fact, PHP is how my brother (who went to business school) converted to a programming career.
- numlock86 7y ago> a file saying "hello world" is enough to get the text to show on a browser Wrong. A file saying "hello world" does not even serve its contents through HTTP on port 80, contrary to the node.js-example you are arguing against. Good luck setting up that Apache monstrosity (as it was common back then) without any "programming knowledge whatsoever". But yeah, I guess your mentioned stockholm syndrome is a thing for PHP people, too.
- lhorie 7y agoIt sounds like you've never actually used PHP. Even way back when, you could pick from multiple pre-packaged solutions (XAMPP, WAMP, etc). In windows, the installer was a no-brainer click-through wizard, much like any other random software you'd find on sourceforge or whatever. And not only it would setup apache, but also mysql. Then you could click a button to turn on PHP (so no need to type anything in terminal either). You could also get hosting and upload your PHP files via a browser interface to put your hello world live on the web without ever typing any "code" other than the text "hello world" on a index.php file in notepad. Not even knowledge of version control was required for this form of deployment (though, of course, you can also follow standard industry best practices like with any other mainstream language).
- deleted 7y ago[deleted]
- adamzochowski 7y agoI think OP's point was that for starting developer PHP is super easy. - edit a text file with any text editor (notepad?) - copy file onto a server (ftp? scp? git push? -- most servers will process php) - access it through url in browser The example was about simplicity. OPs text file is 11 bytes long "Hello World", and is a valid PHP, it will run on a server. This is about how easy a person with no knowledge and no special tools can start doing things. Your example implies that developer has node installed, and expects the developer to run a server from within node, and then understand how the server handles URLs to functions. Additionally, I don't know how an early developer is expected to get this onto a server. First copy, then ssh onto server, then start the node server on server. That is a lot of steps for beginner to remember. Additionally, as you mention, changes to file require server restarts, or building a self reload capability. I play with Flask, which has self reloading available, when developer pushes broken code Flask can just crash (self reload fails), and then developer has to start flask again. With PHP, broken code does not crash apache/nginx. For developers that live and breathe computing knowledge running things through additional steps make sense. C/Java/C++/C# all have compilation and linker steps. Things like Grunt or Less are nothing scary for developers that ran C/C++ code through M4 preprocessors before compiling (now M4 is built into compilers). So yes, for professionals, PHP is just a programming tool as any other. But for beginners, PHP is awesome easy to grasp and use.
- seangrogg 7y ago> Your example implies that developer has node installed, and expects the developer to run a server from within node, and then understand how the server handles URLs to functions The OP's example implies that the developer has Apache and PHP installed at a minimum and that Apache is set to proxy requests to PHP. This requires SSH and starting Apache. I remember doing this back when I first configured my first LAMP server, though most hosting companies will do this for you and usually as part of a cPanel setup (even more dependencies). > Additionally, as you mention, changes to file require server restarts, or building a self reload capability In fact, I said just the opposite.