Hello, Ruby!

December 12th, 2005

rubyonrails.comAfter months of resistance, I decided to join the Ruby on Rails bandwagon and read up on Ruby at a brick and mortar bookstore. I was unable to find Programming Ruby, but I found Agile Web Development with Rails and was able to read Appendix A, which was an introduction to the Ruby programming language. Ruby is presented as a terse object-oriented programming language. People experienced in other popular object-oriented programming languages will be familiar with Ruby’s OOP features. Before jumping into Rails, it seems wise to develop some background with Ruby. So, I decided against purchasing Agile Web Development for now, and I settled for the first edition of Programming Ruby, which is available online.

Development Process Illustrated

December 11th, 2005

The Website Development Process at pingmag.jp describes an iterative product development life cycle through a presentation that is “fun to look at.” The presentation focuses on the interaction between a web design firm and a client, but the interaction can be generalized to cover all product development efforts. This is a useful resource for introducing the development process to clients. It can also serve as a guide for developers who might need a refresher on the basics.

Women Business Leaders

December 10th, 2005
Posted in - blah - | 1 Comment

Jeff Wuorio’s 4 Ways Businesswomen Can Combat Bias discusses ways to fight detrimental views on female company representatives. Although it may be needed for a small company to fight these preconceptions through deception as Gini Dietrich of Arment Dietrich does, making a fictitious male entity the leader of a company that is headed by a woman simply reproduces discrimination against women in business interaction. Living in a time where widespread lack of progressive thinking makes notions of a female US president remarkable is unfortunate. Dietrich’s actions support the status quo. If potential clients are sensitive to doing business with a female business leader, then the performance of the business leader should be used to steer the prospect away from their preconceptions and persuade prospects into becoming clients. Supporting and increasing the success of businesses that discriminate against female business leaders helps discrimination persist in business settings. Female business leaders should use the talented knowledge workers that they have accumulated to help, through their business’s services, companies that are more interested in becoming more profitable and less fixated on extending sexual discrimination.

read more | digg story

On the Cost of HA

December 9th, 2005

A blog entry adds more insight to Jeremy Wright’s Web 2.0 Companies Need to Scale. As an IT administrator, I worry about the availability of Internet applications that run on the servers that I maintain. Perfection is something that I strive for personally, and I continually think about robust methods that will bring the availability of Web applications closer to 100%.

Although it would be ideal to deploy a high availability configuration, the cost of providing HA might be greater than what can be afforded by small companies. The benefit for small companies is most likely less than what would be gained from larger companies. The move to increase availability should be made after some analyses in a similar fashion that other business decisions should be made. A minimal analysis includes the costs incurred by adopting the move, the costs resulting from outages due to delaying the move, and the amount of change in the expected downtime of a service after the move is committed. Deploying high availability is an investment like any other. The potential gains from these investments should be evaluated before an investment is made.

The idea of waiting to deploy HA until the cost of deployment is less than the loss resulting for service outages is acceptable, but I disagree with the suggestion to wait for high availability to become an issue before giving it consideration. Unless it is cheaper to reimplement an application, scalability is something that must be considered early in the software development process. Although a highly available infrastructure might not be available at the same time that an application is deployed, the application should be engineered for easy introduction into a high availability configuration. Availability is a concern for all successful Internet applications. Developers, with their highly optimistic nature, should plan on their applications becoming successful.

read more | digg story

Polymorphism in PHP

December 8th, 2005

While thinking about a programming language deficiency, I rediscovered polymorphism. Overloading a function allows a function call to behave differently when passed variables of different type. I was trying to devise a method of simulating function overloading, because PHP does not support it. I considered implementing a function with an if-else statement ladder that tests the type of the actual argument and executes statements that correspond to the argument’s type. This technique may ultimately result in a monolithic function or a function implementation that is too knowledgeable of multiple class hierarchies. Rethinking a problem that I was hoping to solve with function overloading allowed me to accept the lack of this language feature and think of other techniques.

There are two problems that arise from the if-else statement ladder approach. The implementation of such a function would require the function to have knowledge of every data type to be used with it. This problem can be extended to knowing class hierarchies, if subclassing is involved. This means that an introduction of a new data type to be processed by the function would require the function to be modified, which creates the possibility that the modification will break other existing code that relies on the function. The second problem is having the function’s maintainer think about how the function should operate on the different data types that can be passed to it. This responsibility is better placed on the people who maintain the different data types.

One solution that deals with the problems in the if-else statement ladder is polymorphism. Polymorphism allows a set of heterogeneous elements to be treated identically. It is achieved through inheritance. In PHP, interface inheritance and implementation inheritance can be written explicitly through the use of interfaces and class extensions, respectively. Interfaces specify a class interface without providing an implementation. Classes from different class hierarchies can implement an interface, and in this way, it can be seen as different from abstract classes. When a class is defined to implement an interface, the language enforces a rule that the class implements all features of the interface. A method that operates on an interface will accept an object of any class that implements the interface, and it will function correctly.

Here is a toy example of interface inheritance, polymorphism, and PHP type hinting:

<?
	interface HasArea
	{
		public function area();
		public function areaUnit();
	}
	
	abstract class Shape
	{
		private $color;
		
		public function __construct( $color )
		{
			$this->color = $color;
		}
		
		public function getColor()
		{
			return $this->color;
		}
	}
	
	class Rectangle extends Shape implements HasArea
	{
		private $w;
		private $h;
	
		public function __construct( $color, $w, $h )
		{
			parent::__construct($color);
			$this->w = $w;
			$this->h = $h;
		}
	
		public function area()
		{
			return ($this->w * $this->h);
		}
		
		public function areaUnit()
		{

			if( $this->area() > 1 )
				return "square meters";
			else
				return "square meter";
		}
	}
	
	class Territory implements HasArea
	{
		private $name;
	
		public function __construct( $name )
		{
			$this->name = $name;
			/* not used in this example... */
		}
	
		public function area()
		{
			return 5;
		}
		
		public function areaUnit()
		{
			return "cities";
		}
	}
	
	function outputArea( HasArea $ha )
	{
		echo "The area is:  "
		 . " {$ha->area()} {$ha->areaUnit()}\n";
	}
	
	$HAs = array(
		new Rectangle("red",2,3),
		new Territory( "somename" )
	);

	foreach( $HAs as $HA )
	{
		outputArea( $HA );
	}
?>

Type hints help the PHP interpreter enforce the restriction that outputArea() operates only on objects of data types that implement the HasArea interface. Rectangle and Territory are from unrelated class hierarchies. outputArea() can operate on these classes, since these classes implement the HasArea interface.

The explored method accomplishes only some of the features offered by function overloading. In the above example, outputArea() was restricted to one argument. In some programming languages, a function can be overloaded on the number of arguments along with the types of those arguments and the order that those types appear in the argument list. This method, however, was useful in a problem I considered solving with function overloading.