Where PHP wins: Mixing code with content
You're typing along, pouring thoughts into text for your website, and you want to add a branch to the process, a little if-then statement to make it look pretty, say, depending on some parameter in the URL. Or maybe you want to mix in text or data from a database. With PHP, you open up the magic PHP tags and start writing code within seconds. No need for templates -- everything is a template! No need for extra files or elaborate architectures, just programmable logistical power at your fingertips.
Where Node wins: Separating concerns
Mixing code with content is a crutch that can end up crippling you. Sure, it's fun to mix code in with HTML the first two or three times you do it. But soon your code base becomes a tangled mess of logic. Real programmers add structure and separate the cosmetic layer from the logical layer. It's cleaner for new programmers to understand and easier to maintain. The frameworks running on Node.js are built by programmers who know that life is better when the model, view, and controller are separate.
Where PHP wins: Deep code base
The Web is filled with PHP code. The most popular platforms for building websites (WordPress, Drupal, Joomla) are written in PHP. Not only are the platforms open source, but so are most of their plug-ins. There's PHP code everywhere, and it's waiting for you to download it, modify it, and use it for your needs.
Where Node wins: Newer code means more modern features
Sure, there are thousands of great open source PHP files, but some are 8-year-old WordPress plug-ins hoping and praying that someone will download them. Who wants to spend hours, days, or weeks monkeying with code that hasn’t been updated in years? Node.js plug-ins are not only newer; they were built with full knowledge of the latest architectural approaches. They were built by programmers who understand that modern Web apps should push most of the intelligence to the client.
Where PHP wins: Simplicity (sort of)
There's not much to PHP: a few variables and basic functions for juggling strings and numbers. It's a thin layer that doesn't do much except move the data from port 80 to the database and back. That's what it's supposed to do. A modern database is a magical tool, and it makes sense to leave the heavy lifting to it. PHP is the right amount of complexity for a job that's not supposed to be complex.
Where Node wins: Complexity of closures and more
Where PHP wins: No client app needed
Where Node wins: Service calls are thinner than HTML-fat PHP calls
Where PHP wins: SQL
PHP was built to co-exist with MySQL and its many variants, like MariaDB. If MySQL isn't exactly right, there are other great SQL databases from Oracle and Microsoft. Your code can switch with a few changes to your queries. The vast SQL world doesn’t end at its borders. Some of the most stable, well-developed code will interface with an SQL database, meaning all that power can also be easily integrated into a PHP project. It may not be one perfect, happy family, but it's a big one.
Where Node.js wins: JSON
Where PHP wins: Speed of coding
For most developers, writing PHP for Web apps feels faster: no compilers, no deployment, no JAR files or preprocessors -- just your favorite editor and some PHP files in a directory. Your mileage will vary, but when it comes to banging a project together quickly, PHP is a good tool to use.
Where Node.js wins: Raw speed
- Attack of the one-letter programming languages
- 9 cutting-edge languages worth learning now
- 10 battles raging for the hearts and minds of developers
- 15 technologies changing how developers work
- 12 predictions for the future of programming
- 15 hot programming trends -- and 15 going cold
- Download: Apple Swift, a programming primer
- Download: The care and feeding of a rockstar developer
- Dev-olution: Saluting 19 generations of computer programmers
- 12 ethical dilemmas gnawing at developers today
- 15 workplace barriers to better code
- 9 key career issues software developers face
- Top 7 dilemmas facing today's developers
- 7 programming myths -- busted!
- 12 programming mistakes to avoid
- Safeguard your code: 17 security tips for developers
This story, " PHP vs. Node.js: An Epic Battle forDeveloper Mind Share" was originally published by InfoWorld.