Further reading

Show me the code

at 2010-09-27 in EditorialFurther reading by friebe

After reading and agreeing with Show me the code some time ago, I thought about how to integrate source code examples on the XP Framework website. While lots of blog postings here contain sourcecode, this is not prominent enough - so I set up a new site dedicated to this purpose: The XP Code galleries. Enjoy:-)



Array dereferencing

at 2010-09-22 in Further reading by friebe

While array dereferencing was added to the PHP runtime's so-far unreleased SVN trunk a while ago, this feature isn't going to be backported to older PHP versions, which the XP-Framework will continue to support for quite a while. We've thus added a core functionality, this(), to make indexer access possible:

  $a= $class->getMethods()[0];         // Supported in PHP as of 2011*
$a= this($class->getMethods(), 0); // The XP-Framework way

* Educated guess, there is no communicated release date for PHP "next"



Y2K38

at 2010-08-25 in Further reading by friebe

In a recent Sitepoint article, the author talks about problems with PHP's strtotime() function, which can be basically summed up to this:

  $ xp -e 'Console::writeLine(date("l d F Y H:i", strtotime("2040-02-01")));'
Thursday 01 January 1970 01:00
The problem is the internal representation of dates, which will overflow and thus cause strtotime() to yield an incorrect value.

The XP Framework's util.Date class, being based on PHP's DateTime class, will not exhibit this problem, regardless of whether the system is 32-bit or 64-bit.
  $d= new Date('2040-02-01'); 
Console::writeLine
($d->toString('l d F Y H:i')); // Wednesday 01 February 2040 00:00
See also http://en.wikipedia.org/wiki/Year_2038_problem and - with a humouristic take: http://xkcd.com/607/



Generics in C#, Java, and C++

at 2009-11-14 in Further readingRFCs by friebe

In this interview from quite a while ago Bruce Eckel and Bill Venners talk with Anders Hejlsberg about generics implementations in C# and Java - the differences in their implementations, type erasure vs. runtime instantiation, reflection and how they compare to C++'s template mechanism. This has inspired us to come up with RFC #0193 - and moving our generics implementation closer to the one in the CLR.



Type hinting discussion and contracts

at 2009-07-12 in Further reading by friebe

In the recently ongoing type-hints discussion on the PHP internals mailinglist (see also the PHP Wiki), an interesting proposal was made. It suggests using functions to verify argument types instead of introducing a type checking mechanism which is not strict enough for some, not flexible enough for others and too magic for yet another group.

  function array_of_numeric($x) {
foreach
($x as $val) {
if
(!is_numeric($val)) return FALSE;
}
return TRUE;
}

class Arrays {
public
static function sum(array_of_numeric $a) {
return array_sum
($a);
}
}
See also here, here and here.



PHP-Arrays: Maps and lists

at 2009-04-05 in EditorialFurther readingRFCs by friebe

In the PHP world, arrays are maps are lists:

  $a= array(1, 2, 3);                // #1: A list
$b= array('key' => 'value', ...); // #2: A map
$c= array(1, 2, 'a' => 'b'); // #3: Mix of both

Now this is (almost) perfect as long as you stay inside the PHP world; the only thing you have to know is when to be able to use array functions operating on "associative arrays" (like asort) instead of "numeric arrays" (sort), which is usually achieved by a bit of discipline. This is where a slight problem even inside the PHP world (and that's why it's only almost perfect) starts showing: There is no easy way to keep the both apart.


(more)

Casting an object array to a string array

at 2008-07-19 in Further reading by friebe

While testing the new EASC server and client implementations we're currently working on, we asked ourselves how to cast an object array to, for example, a string array.

The following is an array of objects consisting solely of strings:

  Object[] strings= new Object[] { "Hello", "World" };

The first thing we tried was to cast it via (String[])strings. This is legal sourcecode but will raise a java.lang.ClassCastException in Java, and a System.InvalidCastException in C#, both at runtime.


(more)

Exceptions in Java

at 2008-06-25 in Further reading by friebe

Found this nice article on exceptions in Java - from a historic overview of Oak, on checked and unchecked exceptions, and asynchronous exceptions it explains nicely (and with code examples) what the Java exception mechanism is about. What I like most are the best practices section, which applies not only to Java:

  • Don't Write Own Exceptions
  • Write Useful Exceptions
  • Throw exceptions early
  • Catch exceptions late
  • Document exceptions
  • Unit Test Exceptions

http://www.javaspecialists.eu/archive/Issue162.html



Frank Kleine on Namespaces

at 2007-11-11 in Further reading by friebe

On a short note: In Gathering practical experience with namespaces, Frank describes his first impressions of PHP 5.3 with namespaces:


Oh boy. You should never even think about porting your application completely to namespaces if you do not have enough unit tests!

Reminds me of the rule of thumb that one never has enough unittests:-)



PHP6 Namespaces patch backported

at 2007-07-21 in Further reading by friebe

Beginning of this month, Dmitry Stogov from Zend published a patch implementing namespaces in PHP6.

To be able to begin playing around with it without adding further points of possible failures for our XP unittests with new PHP6 (e.g., unicode-related breakage), I started and after a day's work succeeded in backporting the patch to current CVS HEAD, that is, PHP 5.2.4-dev.


(more)

Subscribe

You can subscribe to the XP framework's news by using RSS syndication.


Categories

News
General
PHP5
Announcements
RFCs
Further reading
Examples
Editorial
EASC
Experiments
Unittests
Databases
5.8-SERIES
Unicode
Language
5.9-SERIES