Topics
Dates
200902 · 05 · 06
2008
01 · 02 · 03 · 04 · 07 · 08 · 09 · 11
2007
06 · 07 · 08 · 09 · 10 · 11 · 12
Also check out FishoftheBay.com for more thoughts about design and life.
Always Coding Generically
PHP February 08, 2008
I've been programming websites for a while now and though I often do things fast for prototyping purposes, I find myself wishing I coded in a more generic manner.
Sure, it's easy to go ahead and write the code as you need it, but eventually you get to the point where everything can be jumbled up and it's hard to find what you're looking for.
The solution?
Set up a class-like, object-oriented structure and create a whole slew of variables at the top of the document. This way you can quickly change them without having to scroll through all the code and find all the spots where you might use the same value.
For example, I may create a website that's specifically for use by me only. Therefore I put in a lot of default values. If I simply save those as variables at the top of the document, it makes it much easier to take the platform I've built and extend it (perhaps to other people or just to other uses).
Besides creating variables, put as much in-line code as you can into a function. Yes, you have to think a little bit more about parameters and whatnot, but often times I find myself eventually reusing the same code (and having to "function-ize" it after all).
Just a thought.
Other PHP Posts
Using PHP When Possible
In recent months, I've gotten in the habit of writing things in PHP arrays, using a function with a loop to actually generate HTML. This works great for anything where you have repeating elements (such as a table, lists,...
Processing Forms: Javascript or PHP?
I've dealt with a lot of online forms. Most, on submit, will refresh the page and process the data before the page loads. Then it will tell you of any errors you have. Sometimes, a page reload can take a while. If yo...
PHP Arrays
PHP hashmap-style arrays make a great solution to wanting to pass multiple variables but not wanting to specify them all in the arguments to a function. As far as object-oriented stuff goes, you can specify an array ...