Archive for January 2011

Post Archives
Archive for January, 2011

Yii and Zend for PHP = ASP.NET and ASP.NET MVC for C#

January 25th, 2011 2 comments

In the past I have extensively used ASP.NET and ASP.NET MVC in C#.  In C# they are basically the only options and it would be rather crazy to try to come up with your own high-level web framework on top of C# and rightfully so.  However when I moved over to be doing a lot of web development in PHP (see PHP for ASP.NET Developers which I blogged about before) things were not so rosy.  PHP is a great scripting language, many things are very simple to do and well geared towards web development.  However, a bad (and a good in some way) thing about PHP is that it’s a very low level language and doesn’t provide many of the higher-level framework nicities that is provided with ASP.NET and ASP.NET MVC straight out of the box.  By nicities I mean things like structured request routing and handling (with hooks/events), page lifecycle, MVC separation, configuration management (e.g. web.config), logging and so on.  It is also a fact that many PHP developers and participants in open-source projects are not professional programmers with an IT or software engineering degree.  What all of this has lead to is A LOT OF HORRIBLE ARCHITECTURE AND CODE.  Having looked through the source code of many many open source PHP projects, there is only a very very small handful that I would say are very well architected.  In some cases there is no architecture at all, in other cases there is some attempt at architecture but it’s not particularly good and in other cases things are over-architected to the point that making even a small change, let alone a complex change becomes extremely difficult.  For many users of these open-source projects this of course doesn’t matter as they don’t ever have to look at the code, but for anyone looking to make serious changes this is quite a problem indeed.  The best architected open-source applications I’ve seen are OpenCart (has it’s architectural flaws, but not too bad), being a Shopping Cart application, and Drupal (being a CMS).  Some people may say Drupal is not well architected because it’s not PHP5 Object Oriented code, but I don’t think you need to have PHP5 or OO for an application be well architected.  For example in C you can structure your application well, or you can structure it poorly and same goes for PHP.  You don’t have to use the latest technology to structure it well.  Sure there are obviously certain performance factors that come into play when you have load lots and lots of modules just to see if they’re enabled, but such is life when you’re building a configurable system.  Other applications in those classes of applications are not very well architected at all.  Here’s a non-exhaustive list:
Shopping Carts

  • PrestaShop – Pretty ugly architecture, poor file structure, doesn’t use MVC (poor form for a modern application), un-necessary use of Smarty for templating, all the admin code output using echoing directly out of modules instead of using MVC pattern, etc.
  • osCommerce – No programming standards, mix of code and markup, terrible code re-use, and just plain ugly bad design.
  • ZenCart – TERRIBLE design rooted in osCommerce that’s almost impossible to change if you try to make serious modifications as you have to change way too many files.
  • Magento – Over-architected to the point of obscrurity (not unexpected given it is based on Zend Framework) which impacts performance and requires lots and lots of caching.
  • Commercial Carts – This includes CSCart, X-Cart, etc – There is some attempt at decent architecture but often it still comes up short.

CMS / Blogs

  • Joomla – Over-architected MVC design and terrible rigid structure and security model.
  • WordPress – Horrible mix of PHP and HTML, although workable to some degree, it is far from well architected.
  • ModX – Ok-ish architecture but also rather ugly when you look at the code.

Now when it comes to frameworks, which is more the subject of this post, things don’t change much.  Most of the frameworks are also poorly designed and structured with their design patterns firmly rooted in PHP4.  This includes CodeIgniter, Kohana, DooPHP and pretty much every other framework I’ve looked at with the exception of Yii and Zend and perhaps Symfony and a few others (see Choosing the Best PHP Framework).  Ultimately after much research I’ve found Yii and Zend to be by far the best structured (with Zend over-engineered).  What I have found is that Yii Framework is by far the closest thing there is to .NET so I’m finding that any application that I’m looking to write even if it’s a console application is well handled by Yii, even if it’s because it has a decent architecture (which I can’t fault).  I’m finding that even for little PHP scripts without a user interface and simple web applications it’s easier and better for me to use Yii Framework even just because of the database access and configuration capabilities that it provides and of course the structured design.  I do find that it is still lacking a few things that are general framework classes (e.g. HttpClient, Application File System) rather than anything specific to do with web development).

Share
Categories: PHP Tags:

Yii vs Zend vs Code Igniter Comparision

January 6th, 2011 97 comments

Choosing a PHP framework is not an easy task, especially if you have relatively little experience in PHP to know what makes a good framework or and what doesn’t, but choosing the right PHP framework for the job is absolutely critical in the long term as choosing the wrong PHP framework can lead to a number of negatives, such as longer development time, need for more experienced staff who may be hard to find and of course performance problems.  Unluckily (or perhaps luckily) when it comes to PHP there is such a plethora of PHP MVC Frameworks that it’s damn hard to actually boil them down to the final choice.  With ASP.NET for example it’s quite easy (although it’s gotten a little more complicated lately), previously there was only ASP.NET but now there’s also ASP.NET MVC, which is very different development paradigm and has it’s own catches.  However, one thing with .NET is that you need to choose how you’re going to do your data access, etc, but with most PHP Frameworks there is usually only one or two ways and they tend to do the job quite well.  So, now with this brief introduction, here’s the thoughts on Yii Framework (1.1.5) vs Zend Framework (1.11.0) vs Code Igniter (1.7.2).

Read more…

Share
Categories: PHP MVC Frameworks Tags:

.NET WPF Project Solution Structure

January 3rd, 2011 No comments

I’m currently at the start of developing a fairly sizable project in .NET using C# with WPF.  As this is going to be quite a large project I thought it would be prudent to spend a bit of time upfront to organise it into some sort of a sensible structure which will see us through into the future, so that we don’t have to change it half way because things get too messy.  So I set out to find the appropriate solution structure for a WPF project.  A bit of googling turned up a few posts such as Recommended WPF Project Structure discussion on StackOverflow and WPF Project Structure by Dr. WPF, but neither gave a difinitive answers or detailed Pros and Cons of any particular structure.  So taking what I’ve read and my own experience my analysis is as follows…

Read more…

Share
Categories: .NET WPF Tags:

PHP for ASP.NET Developers

January 2nd, 2011 1 comment

ASP.NET is very nice to use for developing web applications but also comes with a few cons.  The biggest drawbacks of ASP.NET (including ASP.NET MVC) are that it’s more expensive to host than PHP (and you can’t use certain programming concepts if you want to host on shared servers because they require full trust) and you pretty much need to use Visual Studio to do the development (although you could use the Express edition if you’re doing something basic).

Because of these drawbacks some people (like myself) have looked at other options (of which PHP is one).  In the recent years PHP has matured into a pretty decent OO programming language, but raw PHP is still very low level and doesn’t give you much guidance or have much of a framework for implementing your applications.  This of course requires you to be far more skilled in PHP and application architecture in general and would take much more time.  Having a good IDE is also improtant for productivity.

Luckily there is a very nice solution to this problem.

  1. Use an IDE – There are two mature (and FREE) IDEs you can use to develop PHP.  They are Eclipse PDT and NetBeans.  NetBeans kind of comes with everything there (e.g. SVN and Mercurial support), but I still find that Eclipse PDT is the better option, especially if you’re doing much deployment via FTP (with the Aptana Plug-In).  Eclipse PDT also has much better SVN support than NetBeans when you add the Subclipse or Subversive plugins.
  2. Use a PHP Framework – There are far too many PHP frameworks around, and sadly most are not up to scratch or what one would be used to coming from the ASP.NET environment.  However, there are two awesome frameworks which have a good combination of performance, good architecture and are most similar to ASP.NET.  They are Yii Framework and Zend Framework.  Yii Framework seems to have borrowed may concepts from ASP.NET and is an absolute pleasure to use.  It even solves problems which are still a bit of a pain in ASP.NET (e.g. paging in lists).  It is also significantly faster than Zend Framework and hence is my preferred choice.  Zend Framework is more feature rich than Yii Framework, but it has a degree of complexity and doesn’t perform all that well in shared hosting environments.  If you want to use some Zend Framework features with Yii you can easily do so, so you can get the best of both worlds.

That’s pretty much it… By combining those two concepts you can do pretty much the same thing in PHP as you can in ASP.NET without the associated expense.

Share
Categories: ASP.NET, PHP Tags: