So I figured I’d jump on the blogger bandwagon in the debate on whether or not PHP is a good first language.

First, a little context.  PHP was the first language I did anything useful in.  I learned QBASIC in middle school, which I used to make some neat games.  Around 7th grade I taught myself PHP by hacking on phpBB installations.  I didn’t learn any other language until college, where I quickly picked up Java, C, and SML (in that order).  I agree that PHP is a horrible language to teach proper programming practices, but that’s not the point of it.

I’ve had the privledge of talking to Rasmus a number of times over the last few years, and while I didn’t get permission to reproduce his comments and so I won’t (I will say he has some funny stories about David Filo…), I can quote an article he wrote approx. 4 years ago on PHP:

PHP was never meant to win any beauty contests. … It was designed to solve a single problem: the Web problem.

It does this very well, as shown by it’s outstanding adoption rate.  The truth is that PHP is hacky, but it’s hacky in a logical way.  It was written to help a programmer have an easier time writing for the web by one in that exact situation, and it does it’s job.  If you need to throw a page together in 5 minutes, you can do that!  Which is exactly what budding programmers should be exposed to.

Think of it this way: why do people learn programming in the first place?  Nowadays, it’s either as a career path, in which case they probably aren’t destined to be hackers in any sense, or because they need to solve a problem and writing a program is the best way to do it.  What is going to turn a newbie on to programming faster: learning proper structure, or being able to pump out a solution to his/her problem in 5 minutes?  I would bet a lot it’s the later.  That’s what hackers do, they pump out a solution to a problem quick and, quite possibly, dirty.

“But Brian, have you ever seen dirty code?” you ask.  Of course I have, and I despise it.  But I contest that proper style is something that can be learned after the fact.  The ability to pump out a prototype in 5 minutes can’t be learned as easily.  The ability to ignore all convention and generate an import script to move all of your data from A to B to get your site back up, or hack together a script to bulk rename files in a really wonky way, while trivial to do for most programmers, can be done much faster with a hacker mentality.

I am a hacker, but I have no problem following convention.  I don’t like to, since it slows down coding, but when I’m in a group of programmers, or working on code that needs to be maintained, I do recognize the point of doing so and follow them (to the letter even).  Of course, I’m by no means the norm on anything, so take what I say with a grain of salt, but it seems to have worked well for me: I can follow convention, but at the same time I can adjust, I can change my style as the situation demands, and I can code up a storm when need be.

Tagged with:  
Share →

12 Responses to PHP is a /great/ first language…for a hacker

  1. Skolor says:

    I’ve got to agree with this.

    While I’m personally only about halfway to writing good code, I’ve got to say learning PHP as my first real language was probably a good idea. One thing of note, from my experience, is the intent of programming.

    The first time I tried to code any real program (other than simple BASIC programs) was to Hack together a website. A couple friends and I needed a website, which we could dynamically update, and would show any number of News Posts and/or Comics that we specified. At that time, I couldn’t find anything to do that, so I just hacked at it for a week or so, and came out with a working site.

    What PHP so great was that I could just /do it/ I didn’t have to go out and learn all the specifics in writing good code. I needed to store images, and news posts, and then generate pages. A month later though, I ran into the reason why PHP is such a bad language to learn on: I tried to add features.

    My buddy wanted to be able to work with categories. I went from a nice, working system (albiet very ugly), to a broken, smoking mass of code in a couple of days. From that, I learned a couple of things.

    * There are two very distinct types of coding: Programming, using good, fully functional, extension standards, and Hacking, create quick, dirty scripts which work, and will only ever do one thing.
    * Programming is awesome, and really fucking hard to do well. If you can do it, your program will be all nice, and other people can come in and make changes. You should even be able to come in and make changes yourself, if that need arises.
    * Hacking, is equally awesome, and hard in a completely different way. You need to be able to fix a single, given problem in the quickest way possible. Where programming creates something which will, hopefully, be used by many other people, and used in ways never intended by you, hacking may never leave computers/servers you directly control. Instead of creating something new, it fixes a problem, and probably works on top of or in conjunction with something else.

    PHP works great for hacking, especially for learning it. You first working prototype is working in minutes, and, assuming you know the basics of logic, you can pump out a single purpose piece of code in a couple hours, and will work, hopefully, for as long as you need it.

    PHP is not good for learning good programming on though. For that you need to learn all about methods, and functions, and a metric crap-ton of other things. PHP doesn’t help you learn any of that. In fact, it makes it a whole lot easier to avoid them all together.

  2. Anant says:

    Umm, but there are languages that are better structured, yet still ‘hacky’ enough for quick and dirty solutions! Python, for instance, is my favorite and I would highly recommend it as a first language.

  3. Brian says:

    Yes, but Python lacks that “show your friends what you did” mentality that PHP has. Sure you can run Python scripts for the web, but it’s not as trivial as PHP given the huge support and volume of resources available for PHP on the web.

  4. Skolor says:

    Yeah, I can go out and grab some free php hosting, or drop $1 or two at Nearlyfreespeech to get SQL with it, and have a whole range of things running quickly, that anyone can make use of.

    The portability of PHP also makes it great, python can run on most desktops fairly easily, but it won’t run on most forms of cheap web hosting. If I throw together, say, a piece of polling software in PHP, put it up on my $3 a month web hosting, and show all my friends, they’ll be able to say “Hey, I like that, let me get a copy to put on my equally cheap hosting.”

  5. Python forces style on you even in situations where all you need is a simple, quick and dirty hack that you know you’ll throw away within a few minutes, hours or at least tomorrow. And Python forces a particular style on you even if you might fell better with a different style (that is still clean though).

    And that’s one of the reasons I fully agree that PHP is a good even first language for a hacker: You can do things fast, even with embedding it into otherwise pure HTML page, you can do dirty hacks, even on the commandline if needed. And you also can evolve working with it to doing clean, throught-through, nicely styled, object-orientated, do-everything code.

    PHP is good for the whole way from the small, quick and dirty hack up to full-fledged, cleanly coded (web) applications. Only when you come to the limits of interpreted code (memory- and performance-wise), you can get forced to switch to something else (given you’re in web development, partially also in the commandline environment).

    The key is not to force style on you but to let it grow wisely and naturally.

  6. Eevee says:

    The problem, of course, is that so many people don’t EVER bother to learn that pesky “good code” thing. And that PHP actively resists being written in any way that resembles “good”. Hacking is one thing, but the fumbling around blindly in the dark that a complete beginner does is not quite it, and it’s hardly conducive to becoming a good programmer unless the person in question has impressive amounts of interest and self-discipline.

    Learning to hack is fine, but there are other languages just as good at hacking with just as many resources but that aren’t terrible in every other way. I don’t see how Python lacks a “look what I did” mentality, unless that mentality only comes from copy-pasting really bad code that some other beginner put on his blog. Pretty sure Python has enough resources to go around, too, given that it predates PHP by four years, and it hardly “forces” style on you unless you find it mighty inconvenient to press Tab.

    You can find cheap Web hosts that will run your Perl or Ruby or Python or whatever; you just have to spend more than thirty seconds looking. Off the top of my head, nearlyfreespeech has some dozen languages supported and Dreamhost will let you do pretty much whatever you want that doesn’t take their machines down.

  7. Brian says:

    Unless I’m mistaken (which I probably am, I haven’t done too much Python), Python has with chmod, which many newbies don’t know much about because they’re probably coding and uploading over FTP (since the cheap plans don’t give SSH). They also have to know if the python binary is in /usr/bin or /bin or /usr/local/bin, without being able to run `which python`. Then there’s the cgi-bin, which I imagine some hosts still require.

    As for the “look what I did” part, that’s probably from my mostly-wrong impression that python is more of a command line tool, which I admit isn’t really as true anymore. I was alluding to the ease of setting up a PHP website as opposed to in another language, which is redundant.

  8. Eugene says:

    Now everyone is talking about the American economy and eclections, nice to read something different. Eugene

  9. low profile says:

    “I am a hacker”. (Brian, 2008)

    Are you really sure the true meaning of “hacker” ?
    Real hackers never claim they are, instead people called them.

  10. very low profile... says:

    Well (apart from what I read on this blog)… actually a real hacker doesn’t “make” attacks (even knowing perfectly how to face them if they are against him).

    That is a usually called a “cracker”.

    About hacking… well I would just say this:

    Enjoy “learning”… when you do it with passion.. that means you’re “hacking”

    Bye,
    Max

  11. Dabert says:

    i dont usually comment, but after reading through so much info i had to say thanks

  12. Maharrori says:

    OMG!

    3 days ago I received a call from (972) 2840600 & 9722840600 and was pretty sure the caller was a scammer.

    Guess it was a bad case of the “Mondays” – cause I went nuts – and called the company (Gulf Coast Western) and went nuts.

    Check this out… Gulf Coast Western — the oil drilling company- called who I interviewed with last month – we’re calling to tell me I got the job!

    Any advice how to get unfired!!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>