Ask HN: I am a PHP Newbie, Why do most developers hate it
Could you please explain me in the terms that would make sense to me. :) that Why do most people prefer Ruby/Rails or Python over PHP.
I like PHP because it's quite easy to learn, moreover, all of the major open source CMS (wordpress) are based on PHP, since most of the websites I deal with run on wordpress so it makes my job easier too. Moreover, I am believing, PHP is the most suitable language for 'web applications' because it does not rely on frameworks etc (rails) and can develop web applications at its own.
I want to know in layman terms, why Ruby/Rails or Python are better than PHP. Since I can not figure this out, perhaps due to the fact, I do not have major experience in programming languages. I appreciate if you could explain it to me.
16 comments
[ 2.8 ms ] story [ 59.1 ms ] threadPerhaps, I have not developed a lengthy web application myself yet, therefore I can not determine the inefficiencies of PHP over RoR or Python. And this was the reason I posted it here, to see, How PHP can be troublesome in complex web applications and how RoR or Python handle them more efficiently.
PHP developers, in my experience, have their shit together. This is just my OWN personal experience. I would never hire a Python/Ruby guy again, I'm always going for PHP developers now.
I can also tell you that there are a lot of really good php framework (laravel, yii, symphony, etc) that allow you to develop mvc sites very easily making php again fun and not a pain in the ass.
Personally I would never touch php code that is not in a form of mvc framework (also a personal one).
The advantage of other serverside languages like c#, ruby, python, javascript/node.js is that they are also widely used for other purposes and not only serverside, so when you learn them you also have the chance to explore other solution in more different areas.
Basically any of them is good for what you want to do, just choose one, stick with it for some time and learn it well.
If you follow best practices and use modern frameworks like Laravel, then there should be nothing to complain about PHP.
If not, then ignore what others say! They are are not your target market or stakeholders in your projects. Listening to them will only detract you for your main goals of having customer and having them satisfied.
There are languages I prefer. Perl does a number of things better than PHP, so does Python. But it is possible to write cogent, maintainable PHP, and there can be sound reasons to do so.
If you wish to find out why the HN crowd tends to look down on PHP, I'd suggest that you put some time into experimenting with other languages. But I'd suggest you put time into learning how to do PHP well first.
Some of it is due to security. Several of the things which made PHP very accessible to new developers also encourage poor security practices. For example, sending SQL queries to the database as a raw string, rather than a parameterized query, makes for injection vulnerabilities. There are ways to work around it, but often the 'unsafe' way is a lot easier and more obvious than the safe way.
Some of it is due to the early proliferation of beginner code. PHP was the language of the web right when every man and his dog were learning just enough code to make something work, then selling themselves as experts. That resulted in a lot of people writing very hacky spaghetti code, which rapidly became legacy.
Some of it is due to the switch from its procedural roots to its object oriented alternative (while maintaining backwards compatibility). This isn't really a great thing for a language to do, because it means that people who are less than completely clear as to how to solve problems in both procedural and OO versions of the language often end up writing a confusing mish-mash of code.
Most of this should not be a problem for a sensible, well learned and disciplined developer building a new system. (The security thing can still be a thing, but there are ways to handle it now).
PHP now has a fantastic culture of building fast, usable systems. Thanks to the big PHP CMSs and frameworks, there's also a lot of great interoperability (and extendability) patterns in PHP which don't really show up anywhere near as much as in other languages. It's extremely easy to deploy, it's well documented, and it's cheap to run.
If you like it, and it meets your requirements, then go for it.
If you are working with websites you will naturally learn HTML and CSS, then javascript, then jQuery.
Next you might move to wordpress based websites so PHP and MySQL would be the next things to learn.
Next step would be your own web application. PHP and MySQL will work for your own web application. And I would recommend developing a few from scratch with just PHP and MySQL. Creating a login system and CRUD features. Creating these without a framework will give you a good foundation to know what's going on behind the scenes when you move on to a framework. Before developing a web app from scratch it's harder to understand what Rails is doing and why it's valuable.
Once you do this then the next natural progression will be using a framework to create a web application. I recommend giving Rails and/or Laravel (PHP Framework) a try. Even though you will know more PHP than Ruby it's a good experience to see how Rails works and why it's so popular. Laravel is a good PHP framework similar to Rails if you want to stick with PHP.
I wouldn't limit yourself to PHP though. Once you have been creating web applications it should be pretty easy to learn any framework/language. I prefer Rails and Laravel but that's just a personal preference.
Back to your question. Ruby and Python (and their frameworks) are more elegant than PHP. But those choices have positives and negatives of course and depends on your clients as well. PHP is easy to learn so you have lots of bad code and bad practices out there. And there are things inherently wrong with PHP compared to other languages. But I think it's worth learning especially if you're involved with Wordpress.
Check out TeamTreehouse.com and you'll learn some good programming practices to get you on the right track. If you're just getting started the Oreilly Head First books are really good for learning HTML and CSS and their Head First PHP & MySQL is good as well.
After that you can check out railscast.com and laracast.com.
There is lots of tutorials and information out there for all languages.
Good luck.
I am already member of both treehouse and T+ and they are both awesome places to learn quickly and making sure you follow the best practices.