by kodemager · 4y ago · 0 comments
I’m mainly a C# guy myself as far as the backend goes, but I don’t view PHP as being bad in 2022. I think people who do are stuck in the past to be perfectly honest.
It’s sort of like disliking JavaScript because it really sucked the soul out of you before typescript eventually made it nice to work with.
But being mad at any programming language is sort of silly isn’t it? If it works it works.
PHP has always been considered as a somehow bad language in all corporations I've worked at to date. The same applies to other script languages such as python, ruby or nodejs - but PHP was the most undervalued of them all.
It's kinda strange because the language is really performant and relatively easy to use.
Maybe that's exactly why the big brain architects don't like it. They do tend to love things correlated with pointless complexity after all
Many of these decisions revolve around the authors not wanting their functions to fail under any circumstances. This is nice for beginners but quickly hurts more than it helps in larger projects as it obfuscates bugs.
But, if you genuinely want to know why some of us hate on PHP, I can tell you the reasons that I would never choose PHP for a production backend (now, I do think PHP is a fantastic scripting/sysadmin language- better than Python for sure, but I don't know Perl well enough to judge against that).
PHP is single-threaded. I feel like that's a pretty decent reason all by itself to not want to use it in an enterprise environment.
PHP is not really async, either. Yes, there are are run-loop libraries, and some libraries even claim to be async all by themselves, but these solutions are awkward and cumbersome and easy to use incorrectly.
PHP's array data type is ridiculously bad. In every conceivable way. If you want to use it as a contiguous, linear, collection, then it's slow and bug-prone (e.g., using array_filter, but forgetting to wrap it in array_values). If you want to use it as a dictionary, then it will sneakily convert your keys into numbers which doesn't matter until it does (like when trying to operate over filenames in a directory and someone named a file "1". Then you try to do some operation that expects a string and your code explodes several hours into its operation... Ask me how I know).
PHP's iterators and other, more professional-grade, data structures are not as "first class" as plain-old array, so nobody uses them. IIRC (it's been a while), you theoretically need to enable them in your php.ini and/or install them at the OS level, which kind of kills the whole "PHP is so easy to deploy! Just FTP a file and you're done!"-thing.
I prefer static typing to dynamic typing. PHP's static typing is weak (as in not strict enough) and not expressive enough for me (no generics, no sum types, no extending classes/types).
PHP does not allow for custom equality definitions. Also, since everything is references, I believe you can blow the stack if you try to check that two objects are equal that reference each other.
The architecture of every HTTP request getting a fresh instance of PHP is actually pretty nice. And a ton of work has been put into the language/runtime to make sure it's stupid-fast at ramping up and parsing the request data. HOWEVER, as soon as you slap one of these popular frameworks (Laravel, Symfony, etc) on top, you've basically ruined it and made it slow, with all of the extra framework initialization junk. I remember seeing engineering effort go into "compiling" Symfony code to make it load quickly (I don't remember how Laravel works). But think about that for a second- we're going to choose an interpreted language that can't cache any state beyond a single request, and we're going to add a COMPILE STEP to it?! So that we can work against the init-process-teardown cycle that it's designed for? Are we really sure we actually wanted to use PHP?
I used to have more specific complaints about strings and the numeric types, etc, but it's been a little while since I've had to write any PHP (I haven't used version 8, but I was using 7.4, I think, so I'm still fairly immune to the "You only remember PHP before it became awesome in 7+." criticism).
I'm more than sure that any regular PHP dev has no problem dismissing all of my complaints. Just like when I went to the doctor and told him my elbow hurts when I bend my arm. He told me to stop bending my arm! Problem solved. ;)
[1] https://www.i-programmer.info/news/98-languages/6758-the-rea...
Since you mentioned Python: I would never think of using Python instead of PHP, at least not for a web-based project. Performance-wise PHP is (I think) better thanks to all the work Facebook sponsored, and it has all the "batteries" needed for web development included, so the only reason for choosing Python would be that it's maybe more "elegant".
The performance improvements where not directly sponsored by Facebook.
But some old timers (genX) still today bemoan php as if it had no progress made.
I am balancing my love for it with the public perception I have seen over the years (fortunately I think much of the vitriol has waned sorta), in terms of how bashful I feel whenever discussing anything coding-related as to not overstate what I know/do. Most people, I think, grow out of php, so I see myself as a bad stereotype in still using it. But it has done a lot for me in terms of confidence building, being able to make things, the creative process of turning nothing into something, even though admittedly if I'd picked a different language I could likely say the same. But as far as staying with it, I feel like I look lazy for it, it just does what I want it to do. I am grateful for it. I hope this made sense.
I've recently tried to help out a friend who got stuck with a half-finished PHP project and a deadline to deliver, I have not touched PHP in 10 years and it still has the stench of a bad language from the get go - "modules" requiring VM config, "include" files ... what is this 90s ?
PHP might have had a huge patchwork competent people did to keep things working once projects using it grew enough, but coming back to it after 10 years it still felt like it was built on a foundation of shit.
Also, any language that is used in real life is built on a foundation of sh*t only. The component loading with python is so bad that I have programs keeping their own version of python and IDE suggesting I create VM for my project. The situation with C is so bad that no one can solve my linker problems unless I switch the toolchain version. For a long time Javascript was a (purpose built) toy language to sprinkle pixie dust on web pages. Any sufficiently complex problem requires either deep knowledge or following convention (tribal knowledge specific to the context)
That's from 2012 and many of the issues have been fixed since then, but it was the truth a decade ago and tainted the experience for many devs who have sine moved on to other languages.