Extensibility in PHP and .NET

August 12th, 2007

I’ve been programming more with C#/ASP.NET and less with PHP lately, and I think it’s interesting how they differ in extensibility. In PHP, it’s very easy to write something with a specific goal in mind. If you want to put data into an HTML table, you just loop through the data and write out the corresponding HTML. If you want to add some functionality to the table or render it slightly different on another page, you might end up having to rewrite it or duplicate code (of course, there’s always the option of using some third-party library of data widgets).

In ASP.NET, if you want a table of data you need to create a DataGrid, bind the data, set up the columns, etc. But when you want to change something, the framework you just set up allows for it.

I needed a way to reorder rows of data, so I made a DataGrid and gave it two columns for “Move Up” and “Move Down” buttons, and tied the buttons to a function that would swap rows. After I got it working for a particular set of data, I decided to turn it into a user control to be used with any set of data. The only change I had to make was replacing the column definitions in the aspx file with dynamic column creation code in the code-behind. Now, any DataGrid can be made into a OrderableDataGrid by replacing the definition tag.

Using multiple languages makes you a better programmer. Now, when I need to do something like a data grid in PHP, I’ll use what I know from C#/ASP.NET to make it easier and more powerful.

Leave a Reply

Name

Website

Comment