5 Life Lessons from PHP
I spend a lot of time writing code. The average week will consist of anywhere from 40-60 hrs of writing code for websites. While the majority of that time is probably spent writing ASP, HTML, and CSS, I’m also an enthusiastic PHP and Javascript programmer. I’m also beginning to delve into ASP.NET with C#, but would not call myself proficient in that environment yet.
One of my favorite languages to code in is PHP. PHP is a “server-side” language. This means it does all of the work on the server and then sends the results to your browser. There are a specific set of rules that must be followed carefully or else the code will not work. It occurred to me that this mirrors some of my life experience. Here are 5 life lessons that can be illustrated by the simple rules of PHP.
- Look before you leap.
- Sound advice. Don’t take any action before checking out what you’re getting into. PHP provides a basic mechanism for dealing with this life principle.
if (condition) {
// if the condition is true, do this
} else {
// here is your fallback plan!
}
How many tears would we avoid in our lives if we made a habit of running a simple if…then procedure before making a decision? - Persistence can pay off, but don’t get stuck in an infinite loop.
- We’ve all heard about the value of working hard, but what about working smart? Just like life, PHP provides an easy tool that allows you to pound away at a single task until it is complete.
while (condition) {
// continue repeating this until the condition is met.
}
There is a catch though! Not every task can be completed by simply pounding away at it. It’s up to you to make sure you don’t get stuck in a cycle with no way to get out of it! - Cookies can help make new friends.
- PHP allows you to give cookies to visitors to your website! A cookie is a small file deposited on the visitors computer that helps you remember who they are and what they like. If you’ve given a visitor cookies in the past, it is possible to instantly recall information about them. Your new friend’s favorite color, their name, or anything else they might have told you about the first time they visited, can be used to customize their experience when they return. Remember, not everyone likes cookies, so don’t be forceful (they are your friends after all). They are usually very nice in moderation though!
- Remember lessons learned from past trials.
- PHP has a built in way to journal any hurdles you overcome and provide notes to yourself if you ever come across the same problem again. Often, like life, writing code is a bit of a puzzle. It requires creatively putting together the simple rules of code (life) into steps that will ultimately yield results and, handling any unexpected circumstances that could rudely interrupt your well thought out plan at the wrong moment. What a great idea, learn from our victories!
- Have some constants in your life.
- Writing code is a lot like solving a math problem. One of the challenges of manipulating complicating problems is juggling all of the variables. Variables are nice because they allow you to change what they represent. However, this is also the tricky part; the more variable you have, the more complicated it is to keep track of the value of each one. Sometimes, a variable will inadvertently be changed to something it shouldn’t, and will compromise the integrity of the output. Thankfully, PHP (and life) allow us to use constants. Constants represent values that don’t change! While this will sometimes make your puzzles more challenging to solve, the end result is that having constants in your equation will give a firm foundation for reliable output.
No Comments »
No comments yet.