PHP Programmers must Harness the Power of Laziness
July 5, 2013
Normally people think of laziness as being something negative. Generally it is, but when it comes to programming, laziness can be a virtue. But why?
Programming is all about saving time.
Don’t forget that the whole point of writing software, is to automate some process … to save time. You should carry that forward, into your actual programming as well, where you are always looking for ways to make your code and your coding more efficient. In PHP that can mean:
- Leveraging PHP libraries – never write from scratch.
- Learning OOP PHP – harder at first to learn, but in the end, writing OOP PHP will save a lot of time.
- NOT using PHP when other more efficient options are available.
I think the last point is the only one that needs clarification. PHP is a great language, but sometimes it may make sense to use some outside language or even the server itself to get the job done.
For example, let’s say you need to run a PHP script say every day. The easiest way to get this done would be to run a cron job on your server. This functionality is built into any Linux server and a simple command can be used to run whatever PHP script/page you want:
0 0 * * * php /var/www/vhosts/yourdomain.com/httpdocs/scripts/myphp-script.php
The above cron code will cause the server to run your PHP page every day at midnight.
Some people may want to figure out a way to do this all in PHP, buy why bother when you can get the job done with one line of code?
What we can learn from the lazy?
The larger point is to always look for ways to save time – lazy people naturally look to do this all the time. They don’t equate success with lots of hard work, they equate success with getting the job done as easily as possible – you should too.
… Of course, some lazy bastards are so lazy, that they equate success with doing nothing at all. That doesn’t work to often unfortunately!