I was a bit surprised to read the blog titled Is PHP a good first language? The author of the blog haved bashed C (instead of Java, which is a common trait in PHP fans). However, the author’s argument was not the fact that C is incapable, but the fact that it is too difficult to learn for a newbie programmer.

Contrary to the author’s opinion, my idea of a good first programming language is as follows:

It should encourage you to do problem-solving

It should enable you to think logically

It should teach you to approach the solution in a structured way

Firstly this is not a PHP bashing article. I am a PHP developer myself and I like my job. But there are reasons for which I believe PHP should not be the first language when you begin to learn programming. It might be a good second one. I should also make it clear that I am not suggesting C to be the first one, the choice is entirely yours. I am just going to mention C as an example in the rest of my article.

PHP is a specialized language

PHP was created to solve the Web problem. It was and still remains the most popular language to build web applications. No one expects you to write a web application in C. It will be like building a console calculator in machine language. But if you are someone absolutely new to programming, you should start with language that is generic in nature, and structured. After you have gained sufficient knowledge and skill in that language, moving into a specialized arena, be that web or system programming, won’t be much of a challenge for you. If you ask a C programmer to learn PHP, he’ll need little or no time get himself acquainted with it. And he’ll most likely love it. But If a PHP guy (which is his first language) wants to learn C, it is less likely that he’ll enjoy it. Eventually he’ll hate the very language that implements PHP itself!

PHP is a loosely typed language

Despite what some theoreticians say, I am quite fond of the loose typing feature of PHP. It provides much flexibility and ease of coding. 0 compares equal to ‘0’ without the need of explicit type casting. But this feature is not without its disadvantages, and if you are not careful enough it may lead you into programming pitfalls. What will be the reaction of newbie programmer when (0 == 'test') will return true in PHP? It’ll scare him off PHP, if not programming.

Dynamic variables in PHP

Variables are (kind of)the heart of a code. To understand programming, you have to really understand what a variable really is, what is its lifetime, what is its scope, what part of the code are going to see it, and how are they going to see it. In PHP variables are created on the fly. This is a great ease for development, but not so good for debugging; readability may also take a hit if the coder is not careful. If you start programming with a structural language as C, you would be forced to use variables properly i.e. you will have to declare it first. You have to specify what type it is. Than depending on how you declare it, it will be visible to some code, and hidden from others. You have to understand these things properly and correctly if you want your skill in the language to grow. After that moving to PHP, or any other dynamic language, will be painless for you.

Built-in library functions

My fifth-grader cousin could not figure out how much is 42 times 25 with a pen and pencil, He had to be provided with a calculator. My point is, built-in library functions will make your life really easy. But to be a better programmer you should have an insight of how things work. I am not saying that you must know how each of the function works; or avoid using functions and do things yourself. But if you really like programming, you should know things, like how does a certain sorting algorithm works, what sort of data structures are there, pointers are really P-I-T-A, but they still give you an insight on memory manipulation. Having a sound conception on topics like these makes you better at problem-solving.

The world of software development is diverse and ever changing. Knowing one or two programming languages won’t help you much if you want to progress. Selecting an easy language may benefit you at the beginning. But it’ll make you pay when you need to switch to some other sophisticated technology. So choose the first language wisely. And if PHP is your second language, you’re gonna enjoy working with it.