PHP is a good second programming language(but never a first)

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.

Advertisements

19 thoughts on “PHP is a good second programming language(but never a first)

  1. The comparison of 0 == ‘test’ is actually a very good point what a beginner programmer might not understand in PHP.

    However, PHP does provide variable scoping just like a language like C, with the exception of flow control structures like if-elses and fors not having a separate scope.

    What my post might’ve left slightly unclear is that PHP is in my opinion a good language especially if you’re interested in web development and aren’t yet absolutely sure if you should pursue programming more – it can show you the ropes and let you easily do something to see if you like it or not. When you actually decide, learning a more “traditional” language is a good idea.

  2. At this point, I’m tempted to say that the best first language is no language, but some kind of natural language-ish psuedo-code That way, newbies can focus on imperatively describing the steps that will solve the problem at hand. Then they can ease themselves into the tub with any reasonable (read: no Lisp or Prolog or Turing) general purpose language.

  3. Thats a good idea moffdub. But are you sure that’s gonna be any fun? The real fun of programming (to me)is to see the expected output, like the ‘Hello Word’ on the console screen or on the web page when we all first started to learn coding. I don’t think pseudo-code is going to be as enjoyable for a newbie.

  4. I agree. That is what attracted me to buy a book that had a demo version of a compiler on a CD attached. That way I could type the source listings and run them myself. I think, though, many newbies focus too much on the technical side and not on the problem-solving side. You need a mix of both.

  5. I’m not sure I think that C or C++ (or even Java) are good true first programming languages because I’m not of the opinion that mastering “the plumbing” is as crucial in the beginning as mastering common concepts like flow control (specially branches and loops) or understanding variables or functions/methods and return values. A real beginner should not have to worry about malloc or permission modifers or pointers. Thinking back in your own life, I bet you wrote BASIC (or something similar) before you wrote C.

    I think something like Python or Ruby would be better first programming languages. I believe Python was even originally intended to be a teaching language.

    I do agree with you in your criticisms of PHP and like you I (overall) like the language and use it daily.

  6. Pingback: When PHP Actually is Your First Programming Language

  7. You are right Sam Jones, ‘technically’ my first language was QBASIC. But I never liked it for many reasons and left it quick. It was the famous ‘for’ loop in C that got me interested in coding with it. And the ‘foreach’ loop in PHP made my life a lot easier.

  8. I think Turbo Pascal could be a good first programming language especially for newbies. I started to learn Pascal during my 1st day of college and it was a nice experienced to remmber..
    But now, Ive no more Pascal instead of using my favorite Notepad++ and cooking PHP applications.

  9. Pingback: Nerdlife » PHP is a /great/ first language for a hacker

  10. As a hobbyist, my first language was actually Javascript, back in the days when I was still learning HTML. It was more of an “Hmm, I think I’ll learn this to make my page cooler” kind of language acquisition. I still remember all those snippets.. all the goddamn snippets.

    But my formal programming initiation happened with QBasic. If I ever teach anyone to program, I’ll probably give them a tutorial with BASIC first, just so they can grasp the concepts of procedural programming. BASIC is perfect as an introductory programming language precisely because it isn’t an all-powerful and complex language; it gives the learner the freedom to ignore the language itsel so he can focus on actual problem solving.

    I also think that, although it is a powerful and highly useful language, Ruby isn’t suitable as a first programming language. Yes, I know that many people think it’s easy to learn because of it’s highly idiomatic nature, but I still believe that a good and solid background on procedural programming is better than diving directly into OOP. It may be okay if the student will ignore the OO nature of the language and use Ruby in a procedural setting first, but how many beginning Ruby programmers actually do that? (Hint: almost none who want to build applications with Rails.)

    I can say nothing about Python, given my limited background in the language, but as for PHP–I can’t really comment. I fell in love with language after reading tutorials from DevShed and, aside from a brief rendezvous with Ruby (yep, because of Rails), I still think highly of PHP.

  11. I think’s it’s snobery to suggest that that some kind of language is better than others, or where to start. I think you’ll have to start with the principles underlying programming, and that hasn’t anything to do with a specific language. Siwtching syntax is the only difference in the languages, just like the switch from English to Spanish. Do i feel inclined to sitch to Swedish just because it makes me more intelligent? of course not, it’s a mark of uncertainty. Whether or not you make your own bricks for building a house, or you buy the bricks, the result is the same, with the diffenrece that you’ll finish quicker than when creating your own bricks. It’s just stupid, the whole notion that one should is stupid. Some say fortran, other say lisp to sound eleet, well did you know that LISP is very easy to learn? probably easier than PHP? the comparison is easy, Ruby on rails is somehwat moddeld after LISP, for a good reason. Not because it’s eleet to write in LISP when you don’t have to.

  12. I am not sure how the brick analogy totally fits rvdh. I think you should have mentioned ‘tools’ instead ‘bricks’. And about the language analogy, how about switching from English to Chinese, or vice versa? I’m no expert but I believe that is going to be much harder than English to Spanish switching. ‘Ease of transition’ is what I tried to establish as a good trait in any first programming language.

    Thank you for your input.

  13. I was first introduced to programming by a friend who knew a lot of PHP – and so I began with that.

    I can say I regret it, mainly due to the looseness of the language. I am so used to doing echo($string); or worse if($string == $secondString). I’ve recently started learning C# and it’s almost like culture shock.

  14. You Blog is interest in PHP Language!!!
    You had say what i thinking about.

    I work in VB.NET,C#,ASP.NET around 4 years, but my new job is about php, so i am new to php, and i feel so much strange think in php.

    the first one is , PHP Application include,require function make the application missy,
    for example,
    Function C in C.php
    B.php include C.php
    And A.php include B.php to call function C

    That mean A.php cross 2 level to Call a Function, it’s so strange for me, when the application is huge , it not easy to debug and manage!!

    also why all php variable is anonymous type
    $varInt = 1;
    $varString = “2”;

    echo $varInt.$varString; //12
    oh god, it shouldn’t be on a Strong-Type langauge.

  15. I’ve been working with PHP4 some years ago nas still have some nightmare with many of his unpredictable behaviours.

    I really disagree that it can be a recomended first language, ironically by the points he cites.
    Because it’s “specialized”, it can bring some bad habits with programming, like coupling with logics and presentation.
    The loosely typing can make a lot of confusion if the programmer is still a beginner and didn’t consolidated the typing concepts.
    There is also those global variables *sheever* which can make things even more confusing.
    Finally there is the built-in libraries, which breaks the OO concepts and the newbie can’t learn too much about modularity.

    All said at the plenitude of my ignorance.

  16. Pingback: PHP不是首選的Language | 亞特蘭提斯 .NET Atlantis

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s