Entries tagged "coding practices"

Getting Your Projects Done Faster by Writing Less Code with the Short-hand if()

Have you coded a simple if() construct that sets a variable to one of two values and thought to yourself "Five lines of code; there should be a better way?" Okay, maybe it's just me. Either way, let's take a look at the Ternary Operator [aka the short-hand if()]. [Continue reading]

Condensing if() Constructs to Improve the Scanability of Your Code

In a previous post, we went through the typical setup for the if() construct. The good thing (or bad) is that there's a lot of freedom when it comes to writing code. You could for example write the entire if() construct that contains dozens of lines of code and never use a line break. You could, but I wouldn't necessarily recommend it. However, there are other non-"standard" ways of writing out your if() constructs. [Continue reading]

Small Changes to Make If Statements Easier to Scan

When developing programs with hundreds of lines of code, it's beneficial to write code that's easy to scan. That way when you're updating the program months or years later, it will be much easier to follow along. In addition to breaking the code into logical chunks, adding comments, etc., it's helpful to indent code which only gets executed given a specific criteria…such as code that's within an if/else statement. [Continue reading]

Reduce Website Maintenance by Importing Common Contact Information with PHP

While working on websites, one thing I've learned over the years is that change happens. People will leave the organization. Organizations change names. When change occurs, the thing we need to keep in mind is how that change affects the website. For example, if someone retires and their contact information is listed dozens or hundreds of times throughout the website, it's going to take a while to update everything. But this type issue could be avoided. Instead of hard-coding the information everywhere, it could be imported with PHP. [Continue reading]

Future Proofing Your Google Analytics Code for Tracking PDFs

A few years back, I started using Google Analytics to get a better idea of what people are viewing on our websites. To be prepared for future revisions of the tracking code, I thought all I needed to do was store the code in a file called "GoogleAnalytics.html" and import it into the pages we wanted to track. Then as Google releases new versions of the tracking code, I would only need to update the GoogleAnalytic.html file for each website. [Continue reading]