I’m a PHP Expert!

OK, OK, yes, this post is partly blatent self-promotion, but it’s also a moment of honesty and a hopefully-interesting reflection on an interesting little test that I did today.

What I do know

Here’s the facts:

  • I do class myself as an expert in software engineering – the process of solving a given real-world problem using computer software.
  • I do class myself as a very good developer and can quickly turn my hand to new languages and tools for developing software.
  • I do class myself as a very good web developer.  I know back-end technologies like databases, SQL, and server administration; I know application development technologies like PHP and MVC frameworks; and I know front-end technologies: HTML, CSS, JavaScript and jQuery.  Plus, importantly, I understand the purposes of each and the interaction between them.
  • However, I would only class myself as upper-intermediate in my PHP skills.  Yes, I’ve been using PHP for 4 years are part of my job, but it’s not been a full-time occupation and I’m still learning some of the more detailed aspects of the language.

So, to prove my worth as a PHP developer, a recruitment consultant sent me a PHP technical test yesterday, and I was a little surprised by the result.  I got 95% and was in the top 4th percentile of people who took the test.  It suggested that, far from being intermediate, I was a PHP expert!!

A confession

A slight confession is needed at this point.  The test had a time limit and I approached this test as I would approach a working situation with a tight deadline.  If I could quickly look something up and understand it enough to answer the question (like, which parameters get passed to a given function), I did, but if it was going to take a while to understand I would either work it out or skip the question.  So yes, I did quickly look a couple of things up, but I also skipped those questions that I genuinely didn’t have a clue about.  And I completed the test in average time.

Even so, I found the test tricky and felt far from confident at the end.  Why then, did I manage to do so well?

Languages are just tools

It’s a become a bit of a cliche for me that “languages are just tools”, but there is a lot of truth in that.  My A’ level computing teacher used to say that languages were like screwdrivers or chisels are to a woodworker: a good woodworker can pick up a new tool and use it effectively, the important thing is to know how to do woodwork – how to fit bits of wood together to build things.

I did well at this test because I have a deep understanding of the building blocks of writing code; things like what functions do, recursion, variable scoping, operator precedence and associativity, objects and classes, bitwise operators, loop invariants, interactions between different elements of the system (the database, back-end and front-end), and so on.

I understand the fundamentals of abstraction, encapsulation and decomposition upon which every program should be based.

These are advanced programming concepts that someone who’s just learned a bit of PHP out of a book won’t understand, but which I can apply to pretty much any programming language.

And to demonstrate the point, I’ve used languages as diverse as:

  • Scheme and Miranda (functional);
  • C, Pascal and Ada (procedural);
  • assembler (low-level);
  • SmallTalk (object-oriented);
  • JavaScript (most of the above, plus event-driven)
  • Perl and PHP (text processing);
  • Prolog (logic);
  • and SQL (declarative, query-based).

An example

The operator precedence question is a good example. Not giving too much away, the question was along the lines of:

What output will you get from the following statements:

x=4;
echo x<=6 ? ‘less than or equal to’ : ‘greater than’ . ‘ six’;

NOTE: Apologies to those that don’t code at this point – this won’t make a whole load of sense.

It’s a clever question because it lures you into thinking that the code is correct and will print ‘less than or equal to six’, but it actually prints just ‘less than or equal to’, because the precedence of the conditional operator is lower than that of string concatenation.  In case you’re wondering, no, I didn’t look this up as I know that the ternary operator has quite low precedence.

It’s also worth nothing that this is, in my opinion, ambiguous code and any statement like this should always be written more clearly:

echo (x <= 6 ? ‘less than or equal to’ : ‘greater than’ ) . ‘ six’;1

Adding parentheses adds no computational overhead 2 and makes the code easier to understand.

Learning languages

Do I also have evidence that learning new tools and languages is easier if you have a good grounding in computer science?  Well, yes.

I was recently on a training course where we were learning a tool that had a built-in scripting language.  Some of the other guys on the course didn’t have my computer science background and theory. 3

When we got to doing exercises, they raced ahead for the first few, applying the specific bits of knowledge about the language they’d picked up from the course slides, while I was slow, asking questions like “what does that function return?”, or “why does that query do what it does?”.

However, come the later exercises, where you had to do more than just refer back to the the slides, I’d gained a deeper understanding of the language and raced ahead.

Conclusion

I’ve always believed that a thorough grounding in the principles of programming makes you a better coder than someone who just picked up a book and started writing code.  Occasionally I see practical evidence of this being the case.

Yesterday’s test proved to me that, while I may not know the exact syntax and purpose of every last PHP function or configuration setting, I can still be a PHP expert, and that I have skills and knowledge that are more valuable than I thought.

Perhaps tomorrow I’ll be a C# expert!

  1. You can argue about putting the comparison operator in parentheses too, but it’s pretty safe to assume that a simple numerical comparison will have greater precedence over the conditional operator.
  2. OK, perhaps a TINY overhead when PHP tokenises the script.
  3. If they’re reading, I hope they don’t mind me sharing this story!