October 31, 2022
What’s the best language for developing Web applications on IBM i – Python, PHP, or Node.js? That’s the loaded question recently posed by Mike Pavlak, who has been sailing IBM i’s open source waters for nearly two decades. As Pavlak’s presentation at the recent COMMON NAViGATE conference showed, the answer might surprise you.
Initially, Pavlak aimed to fight for Python in his “Web Language Shootout” session at COMMON’s NAViGATE conference, which was held in St. Louis, Missouri, last month, while his Perforce Software, colleague, Guido Faecke, argued for PHP and Liam Allan, who recently joined IBM, backed Node.js. When Allan was unable to make it, Pavlak and Faecke took it upon themselves to duel among themselves on behalf of the three scripting amigos.
Things devolved barely a minute into the hour-long session, as Pavlak stated, in no uncertain terms, that no punches would be pulled in this holy quest for technological supremacy . “That’s what this session is: A religious war of technology and languages,” he said.
“If it goes up really fast, there’s a chance it goes down really fast,” Pavlak said. “But if it goes up slow, if it’s steady, it’s probably going to be around for a while.”
Attentive readers may be asking, where is Ruby on Rails in the Web Language Shootout? After all, there is a distribution for IBM i. But Ruby, rails or no, didn’t make the cut, for reasons that would soon become clear to attendees. “I don’t do Ruby,” Pavlak said. “It’s highly irregular.”
Ditto for Java, which isn’t a scripting language at all but, according to Pavlak, may instead be a plot to make programmers hate their lives. “I don’t like it,” Pavlak said of the object-oriented language that hides in its own shell. “It’s like luggage. You can’t get rid of it. But it’s still…a wildly popular Web language, for all the wrong reasons.”
Which brings us back to the question at hand: Which is the best Web language? Python, PHP, or Node.js? According to Pavlak, there’s one aspect of Python that gives it a sizable advantage over the other two: every IBM i Web application developer is going to use it eventually.
“It doesn’t matter what language you select to do your technology in, whether it’s going to be Node or Ruby or PHP. You’re still going to use Python,” Pavlak said. “It’s part of the plumbing. It’s kind of like CL on IBM i. Python makes a lot of sense there.”
PHP holds the honor of being the first open source Web technology brought to the IBM i platform. But has a successful run of nearly 20 years bred complacency into the PHP customer base? Maybe just a little bit, Pavlak said.
PHP was created from the beginning specifically for developing Web applications. That gives it an advantage over Python, which is a general-purpose language that’s skyrocketing in popularity these days, due in large part to its adoption for big data and machine learning workloads.
Python has the benefit of being easy to learn. “Even if you’re an RPG guy coming over to this kind of stuff, Python is a really easy language to learn,” Pavlak said.
However, PHP holds the advantage over the other two in terms of the overall speed and simplicity of learning the language.
“To apply Python in a Web scenario requires to kind of reach around your back and scratch your elbow. It’s a little more of a complicated beast because it’s more of a CGI implementation,” Pavlak said. “If your goal is a Web workload, you’re going to have to give a huge advantage to PHP as being one that’s easier to learn.”
Pavlak and Faecke also delved into the performance aspects of the three languages. While there are certain differences among the technologies that impact performance, it’s not so much the technology itself but the implementation that matters most.
“At the end of the day, professionally I’ve worked in about six different languages. I can write bad code in every one of them,” said Pavlak, who identifies as a “recovering RPG developer.” “When people complain about the performance of a Web application, nine times out of ten, 99 times out of 100, go look at your database. It’s your database. It’s your indexing strategies.”
The fastest route to destroying the performance of your PHP Web application would be to use logical files in the database. “Do not use logical files in your SQL,” Faecke warned.
Node.js does have a significant performance advantage over PHP and Python in on particular category: How quickly the stack starts. The technology, which was created by Google, is widely used by massive Web properties, such as Netflix. When you fire up a Netflix session on your TV, your Roku, or your phone, you’re actually initiating the deployment of a Node.js instance running on AWS.
“Node.js starts so fast, it’s so much easier to scale…horizontally,” Pavlak said. “So AWS instances are basically X86. In that scenario, Node has a decided advantage.”
By comparison, PHP is slower to load than Node.js. Instead of half-a-second to start a Node.js session, a PHP session may take two or three seconds to start, Pavlak said. Will that be a dealbreaker for IBM i customers? Probably not, but it depends on what your application is.
“PHP fires up with all of the pieces and parts of the puzzle in memory at one time, and the reason PHP does that is, again, PHP is all about Web workloads. The goal is to have sub-second response times,” Pavlak said. “PHP from a startup standpoint is going to be slower than Node.js. But from an overall run perspective, it could be a little bit faster than Node because it has everything in memory.”
Most PHP on IBM i customers that Pavlak works with develop enterprise applications that run continuously. They’re not starting and stopping the application, like that Netflix backend. “So startup time isn’t necessarily a big deal for them, unless it’s constantly crashing,” he said. “And if it’s constantly crashing, their issue isn’t really startup times – it’s the crashing!”
PHP’s runtime footprint is bigger than Node.js, thanks to everything being loaded into memory. Since Node.js sometimes runs on smaller devices (not always on big old Web servers), it tends to be more conducive for “very precise applications,” Pavlak said. Edge and IoT applications may be more conducive to a Node.js stack, but how many IBM i shops are developing these on the IBM i stack?
One advantage held by Node.js is that it’s multi-threaded by default, Faecke pointed out, while PHP is single-threaded by default. Node.js also was the first to implement an asynchronous event loop, which can boost the resilience of Node.js applications – the Web page might freeze, but the application itself won’t crash. However, the I/O event loop has ceased to be an advantage exclusively held by Node.js.
“One of the things you see from an open source perspective is these languages tend to steal from each other constantly,” Pavlak said. “I joke around that a lot of the object-oriented features that have been added to PHP have been recommended by recovering Java developers. If you see something in the Java realm and all of a sudden it’s in PHP, it’s like crap, more object-oriented stuff.”
When it comes to selecting a language for developing Web applications on IBM i, there’s no shortage of options. As Pavlak and Faecke showed, there are benefits and drawbacks to using Python, PHP, and Node.js. There’s no winners to this religious war, because what works well for one particular IBM i shop may not work for another.
What’s most important, Pavlak said, is how you implement the technology. “When you’re talking about transactional workloads, whether it’s PHP or Python or Node, the reality is when demand is there, you need to be able to satisfy demand,” Pavlak said. “When you start getting into the world of the Web, it doesn’t matter what technology you’re using. You want to be really clever about how you architect things so you’re not chewing up a lot of I/O and bandwidth.”