Does python have more power than php?

I agree completely, but you can’t deny the fact that it’s what a lot of PHP developers will turn to when building a website. There are loads of huge websites, including this one, built on what you (rightly) call a “lazy mans pile of crap code”. Django and Rails aren’t perfect, and they aren’t suitable for every project, but there is still choice out there, and the choice is a lot better than WordPress.

Yes, Symfony, CakePHP, Zend, and the others have come a long way, but only really in response to the likes of Rails and Django. They are playing catch-up, and considering the maturity of both Ruby and Python before they became suitable for web programming, both have a considerably head-start on PHP in terms of building clean, usable code.

My main point is that the language itself enforces the need to run a framework in order to get the code running. With PHP, many shared servers are configured to just run a PHP file that has been plopped onto a server. While very useful, it’s led to some monstrous code. You can’t just upload a *.py or *.rb file onto a server and run it without something to help run that code.

The word “powerful” is too broad and could have many meanings, so I can’t give specifics. But I do feel like I should comment here:

I’ve done plenty of PHP coding and have almost 10 years of web development experience behind me already, and recently I decided to update my skillset and start learning Python and DJango and using Bootstrap. I’m still a “noob” with all three of these specifically, but from a noob’s perspective, I can see that what I’m learning now is surely going to enable me to get projects done way faster than what I’m used to. Fresh built-from-scratch ideas that would have taken months to complete should now only take weeks, or maybe even days. Being able to get a stable and satisfactory solution completed faster than the next person is an attractive skill to have. Not only does it enable you to materialize self-owned projects at a faster pace, but clients and employers will be more likely to offer higher paying opportunities because you’re the candidate who gives them the biggest bang for their bucks. Thats quite an empowerment.

^ but that’s more an argument for frameworks rather than much to do with the language.

A friend of mine said pretty much your words when describing doing a project using PHP, CodeIgnitor and Bootstrap.

What makes Ruby harder to learn for a complete beginner is that it forces OO concepts and ways of thinking/doing things.
PHP allows you to program procedurally or OOP, or both.

Learning OOP and when and why is tough for a lot of more experienced people, so dumping all that on a beginner can be very overwhelming.

I believe that it is easier to learn how to program by doing so procedurally at first – you learn how to do all the basics in the language. Then eventually when you have the hang of it, you start figuring out on your own that “there must be a better or easier way of doing X”.
When you reach that point, you are ready to jump into the awesome world that is OOP.

As for Ruby or Python displacing PHP…well, we’ve been hearing that for nearly a decade now, and PHPs usage continues to expand. It’s currently running 81.6% of websites in the world…in that regard, it is the Windows of the web development world

I hate it when people use this as a point of PHP being something.

Sure, a lot of webpages use PHP. Crappy little home-town business websites running on Wordpress, Joomla, or maybe Drupal. And there are a lot of them, they probably outnumber everything else 1000 to 1. But quite a large portion of web applications or functional websites run on something else. Be it ASP.Net, Python, Ruby, Node, or the JVM.

PHP has it’s place and it’s place is being highly portable and having everything there out of the box. But IMHO, if when you start looking at using Frameworks or anything like that, you’ve already stepped too far out of what it should be used for.

I just finished a small single page PHP script yesterday that totaled in about 150 lines. It accepts a file transfer from a remote server and resizes it and stores it. There really wasn’t anything better than PHP to use, because the heavy lifting is being done by Imagick anyway and anything else would take more overhead to get running. The server does absolutely nothing else but store and serve these images. This sort of thing is what PHP is good at and all it should be used for, or when you want something to run on basically any web server configuration. It’s just slow and if you get past that, it’s still messy, fragmented, and just all around clunky.

No serious development shop is going to even consider PHP for anything else.

There really wasn’t anything better than PHP to use, because the heavy lifting is being done by Imagick anyway and anything else would take more overhead to get running.

In other words, this could have been written in about 2 lines of Perl code and instead of PHP imagemagick you could have used PerlMagick :stuck_out_tongue:

Where PHP beats out most others for these one-off scripts is the cheap-hosting area. Trying to get Python, Ruby, Perl or anything else where you’d like some libs/modules is a pain in the butt/not possible with most of the el-cheapo hosters-- and these are exactly the hosting companies you’d want to use for something small, quick and probably temporary (months to a year rather than years and years).

I’ve seen some raves about a decent (PHP) CMS, Bolt. Since developers are continuing to search for the holy grail of “a CMS that doesn’t suck”, and since everyone who’s ever touched PHP seems to have made a CMS somewhere, it’s probable that some less-sucky-than-all-others CMS will be the reason some company chooses PHP.

I work in e-commerce, which by us happens to be Python, but most of our competitors are using Magento, which is PHP. There aren’t too many open-source e-commerce solutions with any robustness, so for example pretty much any non-homegrown e-commerce setup will be using PHP-- again because of the software needed (Magento), not any particular merits of the language.

As someone who contracts on a regular basis for the largest studio in Maryland, I have to say that you are talking out of your rear when you say no major shop is going to consider PHP.

Perfect example of that is how we recently compiled portions of their brand new site into a PHP extension. Why? Because neither PHP nor Python nor Ruby can run some of the core functions of the application fast enough. PHP is much more than a toy language with limited use cases. If it’s good enough for Facebook and Wikipedia, it’s good enough for “serious projects that companies would never consider PHP for”.
The new projects this company brings in…PHP outnumbers Ruby and Python COMBINED by a ratio of 4:1 as of last month. And these are not some backwoods, insignificant websites / applications

I woulld start with PHP.
Easiest language to dive into more advanced concepts in, once you get the hang of basic programming concepts…in other words, it let’s you learn at your own pace, rather than forcing abstract concepts on you from the beginning.

Before the Perl and Python guys get riled up, it doesn’t necessarily mean PHP is a better language, all it means is that it is friendlier to new programmers than other languages are.

I can fit square pegs in round holes all day long with a knife. If the knife is sharp enough, I can probably get them to fit pretty damn well too.

That doesn’t mean I shouldn’t probably be using the square holes instead.

I don’t know what Facebook’s thing for PHP is, where almost every other major site has moved away from their prototyping language into something stronger… but they have done some pretty damn impressive work re-shaping that round hole to better fit square pegs.

Wikipedia has been around long enough where PHP was the hot new language that was way better than custom CGI code. I know they run on a very small very talented development team, so this probably explains why they haven’t switched.

I don’t mean to come off rude, but you are not actually saying anything.

How exactly is PHP inadequate and Perl / Ruby / Python / etc clearly superior? I want to hear real business world reasons; not petty (even if they are legitimate) gripes like “this is a MORE pure OOP language” or “this is a better designed language”.
Nobody who has any programming background would ever argue that PHP is as well designed as Python or Ruby. But in the real world where results count…there are very good reasons why PHP towers above everything else from a usage standpoint, just like there are good reasons NOT to use PHP and run with Rails instead.

I must sound like a PHP apologist…for reference, I am employed full time as a C programmer, but I do have extensive knowledge of PHP and Python as well (C programmers pretty much have to know Python these days), and intermediate capabilities in Ruby.

In my last post I was making an analogy referencing the post I made before that. Knives being the developers. It has a purpose and just because you can make it work for other purposes, doesn’t make it the best fit.

You say that OOP is petty, but it’s very real for the context that I think PHP falls the shortest. I have never seen or worked on a large PHP application that didn’t behave and act like a conglomeration of random scripts working in unison, rather than a cohesive logical application. Everything is incredibly fragmented and displaced, it’s just a mess. The language was never designed to support lots of code or lots of developers and it shows. Even the tacked on OOP that came in 5.x did little to fix the issue.

Can talented programmers overcome this? Of course. But needing talented programmers to overcome the shortcomings of a language is pretty silly.

This is what I meant by the square pegs and round holes. Even Facebook named their version of PHP “Hack”, but the name fits nice for vanilla PHP since almost everything you do with it is a hack in one way or another. Including it’s poor implementation of objects. Though, from what I understand they have addressed the issue of poor object implementation but I haven’t used it.

Other than that, there are plenty of shortcomings of the language that are widely talked about and widely known. Too numerous to name here, but you can use Google. Often you hear that “only bad PHP programmers do these things” or “good PHP programmers know how to work around that”, which I find to be really sad. Why should you have to know a language inside and out to work against logical fallacies and make them function properly and efficiently? Why should your brain have to work in ways it really shouldn’t, to solve things “the PHP way”? Shouldn’t the language itself guide you into the proper directions? Python does this and that’s one of the main reasons why it’s considered the best language to learn in and taught as the introductory language in CS in almost every single CS course in the entire US and UK.

Even though I haven’t done much more than some advanced Hello Worlds in Python, I think that the fact that in the real world the programmer doesn’t constantly fall into traps or constantly do things “the wrong way” in a language, makes it better for real world cases because code just runs better without needing the programmer to know every little quark and caveat of the language to get it to work in the right way. Again, we’re back to the needing talented programmers to make the language really useful again… :nono: because like you say below “the real world where results count…”

I’m not even going to mention the poor unit testing abilities in PHP. Who uses testing in the real world anyway? :shifty: I would bet money that HHVM works to solve some of this though, but I don’t know for sure.

It towers because it was one of the first languages to break out of pure CGI programming and custom scripts, which if you’ve ever worked with is complicated, convoluted, and just an all round misery to work with. That and it wasn’t Classic ASP in Visual Basic. I think we can agree that was just a pile of horse manure.

My favorite quote about a CGI Application:

I still have to work with some IBM CGI stuff from the 90’s almost daily. I can attest to being in a similar situation.

Today PHP has been around for so long and become such a staple of the internet, it’s incredibly easy to get running and runs seamlessly alongside other technologies. I mean if you have a webserver, is there really any reason why you shouldn’t have PHP at least installed? People like to complain about how hard it is to get running in nginx and php-fpm, but really that isn’t even that bad.

Basically, it’s the lowest hanging fruit.

You keep hitting on Ruby… but I actually don’t see a reason for RoR to exist for any other reason than some people like to program in it. It doesn’t fill any gap what-so-ever and it runs worse than PHP. Rapid prototyping I guess, but that’s irrelevant because PHP and Python both work well for that. I honestly don’t know, I don’t know the language and I have 0 desire to learn it. It’s one of the few languages I really have no desire to ever touch. I know it was one of the first good implementations of MVC, but that was a while ago and it’s still around.

I think I might jump in here a bit.

Can you be specific? How so? It’s entirely possible you’re right, but we’ll need to go deeper than generalities and analogies.

That’s correct. Since 2004, there’s been a fully capable and even Java-like OOP feature set.

Never? They’re definitely out there.

There are probably a few factors that affect the quality of code – broadly speaking – within a language’s ecosystem.

If a language attracts lots of newbies, then that can lead to bad code within the language’s ecosystem. No doubt PHP has suffered from this. Other languages such as JavaScript have suffered from this as well. I don’t have a good feel of Python’s code ecosystem, but I can certainly say – anecdotally – that I’ve had to work with bad Python code too.

Or if the language has so many “gotchas” that bad code seems almost inevitable, that’s obviously a problem too. JavaScript is probably one of the worse that comes to mind, where variables are global by default, where your library won’t have a private scope or namespace if not for some tricks that we’ve had to create for ourselves, where object hierarchies require some unintuitive boilerplate, where monkey patching is easy, and many more. You could probably read JSHint’s options as a comprehensive list of JavaScript’s “gotchas”.

So how about PHP? Probably the most obvious pitfall in PHP is that it makes it easy to mix logic with presentation. That’s how the language was originally meant to work, after all – a few PHP tags mixed into your otherwise HTML page. Probably a lot of newbies still fall into this trap. It takes some experience and self-disciple to do the right thing.

Though, PHP also has a bad reputation in areas that have since been fixed and aren’t a problem anymore. We used to say that PHP is bad for large teams because there weren’t any namespaces, and register_globals and magic_quotes were still a thing. But today register_globals and magic_quotes are gone; namespaces have arrived; autoloading is standard procedure; there’s a healthy ecosystem of high quality libraries; and Composer makes sharing code and managing dependencies incredibly easy. Today, PHP is definitely large-team friendly.

PHPUnit?

I’ll get the Ruby bit out of the way first…

I keep mentioning Rails only because, in my limited experience with it, I like it much more than Django (which I also have limited experience with). To be very clear about it, I think RoR is better for web development
than any Python solution I have used…however, once we leave the web development arena and use these languages elsewhere, my opinion is that Python stomps Ruby in practically every concievable way.

Now, my issue with your above response is that a lot of it seems to be issues that either were true in the past, but no longer really the case for the most part (unit testing, object implementation).

Need look no further than PHPUnit regarding testing, so I’ll move on to the more interesting (to me) object implementation part.

First, I’ll just go ahead and say upfront that PHP is not as well designed as Python. Which is to be expected. PHP of course was born with one idea in mind, and over time evolved into what it is today. It’s much like how the C / C++ community was divided…C++ devs looked down their noses at C, and C guys criticized C++ for being a hack job in order to introduce OOP to the language. PHP has gone down that same path. What began life as a functional (procedural) language evolved into something much larger and better.

Naturally, Python’s architecture is much cleaner, much more refined than PHP’s. Nobody can deny that.

But when I say things like “petty” complaints about one language being a more -pure- OOP language than another, I mean that while Python or Ruby’s design may be nicer to work with, it does not make PHP’s design crap. PHP also gives you cool tricks like type hinting, lambda functions, reflection, late static binding, finally, a reasonable compromise for multiple inheritance (traits), etc etc etc etc.

Using -> instead of . may not be as pretty…but it’s the same idea, different implementation. Which can be said about 95% of the differences in the languages. What I’m getting at is, PHP and Python are just different…that’s all; different. You may consider the differences “fitting a square peg in a round hole”, but I just see it as two different ways of doing the exact same things.

In an attempt to prove that you can write nice, clean PHP code, I’ll point you to my PHP framework that I am currently working on – https://github.com/arout/kwfusion
Mind you, it’s still in development, so comments are thrown in all over the place in a few of the files; but other than that, I think it’s very clean, very readable, minimal code that does a hell of a lot of work.

– Note –

If anyone downloads and installs the framework, note that PHP 5.5 is required. And documentation is far from complete.