Developer Blog

  • Blog
  • /
  • Naming libraries properly
By Dracony on 23 October 2014

Just today I posted a forum poll on whether PHPixie 3 components should be named in a more creative way to underline their modularity and independence from the framework itself. People are more likely to use a Sprite library for their image processing than PHPixie/Image which looks like it was ripped out from the framework.

But there is a huge problem with such naming:

1
2
3
4
5
6
7
//This:
$orm = new \PHPixie\ORM();
$orm->getModel('fairy');

//Looks much more sane than this:
$unicorn = new \PHPixie\Unicorn();
$unicorn->getModel('fairy');

I was always under the impression that branding should be separated from the actual code as much as possible, this is why even though PHPixie often mentions fairies in the examples, you’ll never see something like a Model::fairyDust() method. So then I considered keeping the class names as they were and just saying that the library is called Unicorn on the site. I then could use that name for branding to make it recognizable, but keep it out from the actual code.

And now I think I found a simple method to have both branding and concise class names. All I need to do is shift the classes down one namespace.

1
$orm = new \PHPixie\Unicorn\ORM();

This is such a simple solution, but it solves everything. I am not terribly concerned that the classes will grow a slightly longer namespace. Especially so considering that it all can be hidden in a use statement like:

1
2
use PHPixie\Unicorn\ORM;
$orm = new ORM();

Now I think that this might be a great idea for other projects to adapt too. What do you think?

P.S. I’m not actually going to name the ORM component Unicorn, so don’t worry =)

comments powered by Disqus