Lazy Mode

Lazy mode is just, being lazy while programming, but lazy in a good way. While working on agile environments or “just in a rush” kind of environment you need to come up with “lazy” solutions so time doesn’t come as an issue for the release date.

These lazy solutions are just simple configuration or automatic methods, config’s that can make your life for development and testing very simple.

For example, you work with 2 databases, 1 for development and another one for unit testing. Instead of having 2 environments configured and all files copied, why not have the same environment with a simple config.

If you work with cake this would usually be done as:

Config::write(array(‘server’ => ‘localhost’, ‘username’ => ‘user’, ‘password’ => ‘pass’, ‘database’ => ‘develop’)); // or something like this
// Config::write(array(‘server’ => ‘localhost’, ‘username’ => ‘user’, ‘password’ => ‘pass’, ‘database’ => ‘unit_testing’));

And whenever you would be using config A or config B, you would need to un-comment each line or config. Instead of doing this, why not simply setting the arrays as variables and calling them when needed. It requires more work at the beginning but it saves you a ton of time in the end and this is what is called the Lazy mode.

How this can fit on controllers and models. Simple, just break the methods in smaller parts in a way you can re-use as much of the smaller parts as you can. When you thinking in REST services, this lazy mode can and will save you a consider amount of time.

As an example, think of a users model that have several types of users. The basic information for each one is the same and, according to the type, you would retrieve one or more extra tables related to it.

Create a simple method that has a getUserByType where it retrieves the basic information with a switch where it would retrieve more information depending of the type. Off course, if one type carries the same information as the other, that would also became a smaller function to be called.

Off course we all have used this same concept with OOP or AOP therefore, just calling it lazy and making the concept a bit simpler, it can surely help during development time.

Talking about lazy, time to go and refactor that model that I have been lazy about it 😛

 

Advertisements

About mcloide

Making things simpler, just check: http://www.mcloide.com View all posts by mcloide

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: