In a recent SitePoint PHP vs Node.js Smackdown article, Craig Buckler compared how the two languages addressed a series of 10 challenges to decide which one was better overall.
Craig talks about in the book that these comparisons are always somewhat contradictory. As a fun follow-up, we asked Bruno Åkvorc (a PHP developer at SitePoint) and James Hibbard (a JavaScript developer at SitePoint) to provide comments on each round.
Here are their detailed thoughts...
Round 1: Get Started
Round 1 The challenge is to see how fast you can build a "Hello World" page in each language. This includes the time spent setting up the server environment.
In Craig’s estimation, PHP won this round in part because the language is “conceptually simpler” and “less intimidating to new developers.”
Bruno:
PHP wins the “Start” round purely because more hosts support the language so getting started is very easy. It's ready to use without having to do anything extra. If more hosts ignored using the Node command line and went straight to file uploads and a simple "reload app" key on the control panel, both would be the same. However, in terms of the actual syntax for displaying things on the screen, PHP is simpler - especially for those with no programming experience.
James:
I don’t see a huge difference between the two when developing on my local machine. To run PHP scripts in your browser, you need to install some server software; to run Node scripts, you need to install Node, and preferably a web framework such as express. However, as Craig said, PHP is "conceptually simpler ”.Node has a higher barrier to entry. There is no dispute about this.
Round 2: Help and Support
The second round will consider how easy it is to get help and support in both languages. PHP wins this round mainly because it has been around longer.
Bruno:
Keep silent about this.
James:
I agree with this statement. Node is a new technology, so for now, there will be less help. But when Node becomes more and more mature, this aspect will no longer be a problem.
Round 3: Grammar
The third round compared the difficulty of understanding the grammar of the two languages. Craig decided that Node won this round.
Bruno:
I strongly disagree with this point of view. There are indeed some quirks in PHP syntax, many of which have been fixed, and many more will be removed in new versions. On the other hand, there is also the problem of "this" in JS~
Regarding bullet 3 (when developing, using js you don't need to switch between client-side development and server-side development), I don't agree with this concept. The server environment and the client development environment are completely disconnected, and switching in the brain is still needed. There's always some new syntax that you can't use in the browser and vice versa, so it's also a language switch in a way.
Bullet 4 (Understanding JS will make you want to use it more) I agree with this to a certain extent. I've been using JS and PHP at work for many years, and JS for even longer, but I have little fondness for it - although that's purely a personal preference.
James:
I love JavaScript. I know it has its quirks, and I know for some reason that ECMAScript 2015 will shake things up and bring some exciting new features to the language. JavaScript is powerful and flexible, and can accommodate many different styles of programming. I enjoy using JavaScript as opposed to PHP. Node (Node.js) is one of them.
Round 4: Development Tools
Round 4: Considering the development tools used by these two technologies, Node is slightly better because it has the development tool npm.
Bruno:
Although developers were initially inspired by npm, now there are leaps and bounds that are more comfortable to use than npm, and if you have two versions of the same library installed on your computer, leaps and bounds are not Will crash your system. And compared to npm, leaps and bounds allow designers to use recursive thinking, and recursive thinking is so important that when developers are ready to build a package manager, this is the first thing they consider.
npm also has a fatal flaw, which I call "developer collaboration friendliness". npm cannot do this well. For npm, only the developers themselves can understand what they write. Finally, npm does not play well with Vagrant, which directly prevents you from starting to work on your own, not to mention that npm does not pay attention to the needs of users. There is a bug in npm that has existed for many years, which makes the software basically unusable on windows, which is not a small problem. Of course there are a lot of stupid bugs in PHP, but these bugs won't cause problems on your system.
It’s true that PHP doesn’t come with a compiler, but I don’t think it should. Such convenience should not be accomplished by a package manager or a standalone application. If one day someone develops a good package manager for Node, it will be extremely difficult to replace it with the existing compiler. Make it relatively independent and people can switch easily. Furthermore, installing it only requires typing a line of code into the terminal, or downloading an installer.
The statement in the book that the compiler has little impact is an obvious mistake. The compiler has impacted every new PHP developer since PHP was developed, and some of the best ones have had to add it to their existing pipeline. Just because there were many PHP users before the compiler existed doesn't make it any less useful. In fact, since its introduction, it has had a huge impact. The claims made by some that there would be "little impact on the community" have no basis in fact at all.
Now, I can't argue with the fact that most PHP developers want Node installed, that's a true fact. Sadly, many good tools were first developed based on Node, but I still hope that just like the Node-free development environment, it can also be used to develop BowerPHP.
James:
I’m excited to have people join Node.
I like npm. It's easy to install, easy to use, and has thousands of packages available for almost any need. I also like the fact that npm can select both global and local packages (compared to some languages like Ruby, where the standard requires your packages to be installed alongside your version of Ruby). Its tools are great too. Some tools, like Bower and Grunt, have a permanent place in my workflow and have increased my productivity exponentially.
It is also worth mentioning that npm has developed a beta version of version 3. It solves many of the problems Bruno mentioned, such as nested node_modules method errors, etc.
The following quote is from entire smackdown:
PHP developers may want (or need) to install Node.js on certain occasions. The converse is not true.
Round 5: Environment
Round 5 is about the availability and deployment of the technology, as well as which platforms and ecosystems support it. Craig isn't very clear on this, but seems to favor Node.
Bruno:
Craig said that he once compared the advantages of PHP and Node on the web (common web development problems), and then said that JS is used everywhere. First, we compare Node.js, not JS itself, and second, we compare the environments in which both languages can run. Monkeys are stronger than fish because fish are too stupid to climb trees, but both monkeys and fish can swim. So let’s compare how well they do.
In web development environments, PHP wins. Here are some PHP-based desktop program tools - yes, maybe you won't use them, but you will definitely use these PHP-based command line programs.
James:
Craig and I are on the same page again. Some of the features that have made Node.js so popular (speed, scalability, tight connection to JSON, low resource footprint) make it suitable for many other types of applications, such as powerful IoT devices. I think, who doesn’t like robots?
Node empowers projects such as NW.js (an application based on Chromium and Node.js), which allows you to write native apps on HTML and JavaScript. How exciting!
Round 6: Integration
In Round 6, let’s take a look at the integration of databases and drivers. PHP wins mainly because it is older.
Bruno:
In terms of integration, it is actually a tie. PHP has the advantage of age and can have more options, but it also means taking care of many outdated technologies, such as mysql extensions - we can upgrade to PHP7 to get rid of it, but Has been unavailable for years.
James:
I certainly agree with this, even though it seems vague, and I really like this example: "obsolete, more popular technology". This also highlights a great advantage of Node - its native support for JSON. JSON is perhaps the most important data transfer format on the web and is the common structure for the latest NoSQL databases. It is very easy to use JSON in JavaScript programs, which means that when you work with Node, the data can be transmitted very concisely, without the need for format conversion. You can pass between browser, server and database using only one syntax (JSON format).
Round 7: Hosting and Deployment
Round 7 will look at how easy it is to deploy a new application to a web server, and in Craig's opinion PHP is the clear winner here
Bruno:
Bruno is silent once again .
James:
This is an area Node needs to work on improving. Every company that offers web hosting offers PHP and MySQL. If you want to see the output, you only need to create a file with a ".php" extension, write some valid code between and ?>, upload it, and access it with a browser. But the same approach doesn't work with Node. Of course, there are many options for Node hosting, but they require more setup and command-line access, which can be unpleasant for beginners. There is no doubt that PHP won this round.
Round 8: Performance
Round 8 Mainly focused on speed. While this often comes down to experience and how dedicated the development team is, Craig noted that Node has advantages in some areas.
Bruno:
Mistakes abound. First, this article has a detailed discussion of performance, which excludes the impact of developer experience and application type on performance. If that article still doesn't convince you how foolish it is to talk about performance out of context, here's my point:
The discussion about performance is and will always be a draw (unless you are using Java, then Java will definitely lose)
James:
Node is famous for its high-performance and low-latency runtime environment. And it has also found its own way to embed itself into the code stacks of some Fortune 500 companies. Thanks to its non-blocking I/O mechanism and Google Chrome V8 engine technology, Node has now become synonymous with "fast" and "scalable". There are many stories on the Internet now, such as how Node allows companies to obtain better performance improvements and provides developers with higher productivity. I'm happy that node won this round, but I also understand that some people question this.
Round 9: ProgrammerComplex
In the ninth round, let’s see how much emotion Craig thinks the average programmer has towards PHP and Node. In the end, he thinks Node wins.
Bruno:
You must be looking at the wrong place, Craig, the PHP community is incredibly passionate and active, with over 20 conferences every year and very exciting topic discussions. This is how HHVM's PHP7 was completed.
Also, I would like to say that I am curious which version Node developers are working on (v0.12.5 has already been written), even after 6 years of development. This is immature and dangerous (gosh, you're using an unstable technology, are you deliberately letting your business die), plus it ignores some old bugs in the operating system and will cause some Important developers are leaving the language's ecosystem.
Some negative experiences made me dislike Node, mainly because of npm. That may change in the future, but right now every time I use Node I feel scared and disappointed. We all have our preferences, but it's important to stay objective and choose the right tool for the job. But it’s also important to allow others to try and make mistakes, because everyone is doing it in hindsight. So don’t listen to Craig, don’t listen to Jim, and don’t listen to me. Go ahead and experiment, see what works, and find what feels good to use. Ultimately, the best ones are the ones that make you feel productive, not the ones that just save some load time.
James:
Node is very popular and there are a lot of innovations in the field of Node. Although passion is not objective, I am happy that Node won this round.
Round 10: The Future
Round 10 looks at the prospects of both languages, and with both languages looking to have a strong future at this stage, Craig concludes that the result of this round is a draw.
Bruno:
Bruno has to hurry up and write more articles about PHP and maintain the amazing SitePoint PHP channel.
James:
James also can’t wait to get back to his beloved JavaScript channel, but he left with these views:
A draw is fair for this round. Node is a rising star, but it has a lot of work to do if it wants to dethrone PHP.
In summary, if a hammer is your only tool, every problem looks like a nail. Node is not perfectly suitable for every solution. Of course, it is very reasonable not to use Node in many cases. However, what Node can do, it can do extremely well. It's entirely up to you to make an informed decision and choose the best tool for your project.
Now that Bruno and James have expressed their opinions, what do you think of this issue?
Bruno Skvorc
Bruno, a Croatian programmer, holds three master's degrees in computer science, English and literature. He is a PHP columnist for SitePoint and a development evangelist for Diffbot.com. He avoids legacy code like the plague and picks projects that use the latest technology. He is also a treadmill desk enthusiast and gamer. He has a blog: sometimes blogs.
James Hibbard
I am a website developer currently living in sunny northern Germany. I love programming in JavaScript and Ruby, and you can often find me on SitePoint's javascript forum. When I'm not coding, I enjoy running.
The above introduces the 10 comparative challenges between PHP and Nodejs, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.