PHP "Tutorials" - Portable Code 
PHP Tutorial Index

Portable Code


The term "portable" can mean a few things but when used in terms related to programming it usually means something about being able to re-use the same code over and over again, especially if it can be used on different software platforms with little to no modification.

In this article, I will use the term "portable code" to describe code that is the opposite to, what I call, "hard coded" code. If you hard code something it will do the task you want but if you want to add or remove some data from the processing, you need to modify the code to handle it. Portable code (how I am using the term here) is designed to handle an arbitrary amount of data.
Just a small note here: the word 'arbitrary' basically means "unknown". For years I didn't know what this meant until I looked it up.
Portable code is usually harder to design and create from the start, but in the long run it is much better than hard coding your scripts unless they are designed in a way that hard coding is all that will be required and little to no modification will occur in the future.

For example, consider if you make something that works with database records. When you display the data from the database, you have two options:

1. Create the table and use the field names in your code when displaying them
2. Create your code so it can handle an undefined number of fields when displaying database data

The first option is easier at the start because you know what you want to achieve and you know what you want to display. The second option is a bit harder at the start, but once you create the code to handle any given amount of data for displaying you will never need to write code to do that again.

You will need to learn which functions will help you achieve the task you want to perform. Because each task and data requirements differ, you need to access the best functions to help you obtain your goals.


This article is not finished. I will add examples later.

PHP Tutorial Index