Amptools.Net

simplify your life.

Archive for May, 2009

PHP lacks true object comparability

No Gravatar

For those of you who read the f* manual and see that section called object-comparison. You already realize that its a misnomer or you might be oblivious to another reason why objects in PHP are still second, even third class citizens.

Currently I’m writing a moderate set of Types for (granted i have most of it already written, i’m going back and for the first ctp just releasing the core types, which means i need to document, test, and test some mo). And for those of you that think this is a crazy idea, welp the PHP internals have started to do the same things themselves…. just lacking documentation and anything really useful at the moment. This just adds to why PHP feels like the IE of programming languages and a complete blight.

I think its sad that PHP 5.3 is currently at RC2 as I write this post and the only thing you can really check with object is equality using ==. You can not use operators like greater than (>), less than(<), etc on objects in PHP. The code below will illustrate php’s lack of true object comparison. Though I won’t say this takes away from the whole notion that PHP is enterprise ready, it does take away from the ease of use of objects in PHP and thus could take away from its maintainability.

class Midori_Int32
{
    public $value = 0;

    public function __construct($value = 0)
    {
          $this->$value = $value;
    }
}

 $a = new Midori_Int32(45);
 $b = new Midori_Int32(10);
 //this would be legal, for shallow checking use ==, use === for deep comparisons
 $condition = ($a== $b)
// this is illegal in php
$condition2 = ($a >= $b);

In Ruby (where everything is an object) they allow for operator overloading on method so you can define custom object types with comparability.

class MidoriInt32

  def initialize(value)
       @value = value
  end

  def === (obj)
    return @value === obj
  end

  def > (obj)
    return @value > obj
  end
end

a = MidoriInt32.new(3)
b = MidoriInt32.new(4)

condition = (a === b)
condition = (a > b)

though it may be unknown, you can do the same in dot .net using . If you need to override things like math operators or type conversion you need to check out the wicked cool

using System;

public class MidoriInt32 : IComparable
{

     public MidoriInt32(int value)
     {
         this.Value = value;
     }

     public int Value { get; set; }

     public static MidoriInt32 operator +(MidoriInt32 objA, int objB)
     {
          return new MidoriInt32(objA.Value + objB);
     }

     public static MidoriInt32 operator +(MidoriInt32 objA, MidoriInt32 objB)
     {
          return new MidoriInt32(objA.Value + objB.Value);
     }

     public int CompareTo(object obj) {
     {
          if(obj is int)
                return this.Value.CompareTo(obj);
          else
                 throw new ArgumentException("Object is not an integer");
     }
}

// test
class TestStuff
{
     public void Test()
     {
           var a = new MidoriInt32(3);
           var b = new MidoriInt32(4);
           var condition = (a > b);
           var condition2 = (a === b);
      }
}

Tags: , , , ,

Monday, May 25th, 2009 Blog Comments

Isapi Rewrite 4 rules for wordpress

No Gravatar

For those of you who might be using Isapi Rewrite 4 on a .net host and yet using wordpress for a blog, here are the rewrite rules. Most blog posts only show things for the index and maybe the wp folders. They tend to leave oout the xmlrpc file which is vital if you plan to use something like windows live writer to make your blog posts.

RewriteBase /
RewriteCond ${REQUEST_FILENAME} !-f
RewriteCond ${REQUEST_FILENAME} !-d 

# For special Wordpress folders (e.g. theme, admin, etc.)
RewriteRule /wp-(.*) /wp-$1 [L]
RewriteRule /favicon.ico /favicon.ico [L]
RewriteRule /xmlrpc.php /xmlrpc.php [L]  

# For all Wordpress pages
RewriteRule ^/$ /index.php [L]
RewriteRule /(.*) /index.php/$1 [L]

Tags: , , ,

Monday, May 25th, 2009 Blog Comments

Where do we go from here? Can blogs reboot?

No Gravatar

Its always to good to take time to do inventory and some form of introspection.  This is essentially my blog’s reboot post, similar to how Batman Begins or the Hulk 2 rebooted its theatrical franchise.  Even though I do not resonate with my age of almost 30 in appearance or actions, I am at the cross roads all to soon.  Circumstances, experiences, and their timing have forced me to really rethink about the overall picture of this thing called life and the importance or value of various things to shift in this very tiny brain of mine.  What are my overall real goals? How do I get there? How do I keep it fun and real while doing so?  How do I make sure i have enough time to stop and smell the roses along the way?  

So what is the overall goal of this blog? To provide a source of information that seems to help bring simplicity to complexity, inspire growth, or provide humor among the seemingly dismal current human condition.  Obviously one of those ways of bringing simplicity is to build software tools (especially for developers) to make life easier. 

So what is going to be my niche technical focus?  /.Net comes to mind (essentially the business value of Mono and the cool technologies of .NET like WPF or ), though I think I will be cursed to also discuss from time to time as the world spreads this blight of a programming language like it does IE6. Outside of that I will probably leak life personal experience from time to time as well, cause well, there is more to life than code. 

Thursday, May 21st, 2009 Blog Comments

midori php

No Gravatar

Midori-PHP is the PHP version of the Midori Generative Framework.  Its aim at providing building blocks and springboarding into creating an application.  

Midori-Php was created in order to be used with the Zend Framework initially to bring in some rails like concepts as well as help generate the data layer with a type system.  PHP unfortunately is not a pure object oriented language and lacks core classes similar to what ruby and many other popular languages have to day.  On top of that problem what types PHP’s SPL does provide is surely lacking in both power and simple api, instead conforming to keep the terrible naming convention of its functions.   

Source Code

Tags: ,

Tuesday, May 12th, 2009 Wiki Comments