Wednesday, July 28, 2010

I should Explain

So I had my other blog setup but we had some trouble with our hosting provider (read 'they suck')
So we switched to another dedicated Host.
I guess if the need actually arises I will move the blog to our dedicated host, but for right now I think I'll just use blogger and forward my blog.bendemott.org domain here.

Whats New?
So currently we are working on an internal project at my company (Ecommerce) that manages product data. I wrote several documents about a year ago describing how I wanted the application to work (how it NEEDED to work) - And now that we are wrapping up major development it's great to see the vision come to a head.
I couldn't have done it without my two great friends, and colleagues Josh Burns, and Caleb Burns...
So thanks guys!

Currently the product management system we wrote has an Administration Component, a Server Component, and all of its utility classes - It's written in PHP - but I feel the days of PHP development at my company are numbered - we keep moving more and more to Python; which brings me to the next subject.

PYTHON - Why and Where.
At my company all back-end processes are written in Python pretty much. Image management, servers, long-polling (comet) servers, all sorts of stuff that just cannot be done with PHP.
The more I work on complex applications the more I realize the future of web applications is grim if writing stateful servers/web applications isn't possible.
What I mean by "stateful" is not support of sessions, but an actual Main-Loop with shared resources or shared singletons. My understanding is that this is how most Java Web Frameworks operate - however if you don't already know Java is not my cup of tea.
Overall it would seem that the more business logic we write in Python the more reusable the code is because we don't have to build quite as 'purposeful' code in order to gain slight efficiencies.

PHP - The Bad and Good'
We use PHP in our organization and used Zend Framework. As I've become closely acquainted with Zend Framework the only thing I really like is it's 'ease of setup' and the storage and organization paradigms. It's a great thing when anyone (almost anyone) can come to your code and understand its structure immediately... HOWEVER - Zend Framework is bloated, their Autoloading is bloated, and out of the box the MVC or Zend_Application() / Front Controller takes 1/20th of a second to render a page on our hardware. This is a completely relative figure, but in general the way the MVC / Routers work is just not efficient enough for any serious web application.
When it comes to PHP we also do some hacking in order to gain more efficiencies.
For example - in PHP class instantiation is expensive!!! (see Magento).
So we employ Singletons and Static Methods as often as possible - this means that we don't use Interfaces even when we should - just to gain efficiencies... Instead we write unit tests that compare classes against an interface so there is no additional overhead at runtime (sounds retarted I know)
But when you call a class/method PHP has to...
1.) determine real path of CLASS
2.) Parse CLASS
3.) determine real path of IMPLEMENTED INTERFACES
4.) Parse INTERFACE(s)
5.) CHECK METHOD existence / (abstract/interface)
6.) CHECK METHOD access/type (private/public/static)
7.) PERFORM THE CALL

PHP for its faults is a great scripting and utility language in my opinion however!
What it lacks for in Python stability, and Application Language features it makes up for in ease of use, and templating.
The ability to go in and out of HTML makes PHP work better than most other application languages for echo'ing TEXT to stdout (which is all a web application does!!!).
At my company we combine PHP and Python together, and one of my long-term goals is to embed PHP inside of Python for templating.
You may think thats mad, but Python has it's own Templating languages already and if the interpreter could read .php files and map Python Variables to PHP data types it would be a match made in heaven.


In the end my appreciation for Python as a Language for accomplishing tasks big and small and code-reuse is growing... While my appreciation for PHP is lessening. It seems recently PHP has gained somewhat of a Ruby on Rails movement with some of its large frameworks.

For enterprise level PHP development these frameworks are just overhead.
We don't use Zend_Db -> we use the postgres functions - WE ARE NEVER GOING TO SWITCH TO ANOTHER DATABASE!
We don't use Zend_Session we use MongoDB to store sessions and interact with them directly in a manner that suits our application design.
We don't use ORM or Doctrine - we use purpose built classes that make MongoDB and Postgres queries where needed - Our code is obvious and apparent to read, no magic, and no overhead - Just direct calls.

Use technologies and C extensions for application engineering - be wary of one-size and shared-host solutions in PHP. Also be wary of PHP code libraries - The overhead can get extremely expensive very quickly.
Maybe someday PHP will be stable and memory-leak-free enough to have its own Main Loop. But it seems like that's a long way off.