Starter Appengine Application with Facebook Login for Authentication

Right after it was merged, I though of improving upon my contribution on how to use Facebook Login on Python and Google Appengine. Though the latter works, one would still have to do some work to be able to use the techniques there in a project. So I thought to myself, why not do a starter application where you can use Facebook Login on Python Appengine right away?

So that’s exactly what I did with appengine-facebook-base. Here are major problems that are solved by this barebones application.

Read more

Factory Methods Over Introspective Builders

Not too long ago, I wrote about how fascinated I was with introspective builders. Upon further reflection, however, I thought to myself, should all my objects really have this following snippet of code?

I thought I smelled something here: code duplication.

Read more

Composer for the Win

composer

I have found myself in a lot of trouble managing the dependencies in our projects at work one too many times:

For one, we use a lot of open source libraries at work like Zend for our MVC, recently Symfony DI for our IOC container etc. I wanted a script or tool that would download all these plus all the libraries they use in one step.

I also wanted an easy way to be able to update these libraries when I wanted to. I thought of doing this before with svn:externals but I thought that wouldn’t work. What if I wanted to update the whole code base including the application code as well as our tests together? I think there’s a better way to do this than update the application code’s folder and then the tests folder. With svn:externals, it was impossible to do this in one step, at the root of the project folder, without the svn:externals getting updated as well.

Read more

An Introspective Builder Pattern Implementation

As I am creating apis at my current work where a client could post json data, at one point I got really tired of checking whether an array key exists so I could call the corresponding setter in the object I am building up:

Usually, when I am stuck in a situation like this where I want to write more elegant code, I usually turn to open source projects.

Read more

Choosing a New Framework

Over the weekend I found myself evaluating new frameworks to use.

The current framework I am using right now for my projects is the Zend Framework. I like that it has a lot of components, hence some people call Zend more of a component library. Some of the components I like are Zend Form and Zend_Resource_Autoloader which makes it easy for me to load third party libraries. One problem I have been having with it though is it’s lack of a Dependency Injection container. Right now I still have to either manually inject dependencies or instantiate dependencies in the constructors of classes where they are needed. It works but I don’t like it it. I think it’s dirty.

Read more

PHP, Java and Complicated Business Logic

When I just started out getting serious with software development, I asked the CEO of the company where I interned what he though of PHP. He said to me that, PHP was great at the stuff it does but Java was better at handling complicated business logic.

Of course at that time having little experience I did not understand what complicated business logic was. I left it at that and as the CEO told me himself during our classes, when he started out he didn’t understand what business logic was at first but but did so along the way.

I have been using PHP for one and a half years now and I really think it’s great at what it does. If I am going to create a website, I have no doubt in my mind that to use PHP. But there are some things that I miss from the Java world: the IOC container, Aspect Oriented Programming and IBatis.

Read more

Project Euler Problem 18 With a Reduce Formulation

I have seen a lot of solutions use two for loops for this problem but I just thought a reduce formulation is better. Here you go:

Read more

Should I Return an Object or Array?

In a previous post, I asked myself whether Data Access Objects (Daos) should return concrete instances of domain objects or their array representation. After a long time, I think I have got my answer already.

That is, returning domain objects should always be the way to go.

I myself have been returning arrays from my daos because I use them for my apis where I could easily json_encode arrays. But the thing is, the daos shouldn’t care whether it is being used for an api or not. All it cares about is that it returns the object.

What if you need the actual object because you needed to invoke some method in it? By returning an array, you can never do this. What happens now to api where an array is needed for json_encoding? Well then I guess the best thing to do is to just have a toArray() method (Doctrine 1.2 has this) that will return its array representation. This can be easily invoked after retrieval.

Read more

Using Reflection for the First Time

For this API I was writing last week, I needed to validate whether or not a parameter was valid by comparing it to one of the constants of a class. While I could do this through a long if else statement, I couldn’t help but think how this would scale in the future.

What if more constants are added? Right now, there are already 5 constants and it’s ugly to do 5 if else comparisons to validate validate an input. So I thought, is there a way to get all the constants of a class and then see if an input is among them using perhaps in_array()?

I did this using reflection:

Read more