programming

Inversion of control is the answer to more maintainable, testable, modular code, a common pattern in OOP adopted by frameworks and enterprise projects.  The main idea is to separate configuration (class names and initialisation parameters) from implementation (class instantiations and static calls), avoiding hard coded class names and parameters, so that they can be replaced by third parties and during tests.

There are at least three common ways of injecting dependencies (see here for a detailed description).

Constructor Injection: injection through constructor parameters

For every object, all the dependencies are passed as constructor arguments.  Constructor injection is fairly straightforward and works quite well on small projects, but as a project and the number of dependecies grow, so do constructors' signatures length.  Complex constructors are eventually refactored to receive an array of dependecies or moving them up in the hierarchy, in some base class, which evolves into a registry of dependencies (among other responsibilities).

Setter Injection: public setters for every dependency

Every dependency is set using a public method inside a class. For instance three classes depending on a Mailer would have each a `setMailer($object)` method.  Fairly simple to implement but leads to duplication and maintainability issues, every time an object is created all the setters must be called.

Service locator: holder/registry of components/services

All the dependencies are provided by a builder, which serves as a registry of dependencies and/or service definitions. The service locator knows how to instantiate each dependency.   Such service exposes methods like `getMailer()`, `getLogger()` etc.  A service locator centralises the configuration detailing classes and parameters involved on objects instantiations.

Select is a static Service Locator implementation with PHP method overloading.  It allows to replace classes and can be used to hold components/services, identified by unique names and automatically exposed with getter methods.

Select is designed to be subclassed with a custom class name, as opposed to the common injection through constructors.  To replace Select you subclass the main class.  For instance: during tests you can either use a different set of definitions (suggested) or use a mocked Service Locator class implementing the same interface iSelect.

There are many things you can do to speed up your website. This article focuses on practical things that I used, without any spending money on additional hardware or commercial software.

http://tr.im/xs6y

  • Cache PHP output
  • Create turbo charged storage
  • Leave heavy processing to cronjobs
  • Optimize your database
  • Save some bandwidth
  • Store PHP sessions in your database

About PHP sessions and DB usage I would like to add something: do not use them unless you really need them! Start php sessions and open db connections when needed. Do not put them in the boostrap/frontend file.
HTTP is stateless, try to keep your site/application the same, it makes caching and load balancing a lot easier.
In some context, site content related to user sessions can be loaded using ajax. And DB data can be cached into memcache.

You may also consider stracing your web processes to optimize disk usage. E.g. your Apache could be configured to look for index.html and index.htm everytime the homepage is called. See DirectoryIndex.

An article outlining the digg.com engineering teams switch from svn to git. Basically sings git's praises, without getting technical.

Git is a distributed revision control system (while svn is a centralized one) where you can perform commits, branches, merges on your local working copy, without being connected to Internet. It allows, for instance, to commit multiple local commits as a single commit, even to a svn repository.

From: http://www.programmerq.net/blog/2009/mar/10/accessing-git-through-firewall/

A decent number of things are blocked where I work. SSH is not. I usually use git via SSH. I did want to clone someone's repo that was shared over the git protocol, so I typed in the git-clone command, and waited. It timed out. The quick fix would be to clone it to my home machine, and then clone it over ssh. I never like doing that though, I like origin being the actual origin. I decided that it shouldn't be too hard to get a clone to work, so I did a bit of googling. I figured that if git had any support for a proxy server, it'd be possible one way or another.

Twisted is a networking engine written in Python, supporting numerous protocols. It contains a web server, numerous chat clients, chat servers, mail servers, and more.

Twisted is a platform for developing internet applications. While python, by itself, is a very powerful language, there are many facilities it lacks which other languages have spent great attention to adding. It can do this now; Twisted is a good (if somewhat idiosyncratic) pure-python framework or library, depending on how you treat it, and it continues to improve.

Syndicate content
© 2011 Devis Lucato @itbus.