Is PHP a good first language?

May 1, 2008 – 3:47 pm Tags: ,

Sometimes I’ve seen people say PHP is a bad first language, because it teaches bad programming habits. But is this actually true at all? Often those who say that don’t really like PHP themselves either, many times because of equally untrue reasons.

I think PHP is a perfectly good first programming language - I would even go as far as say it’s possibly the ideal first language if you are interested in web development.

What makes a good first programming language?

When I began programming back in.. uh.. I think somewhere in the ’90s, I started with C. There weren’t really any other languages than C and Turbo Pascal that a young wannabe-programmer might have known of back then, at least where I grew up.

C is a lousy first language.

  • C has a lot of difficult to understand concepts like pointers
  • You have to write a lot code to do anything
  • Want something outside the console? Not going to happen any soon.

Because of the above reasons, C is not a very good language to begin your programming studies with.

But why?

If you aren’t really interested in programming, like I was, you will not get much incentive to continue. You get some console prompts - really boring stuff today. We can easily flip around those above three points and come up with…

A good first language should:

  • Not require complicated things to get going
  • Be powerful - provide high level functions to do things with less code
  • Be able to provide something concrete to show you your progress

So we can say that a good language should be simple to use, but powerful and have real functionality - ie. not a toy-language - and encourage the fresh developer to continue by easily letting them do something useful and cool!

PHP is nearly perfect

With the points made, I would say PHP is definitely a nearly perfect language for people looking to get into web development.

PHP is not a complex language. It’s quite easy to use and understand, but it still has the features of a “real” programming language like Object Oriented Programming. It can be an easy beginner’s language, but it also provides you room for learning new things.

PHP has a huge library of built in functions and classes that make almost all tasks very easy to do. Read the contents of a file? Sure - $myvar = file_get_contents(’myfile.txt’); - Now, do it in C…

And thanks to the above points and the fact that you can embed PHP in HTML, it’s very easy to make something that you can feel proud of. Just throw together some HTML and PHP, host it and you can show everyone what cool stuff you’ve made.

And finally, PHP is a very popular language! If you learn PHP, you can be sure that you can find employment coding it.

Reasons to not choose PHP

Often people say that PHP makes it easy to write bad code, which makes it a bad first language.

What’s wrong with writing bad code, if you’ve just began your programmer’s career? Isn’t that what beginners do - and it’s perfectly fine.

Some other arguments include PHP’s poor decisions in the past, such as enabling magic quotes (which automatically escape post, get and cookie vars with backslashes, sometimes leading to confusion) and register globals (get, post, cookie and some other vars get automatically registered on the global scope) by default. These two are also often used as general attacks on PHP - which I really don’t understand. Sure, they aren’t exactly good things, but you can disable them.

Some also say that PHP’s builtin functions don’t really follow any conventions, which is not true at all. It may not follow a specific convention 100% strictly, but it does not make it a worse language as it’s more than enough similar for most parts.

Learn PHP!

I would encourage any new programmer to pick up PHP. It’s great, despite what people say about it.

  1. 17 Responses to “Is PHP a good first language?”

  2. Yes, php is a good first programming language, i got started programming when i tried php, it was easy to start with, and you didn’t need alot of difficult theorys’ before you could make something.

    But it is hard to come from slam php starter programmer, to a well organised programmer. But again i think it is a good first language, since it is so easy, and it learns the person many objective programming aspects :)

    By Kasper A. Svendsen on May 1, 2008

  3. I think it does not really matter what language you start with, especially if you don’t have any “proper” education in programming, it is difficult to find out good practices and such.

    I’ve found a good way to learn good programming style and practices is to read books that talk about it. I’ve probably mentioned books such as Code Complete and The Pragmatic Programmer before - those two are really good ones and you can learn a lot from them in my opinion.

    By Jani Hartikainen on May 1, 2008

  4. I think that PHP is an excellent first language for a beginner for the reasons you’ve stated. I also think that if you get a very good PHP programmer to teach you how to use PHP, then you can avoid the nasty habits that PHP noobs usually pick up from cutting and pasting fragments off the web.

    That being said PHP is not without its problems. Its OOP implementation while vastly improved in PHP5 can still make running into a language with a solid OOP implementation a little hairy.

    Case in point, see this gotcha I ran into assuming stuff would work as it did in PHP
    http://www.concept47.com/austin_web_developer_blog/2008/04/29/gotcha-in-ruby-for-php-developers-with-multiple-assignments-of-array-to-variables/

    If you’re using PHP, make sure you use PHP5 and then try to balance it out by programming in Ruby or Python. It will expand your mind in ways you won’t understand from just reading this.

    By austin_web_developer on May 1, 2008

  5. The answer depends on the goal of the learner. If the learner is motivated and wants to become a well rounded developer, they’re probably better of starting with an “academic” language like Scheme. If the learner has a short attention span and wants to see results quickly (which is probably the majority of people), then PHP is probably a great option.

    By Bradley Holt on May 1, 2008

  6. That gotcha could be avoided if you note that Ruby’s array is a class, instead of a type like PHP’s. Class instances in Ruby, like in PHP, seem to be copied as references based on that… Never done any Ruby programming really, so I won’t swear it’s correct.

    I have to agree on Python (and probably Ruby, too) - Python is a great language. Has its haters, again, though.

    Bradley,

    Yep, that’s true. If the person is really interested in programming, they might be better to start with a language like C, Scheme or whatnot. If you’re still dabbling whether to get more into programming or not, then a more high-level and powerful language like PHP (or perhaps VB.NET, if you want to write desktop apps) is good in my opinion.

    By Jani Hartikainen on May 1, 2008

  7. Yes, it’s an OK first language as long as it’s also your last language.

    Otherwise you’ll learn a warped view of programming and too many bad habits, which you probably won’t even realize aren’t necessary when you start using a language that don’t enforce such things on you.

    By Greg M on May 2, 2008

  8. Gee, I must be a bad coder then. ;)
    If you have opinions, please add proper reasoning and not just random attempts at flaming.

    By Jani Hartikainen on May 2, 2008

  9. As someone who started off in Java and then found PHP a bit later, I have to say that PHP would have been a MUCH better language for me to learn first.
    Even if just to get your feet wet learning how web applications work.
    A newbie can take the script approach and learn these things and then grow into the OO approach and onto frameworks such as Code Igniter, Symfony, etc.
    With Java man, for me…it was trial by fire…and yes writing tons of bad…_very_ bad code. After I learned PHP I found that my Java code started getting cleaner because the barrier to entry on PHP was much lower and I grew more comfortable with regular programming concepts much quicker.
    As I’ve griped about MANY MANY times, “real” programmers think PHP is just a crap language and look down their noses at those who program in it, but I have YET to hear an actual reason “why” from any of them.
    I like to think to myself that its because they’ve no experience with it (outside of the scripting portion perhaps) and that since it doesn’t have 16 different layers, that its no good.
    Now I’m mainly PHP, Grails and some Java, with Java being my last choice of the three.

    By ryan on May 2, 2008

  10. PHP was the first language I really cut my teeth on. But at the same time, I was reading a lot about OO design and how to apply OO principles in PHP. This was the single best thing I really could have done. I have since worked with “real” languages like C#, and I can tell you right now — the language has relatively little to do with how good of a developer you are. I’ve seen some C#/ASP.NET code that makes the *worst* PHP code I’ve ever seen look glamorous. Focus on good programming concepts, and how to apply them in the language of your choice.

    By ncloud on May 2, 2008

  11. I think PHP is not only a choice as the first language to learn, but the best. Here’s why:

    1- You don’t have to know everything about PHP to make it work.
    2- It’s free
    3- There are free IDE’s (www.eclipse.org & http://www.aptana.com/)
    4- Large following, this is useful for questions (http://webdeveloper.com/)
    5- It can work with other languages & services very easily
    6- After you learn the basics you can start to learn OOP (Object-oriented programming)
    7- Great database support (MySQL, MSSQL & Postgresql)
    8- Can make desktop applications as well as server side applications
    9- Platform independent (http://www.apachefriends.org/en/xampp.html)
    10- Do I need say more, get developing :-)

    By Phill Pafford on May 2, 2008

  12. PHP is a great language to get started. It semi forces its users to write something web based, thus picking up a little html and css on the way. And providing quick, pleasing results.

    As opposed to an ugly console calculator in C.

    Any starting programmer will write ugly code, it’s a no brainer :P I don’t think there is an argument, that PHP promotes more bad coding than other languages.

    It’s a chicken and egg situation.

    PHP has more novice programmers than most other languages, hence more badly written code.

    By Nick Verlinde on May 4, 2008

  13. “Otherwise you’ll learn a warped view of programming and too many bad habits, which you probably won’t even realize aren’t necessary when you start using a language that don’t enforce such things on you.” — Jani Greg M

    I think any coder who can’t break out of habits is a bad programmer! Don’t blame the tools.

    It can be seen in the whole java Vs the dynamic languages (ruby,groovy) debate.

    most java programmers moving to these languages, at first write dread awful code, because they are not used to thinking in these new paradigms: closures, duck typing, …

    Perhaps, some of them never get it, and just stick with their language. But that’s not the fault of the language, just the person

    By Nick Verlinde on May 4, 2008

  14. Fix: Nick’s quotation is by Greg M, not me. ;)

    The situation with PHP is a bit similar to VB6 - A lot of people say VB6 is crap, that it’s not a real language etc., while it actually is a totally fine tool for creating windows apps and such. Today it may be a bit outdated by things like VB.NET, though.

    Oh, and thanks for the diggs :D

    By Jani Hartikainen on May 4, 2008

  15. hum.. why not Python?

    I still like Pascal though. :-)

    By henry on May 6, 2008

  1. 3 Trackback(s)

  2. May 3, 2008: Bookmarks for May 2nd : Blog-Her
  3. May 3, 2008: Weekend Links - MooTools Fancy Upload, 60 Second Tech, jSize, CSS Pull Quotes, PHP First Language
  4. May 11, 2008: PHP is a good second programming language « Glorified Geek

Post a Comment