Entries tagged "coding practices"
Lessons Learned: Management Program for the Plan Preparations Guide
Several years back, I developed one of my first in-depth PHP scripts. The goal was to create a voting mechanism for a set of notes posted online. The vote helped committee members decide on whether specific notes should be removed, moved, or changed. Although the completed solution wasn't perfect, it was an excellent learning experience. So I wanted to share a few things I learned. [Continue reading]
Alternate Way to Write PHP Function Arguments Part 3: Manually Throwing Errors
Using associative arrays for function arguments allows for more flexibility. However, we do lose some important features when it comes to building and calling functions. Packing all those arguments into an associative array prevents PHP from automatically detecting when required arguments are not included. But, there is a way to simulate this feature. [Continue reading]
Alternate Way to Write PHP Function Arguments Part 2: Using Associative Arrays
The standard process for building user-defined functions is to manually list out the arguments. The problem with this method is that the arguments need to appear in the order given. If the function has several optional arguments, you need to pass a value for all arguments just to specify the last one. Well, let's look at an alternate way to write functions which provides more freedom. [Continue reading]
Alternate Way to Write PHP Function Arguments Part 1: The Standard Process
When calling user-defined functions, there are occasions where it feels like optional arguments become required. I've seen third-party solutions like WordPress find a way to get around this issue. But it wasn't until recently that I've attempted my own solution. Before getting into an alternate method of passing function arguments, however, let's look at the standard process. [Continue reading]
Alternate Way for Adding Labels to Online Forms
To make HTML forms more accessible to those using assistive technology like screen readers, we need to use <label> tags to associate the field labels with the corresponding fields. It wasn't until recently that I realized you don't always need to add an id attribute to field that you're attaching the label to. There is another way and it requires less typing. [Continue reading]
Remove Unnecessary Code by Rethinking Your Default Setting
Over the past few years, I've spent a lot of time revamping my old code. I've been doing what I can to simplify, simply, simplify. While going through the code, I started noticing a pattern when it came to setting defaults. Let's take a look at a quick example and see how I was able to remove the unnecessary code. [Continue reading]
Avoid Overly Complicated Code by Stopping Scripts Early
The if construct is commonly used within PHP. It lets us execute blocks of code based on certain condition(s) being met. We can even layer if constructs within if constructs to perform operations that are very specific to the task at hand. While this gives us greater control over how the overall script executes, there may be cases where piling on the if constructs can lead to unnecessary complications. [Continue reading]
Using phpMyAdmin as a Checklist for Columns Used in a Script
One of my many coding habits I've been changing is the use of select all (SELECT *) in MySQL queries. Scripts usually don't need all the columns and grabbing unnecessary data reduces efficiency. Fixing the references usually involves me digging through the code, remembering the column names actually being used, and updating the query. This method works well when there are only a few columns to worry about. It gets more complicated with more columns or when they're used throughout a large script. That's where phpMyAdmin comes to the rescue. [Continue reading]
Simplify Website Experiments by Creating Test Folders
While experimenting with new website features, I'm not always consistent with managing the files. I usually duplicate the file being updated, but sometimes I edit the original while other times I modify the duplicate. This normally isn't a problem since most projects are completed relatively quickly. However, there are times when a project is placed on hold. Depending on how long I'm away, it can be difficult determining which file to edit when returning. So let's talk about ways to differentiate the files. [Continue reading]
Prevent Broken Links in WordPress Posts by Using Root-Relative Links
WordPress does many magical things behind the scenes. HTML tags needed to display a blog post are added for us. Posts tagged with keywords are automatically connected to other posts with the same tag. Side bar widgets generate lists of recent posts, most used tags, etc. with no intervention from us. We just need to write the posts, add the tags, activate the widgets and WordPress does the rest. With all these automation features, I have overlooked a potential flaw in the system—they use absolute links. [Continue reading]