← Thomas Lackemann

From PHP to JavaScript

Posted on Sep 27, 2014 in

In the beginning

When I started to learn how to program for the web, it started much like anyone else. I picked up HTML/CSS and wrote up some ugly looking templates accompanied by some awful looking stylesheets. Then the idea happened that I wanted to make my own forms, but how did you get them to submit? A quick Google pointed me to use PHP and the rest is history.

PHP was and still might be the best introductory language for web programming. Why? Well it’s “easy” to learn (more on that in a second), it’s widely available on almost any system, and there is a ton of support for common problems, debugging methods, and troubleshooting techniques. Practically anyone that can download a program like XAMP/MAMP, can start coding for PHP with no prior knowledge on what a server-side language is or how it’s supposed to operate.

Learning PHP

The best and worst part about PHP is that it is both procedural and object-oriented. I believe it’s this reason that PHP gets a bad reputation amongst developers of other languages. It’s essentially the playground that developer’s learn on before moving on to “big boy” languages like Ruby, Java, or Python. In PHP it is completely possible, and sometimes acceptable, to write code that looks like this:

<?php

echo "This is my document";

class MyClass {
	
    public function callMe() {
    	echo "maybe";
    }
}

$class = new MyClass();
$class->callMe();

Not only will this work, I’ve seen plently of examples of stuff like this in real-world applications. It’s not “sophisticated”, it’s not clean or acceptable, but it works and that’s the reason PHP is very easy to pick up. It just works and it won’t complain often. If you ever get a chance to look at the original Facebook source code, it’s pretty ugly but it worked.

Moving on

Eventually the interest will spark to pick up a new language. For me I went to Ruby, didn’t really like it and very quickly went back to PHP. That’s not to say Ruby isn’t a great language, I just didn’t like Rails and the way it was very defined and forced. Ruby, however, I love. I think it’s great for scripting quick things and I still use it when I get the chance.

And then there’s JavaScript. This hip, new, elephant in the room that no one is really sure of just yet. With the introduction of node.js, JavaScript began to really pick up and a swarming community started to stand behind it. We now had a way to start a web server and start coding in seconds with the same language with no external applications or experience of how server-side languages worked. Simply following the example on the Node.js homepage is enough to get you up and running, and quickly addicted.

Learning JavaScript

I became fascinated with Node.js and JavaScript shortly after hearing about it’s first inception. It was basically another PHP, another language that you could program pretty much however you liked in order to get something you made working. Like PHP though, JavaScript has some major problems with it and their baked right into the core implementation of the language. Take the examples below:

[] + [] // Returns ""
{} + {} // Returns NaN
[] + {} // Returns [object Object]
{} + [] // Returns 0 (wat)

I particularly love the last two examples. Normally 1 + 3 = 4 and 3 + 1 = 4 but not when you add objects and arrays (although, in practice, no one is really doing this.)

It’s a bit screwy the language, but then again so is PHP and for that, I can forgive JavaScript.

Why write JavaScript now?

I believe it’s going to become the next PHP, it’s still in it’s infancy, but it’s going strong and more and more people are picking it up.

In fact, if you Google “getting started with web programming”, the first result is a site that teaches you how to utilize CodePen, JSFiddle, JSPen, and other sites that focus on writing and sharing good JavaScript. It might only be a short while before Node is the top hit for “how to process a web form” and “how to make a login script” (two searches I remember performing, back in the day.)

Love JavaScript or hate it? Join the discussion below, we’d love to hear your thoughts.

Cheers!

About

Tom is the CEO (Customer Experience Overlord) of Unicorn Heart Club where he leads development for Astral Virtual TableTop. He's a homebrewer, hiker, and has an about page.

Read More

← Light Table for Beginners

Comments