Friday, February 9, 2007

Type Safety

As you know, PHP has dynamic type variables which is not type safety. I am not good at such programing language like PHP. So I had used the concept of type safe in XCube.

HTML is just text. Therefore, it's very powerful that PHP has string type. But, are you happy at integer variables can take string? Other languages have an excellent cast mechanism. Perhaps, it's enough spec. PHP doesn't need such casting, but it's not useful but dangerous.

XCube has property classes for some primitive types. You can use these classes in XCube_ActionForm. And, these classes will be used in XCube_Object so that XCube_Service will handle WSDL well.

I say there is the following structure;

struct student {
  string first_name;
  string last_name;
  int hight;
  int weight;

You can write it as the following;

class student {
  var $first_name =& new XCube_StringProperty("first_name");
  var $last_name =& new XCube_StringProperty("last_name");
  var $hight =& new XCube_IntProperty("hight");
  var $weight =& new XCube_IntProperty("weight");

It is good at fetching requests from user access and XML web service. Especially, in XML web service, WSDL offers structure informations that XCube primitive classes can match with.

When I come back to XCube from my job, I always think that dynamic type variables are not good. Of course, in some parts, PHP is excellent than other languages...

No comments: