Posts Tagged ‘humour’

System.out.print in PHP

Friday, March 9th, 2007

We are recruiting people on a regular basis, and since it's sometimes difficult to find people with both a computer science background and PHP experience, we also recruit people that are fluent in other languages. Teaching a c++/java/delphi-guy to do PHP in general is easier than teaching a PHP hobbyist good engineering practices.

So yesterday I was reviewing a code sample that a job applicant had written during a test and I encountered the following line of code:

 
System.out.print($result);
 

It's not hard to guess what his background was :), but I was initially stunned that this actually works in php.

My first thought was that this was because I installed the Java Bridge from Zend Platform, but the bridging API does not allow the direct use of java objects like this. So was there some evil hidden hack in PHP?

Of course not; eventually the truth was uncovered by the notices in the errorlog:

PHP Notice: Use of undefined constant System - assumed 'System'

Ah, that makes sense. It just sees them as constants which do not exist and are interpreted as strings, and apparently, this is a valid PHP statement as well:

 
  "this"."is"."a"."string";
 

I cannot find any practical use for being able to write a statement without assignment or output like that, but it does enable code beautification:

 
  I.need.to.get.some.sleep(1);
 

Of course I would have to strongly advise against this but it was fun to notice that this works. :-)

P.S. shameless plug: this week we launched the first preview of our new web 2.0 pet project: http://www.mockatoo.com; not much to see just yet, but consider it a preview of what we are up to.

Exposing programming frustrations with Google Code Search

Thursday, October 5th, 2006

Recently, Google opened a search engine that will appeal to all developers: Google Code Search, for searching through all available source code on the web.

While this is great to find example usages of functions, or to find security vulnerabilities, a far more fun thing to do is delve into the frustrations developers encounter while developing code. Frustrations that are filtered out by the compiler, and are hidden away into source code comments.

This search for example is a nice one, and I had a good laugh at the first result of this search.

You can also see how programmers think about certain big corporations when using their API's. :-)

It's also fun to see how much faith developers have in their code.

Finally, it's nice to have a way to see how much legends such as 'foo' are actually used, and that some developers even put prayers in their programs.

One tip: if you search for PHP variables, prepend the $ with a \, as Google Code Search supports regular expressions, so you have to escape certain characters.