Object-Oriented PHP 5 – just like Java

October 19th, 2008

One of the best thing about PHP is how easy it is to learn.

If you come from Perl, you may have at times the feeling that “PHP is Perl for Dummies”  … as my Perl teacher liked to repeat.

If you come from Java, it is even better. PHP 5 OO concepts make it very close to Java, you can learn the few differences very quickly: the package concept in Java is replaced with namespaces in PHP, since version 5.3; the properties of an object are accessed with the awkward $this->myProperty.

Now, you can grab a book on PHP 5 objects, flip the pages and repeat: “just like Java”, “just like Java”, “just like Java.”

Why JavaScript is so difficult to learn

October 19th, 2008

I have been a web developer for more than 3 years. In the process I have learned HTML/XHTML, CSS, Ajax, PHP, MySQL and a few things about HTTP and Apache. And overall this has been a fairly smooth experience. But, for some reasons that I have had troubles to pinpoint up to now, JavaScript is the language that has been difficult to learn.

Blaming it on awkward constructs misses the point

For a while I have been blaming that on some unique JavaScript features such as closures or JavaScript Object-Oriented constructs. But blaming it on those is missing the point.

What makes JavaScript so difficult to use in a browser is that you need to learn much more than just a language!
To understand JavaScript, you need to know about:
- browsers
- the DOM
- the BOM
- a UI platform
- 3 different event models
- web forms
- cookies
- Ajax

You need to learn way more than just a language

When you know all that, you can finally start learning JavaScript and its awkward constructs!
And then you’ll probably learn to use at least one JavaScript library because it will make your life much easier!
And of course you will have to worry about many other concepts such as “progressive enhancements” or “unobtrusive JavaScript”.

The worse is that I am not even kidding, you really need to understand all of the above quite well otherwise you will not make much progress in your JavaScript practice.

So, no wonder JavaScript is so difficult to learn and use well.

But here is the silverlining:
1. This is fun!
2. Once you have developed all these skills, you will have become quite valuable!

Why PHP?

January 1st, 2007

We already have Perl, we already have Java, and both claim they can do the job on the web. So why introduce another language? Why use PHP?

P stands for Pragmatic

PHP is just the smallest tool that gets the job done. Why use anything else than a hammer when you just want to pound a nail in the wall.

Together with MySQL, PHP provides a simple and complete web solution on the server side. It is simple: you can create very quickly a web prototype. It is also highly scalable: some of the largest web sites use PHP.

Whether the task is to generate HTML, manage sessions or interact with a database, PHP always comes with a very simple solution.

A simple language

Many languages have difficult concepts to grasp; some of them are even weird at times. This is not the case for PHP. In fact, if you know any modern language, you should be able to learn PHP quickly.

The simplest tool for the job

PHP is a simple scripting language and you can certainly write sloppy code with it. However if you want you can write highly maintainable code; actually, you can easily write object-oriented code. In fact, PHP 5 can look very similar to Java (with one big hole: no packages/namespaces).

The best feature

The best PHP feature may seem like a little thing. The big deal is that you can mix PHP tags and HTML tags: you can put PHP code inside HTML tags, and you can put HTML tags in PHP code. This makes it a very pragmatic tool to produce HTML pages, the core of the web.

I heard at a conference that at one point Yahoo wanted to standardize their development on one language. They reviewed 10 possible solutions and they ended up choosing PHP: the deal breaker was that capability of embedding PHP tags directly into the HTML.

The best tool for web development

So, as far as I am concerned, on the server-side PHP is just the best tool for web development (i.e. web page manufacturing).
Now, I would not use PHP for anything else. But for that one essential task, it is an outstanding tool.


JavaScript has nothing to do with Java

January 1st, 2007

We probably have all stumbled on this one when we discovered the two names Java and JavaScript.

At both ends of the spectrum

Java? JavaScript? Probably the same language, right? Or at least very similar languages, like part of the same family, right? 

A marketing ploy

JavaScript was first developed by Netscape under the name Mocha, and later LiveScript. At that time the hot new language was Java.
I guess someone at Netscape must have thought that it would be cool to give that new language the name of JavaScript, confusing in the process generations of developers, managers and headhunters.

At the opposite ends of the spectrum

So the truth is that JavaScript has nothing to do with Java, except for the fact that both are modern software languages.

In fact if you rank current languages according to how structured they are, JavaScript will rank as one of the least typed, most dynamic, least structured, potentially dangerous and difficult to maintain and Java will rank as one of the most structured, highly typed and easier to maintain.

The Big Picture

December 18th, 2006

I don’t really care about details. This is something that differentiates me from most engineers: we, engineers, have the reputation to be detail-oriented.
It’s not that details are not important. In User Interface development, details are extremely important.
It’s not that details are never cool; sometimes there can be very cool details.
It’s just that I like big picture ideas so much. I am a sucker for big ideas, major trends, the last theory on the origin of the universe or the meaning of consciousness.

Luckily, there is a need for people like me: the Internet is full of details and too often folks are missing the big picture, missing the forest for the trees.

Missing the Big Picture

How often have you tried to learn about a new subject. You read an article or open a book that was supposed to introduce you to the basics of that subject, but just left you more puzzled than before. It basically explained a few important points but didn’t answer the most pressing questions you had. And it added more questions than you didn’t have.

AHA! Experiences

This is where this blog comes in. It tries to answer the first 10 big questions that you may have about a subject.
These often are the answers to the questions that puzzled me while I was learning User Interface Development. Sometimes it took me a few hours to figure out that stuff, sometimes it took me several months. Always leaving me with the same feeling: ”If only someone had told me this at the beginning”.

The right model in your mind

For most abstract domains: calculus, quantum physics, chess or software engineering, the trick for learning is to get an accurate model (or a set of models) on how things really work.
The goal here is to facilitate this building of a model in your brain: to give you the shortcuts to build these models quickly.

AHA! Experiences

One of the great thrills in my life comes when I figure out something new. It really doesn’t matter if I am the first one to discover it or if millions of people have figured it out already. This is the thrill that we must have when we take our first steps, the thrill of Helen Keller figuring out that everything has a name, the thrill of the inventors.

 This blog is very much about you getting that thrill. If while you browse through this blog, you think just once “This is interesting, I didn’t know that” or “now I get it!”, I’ll have achieved my goal.

On to the blog

So hopefully, you’ll have a good time reading my blog. If you’ve got other questions, critics, feedback, suggestions, do not hesitate to leave a comment. I’ll try to address them as time permits.

Why JavaScript?

November 6th, 2006

Why should you care about JavaScript? Is that because it is a cool language? What about ActionScript? What about Java?

JavaScript is in bed with the big guys!

The main reason you should care about JavaScript is that it has a unique position in web development: JavaScript is in bed with the big guys!

JavaScript is the only real programming language that is understood natively by the browsers: Internet Explorer, FireFox, Opera and Safari. It does not require any plug-in to be executed on the web page.

So, JavaScript may or may not be a great language, but it is the univeral client-side scripting language of the web! That’s why you need to learn it!