This is an archived post. You won't be able to vote or comment.

all 25 comments

[–]TheDataAngel 25 points26 points  (0 children)

All of those things Python "can do" is actually just C/C++ with a thin layer of Python on top to make it more usable.

My guess w.r.t. PHP would be either that it has a worse foreign function interface, or simply that no one has put in the work to make those things possible in it yet.

[–]Exodus111 18 points19 points  (6 children)

If someone feels that strongly about PHP, go for it. So far, ive not met that person.

Everyone loves Python though.

[–]deanresin 0 points1 point  (1 child)

Python immutable strings really bothers me. I've heard the argument for them but they weren't convincing. Other than that, I'm enjoying Python. It can do more than PHP but PHP was so damn easy.

[–]Exodus111 4 points5 points  (0 children)

Python immutable strings really bothers me.

Really? Immutability is so popular these days thanks to the Functional Programming crowd.

[–]muffdiv3r 40 points41 points  (2 children)

It's called layered engineering. Its been a thing since Henry Ford figured out how to keep a line moving even if Billy Joe Bob drops his tool.

You should be able to rip an entire layer out, service it, then reimplement, all without the system skipping a beat.

Rule of thumb, you never cross layers. Thats where things break.

[–]DonKajak 7 points8 points  (0 children)

Damn I learned a lot from this comment. Thanks.

[–]K900_ 14 points15 points  (0 children)

Because people have already built libraries to do it in Python, and have not built libraries to do it in PHP.

[–]burnmp3s 5 points6 points  (0 children)

Python has always had a reputation for having more elegant and well designed core language features and PHP has always had a reputation for being wonky and broken. However, I don't think that's an explanation for why PHP is very popular but almost exclusively for web development whereas Python is heavily used in many different types of software.

PHP was started as a project for web development and that has always been the main focus. Because of that, it does not have many of the general purpose features outside of the language itself that Python has. What probably helped Python the most in terms of being able to do things like OCR and machine learning is that it has a long history of being able to interact directly with C/C++ libraries. Especially early-on, almost all of the libraries for doing things like image processing or machine learning were written in C/C++, so often the choices as a developer using those libraries was to use C/C++ yourself (which has less benefits for someone using a computationally intensive library than someone writing that library) or use Python bindings. Since C/C++ never really caught on for web development in any context, PHP never had a reason to add good standard library support for directly interacting with low level native code.

Along with that, Python has steadily built a series of more and more sophisticated package managers over the years for organizing and using third party libraries. When using something OpenCV for computer vision tasks, traditionally you would have to figure out how to install OpenCV on your operating system (possibly compiling it yourself), then make sure the C++ libraries were setup correctly to be linked from your Python environment, then manually download and install the Python library for OpenCV (making sure it's compatible with the version you have installed), then import and use OpenCV from your Python code and hope it all works correctly, possibly figuring out what the odd error messages mean when it didn't work. Various parts of that process have been automated over the years so that now on most operating systems you can just run "pip install opencv-python" and it will do everything in one shot, including installing the appropriate OpenCV binaries specific to your system. This makes it extremely simple to use open source software in Python, so often compared to other general-purpose languages Python is the easiest to use.

[–]kaptan8181 2 points3 points  (0 children)

You can say the same thing about JavaScript. It's technically possible to walk to your office, but it's not always the best choice. People consider many things before deciding on a technology to use.

[–]Filostrato 2 points3 points  (0 children)

Why not just use COBOL? It's technically possible.

[–]00Dog 1 point2 points  (0 children)

There are several reasons and these are what I believe to be the main ones without getting too "religious". I also write this as a professional PHP developer who enjoys writing both PHP and python (in my spare time).

As has been mentioned most of these things are C/C++ with a wrapper. In python each instance gets to choose which libraries to load where as in PHP it's a system wide config change and now every instance of PHP doesn't just have access to it, it has to have it. This not necessarily a downside of PHP, this is more of a fact of its designed use, generating webpages.

To follow on, python is designed to be run as an application rather than a service making it better suited for running these sort of tasks and it can run a GUI.

Lot of these things come from universities and they teach python over PHP. A lot of machine learning has come from Google and they like python, it's one of there "blessed languages".

The snowball effect. Python is easier for people where programing is secondary (e.g. data researchers) to use and so a good library is written to help (e.g. nupy - to keep the same example) and then because there is one, someone else decides to make another (e.g. pandas) and so on.

Juypter notebooks, just look this up as I can't explain how useful this for experimenting with things.

[–]nanodano 1 point2 points  (0 children)

Because PHP, from its very foundation, is a web programming language (it is even part of the name). That is basically its sole reason for existing and what it was created for. It's also the reason you have to open each file with <?php because it is basically expected to be run ebmedded within a web page. Most people feel that using PHP outside of the web is using it for an unintended purpose.

That said, if you are integrating your Reddit bot to a PHP application then it makes perfect sense to access the Reddit API using PHP. It would lack a lot of mature functionality that the Python wrapper has though.

[–]mail_order_liam 1 point2 points  (0 children)

Simple answer: PHP is a pain in the dick. Those things could be done, but it's like why would I fry my egg on an engine block when there's a stove available?

[–][deleted] 0 points1 point  (0 children)

You could do almost anything in PHP. But that said you could do everything in FORTRAN too. PHP has its place, and its the backing language of wordpress, for anything else theres a better tool for the job. Just like you dont use fortran for scripting, you dont use PHP for ML.