Is PHP really that bad?
First of all, let me state that I don’t think I’m an expert programmer, but I think I’ve learned programming from some very good people (at my previous work) who were perfectionists in terms of how the code should look like.Â
When I first started programming (it has not been long, trust me), I started to work on a real-project using PHP.  I was taught to use it because PHP is considerably easy to learn.  I believed it, after all, lots of universities in Indonesia didn’t have PHP in their curriculum, yet there were so many PHP developers in Indonesia.  I thought these people must’ve been self-taught, hence the languge itself isn’t really difficult. It turned out to be true.  PHP isn’t really hard.  I’m now used to it, even though I’m still looking at other programming language to learn from.
When I worked as a developer in the past, my employer was very strict on coding style. Â Everything has to look similar from one file to another. Â We also followed (kinda) MVC where View should not interact to the Model right away. Â Instead, it will be the controller’s job. Â We also tried to maintain that there should be no PHP codes in HTML files or vice versa. Â The solution was to use Smarty, for better or worse.Â
Some of the strictness we used were:
We use: $n = count ($var); for ($i = 0; $i < $n; $i++); Instead of: for ($i = 0; $i < count ($var); $i++);
Also, spacing between characters, variable assignments, calculation, curly braces, and all that stuff are maintained. No one is allowed to write:
for($i=0;$i<$n;$i++);
Well, one line of code might not matter. Â But if you have hundreds or thousands of files, your eyes will eventually be tired to read some of these codes. To cut story short, we used K&R style as much as possible.
Now, my problem is, I resigned from my old company, and started on my own business, and I’m still doing PHP work. Â For the first few months I could work by myself. But sooner or later, I started to need some help from other developers, so the job vacancies began.
Here’s what I found out when I interviewed and tested some of the guys:
- Their codes are truly a mess. No indentation, no spaces between assignments, calculations, and etc.
- They don’t understand the concept of MVC. So, they write their codes on Dreamweaver where they can mix the HTML codes and PHP codes
- Even worse, some of them don’t even know how to write codes from scratch. One of the applicants actually asked me if I had a PHP file where he could edit and finish it.
I know that some of the problems I faced was because some of these people might “lie” on their resume, or maybe their codes was good enough for their former employer. Now, this leads me to my question:
Is PHP really that bad? Don’t people learn how to code nicely so that others can read/understand them? Is it because of the IDE? Or is it because PHP is not in our universities’ curriculum so that people practice PHP in different ways (I noticed Java people or .NET people don’t have these problems since they are taught in the University)?
The last thing is, is PHP really that easy to learn that it becomes a disadvantage, where people can just abuse the language, in terms of how it is written?
Yes PHP really is that bad because it encourages poor code and habits due to the poor design of the api and the language itself.
PHP happens to be very easy to learn, and that's the main reason why it's so popular. It's used not only by programmers, but also by sys admins, web designers, multimedia developers and people with no computer science background and who don't care about software engineering in general. And that's what's so great about PHP.
If you want to hire a programmer, then it's up to you to conduct a proper interview to fin the right one. Otherwise you can end-up hiring a web designer or sys admin.
Woah wait a second, you say you are a 'coder' with no formal training but you can pump out code that you have been 'taught' is the best way of doing it and you find alot of fault in others work just because they dont use MVC/smarty etc ?
I personally dont touch a 'MVC' framwork or smarty (not even with a stick) instead I use what would amount to a controller on each page, would you call my code rubbish ?
For any given small to medium website, my code would be smaller, faster, more readable, looser coupling and a damn side faster to code then any MVC based solution.
You might want to make sure they dont just have a different idea of what is 'proper' then yourself.
@Matt:
Yeah, the part where PHP is very easy to learn is beneficial at some point, and at least that's how I think I can learn it faster than other programming language. But the thing is, in Indonesia most of the books published regarding PHP is related to Macromedia Dreamweaver. I'm not bashing Dreamweaver because it does its job, but I've seen some people (based on the people who I've interviewed) built an E-commerce or other "pretty big project" web applications using Dreamweaver. They don't use it only to create HTML, but also put PHP codes and HTML codes in one file. They look messy, and somewhat (this is subjective, of course) hard to maintain.
When I asked them to write PHP from scratch to do certain things, they went blank.
@Snuffy:
I'm sorry if you get my message negatively. I don't think the way I was taught was the most appropriate one. But I believe some of the things I learned was good fundamental. For example, writing clean code (how clean it is might vary, you probably have a certain coding style the whole group can follow, etc) so that others can review your code.
I'm not saying that all PHP applications should be MVC or use Smarty (although I think using MVC has its advantages), but like I mentioned earlier, a lot of people in here (based on a small group) could not write PHP codes that are separated with HTML files. I think putting HTML codes and PHP codes in the same file is hard to read, and may be hard to maintain.
Do you mix between HTML and PHP codes every few lines or so in the same file? If yes, then I say your code is rubbish.
thanks..i have been found one of best articles..keep writes more
different programmer has different style and way to write the codes. It's like as habit. They write the codes for the destination basically of efficiency and effectively
7 Comments