So I just wrote about 2012 and I mentioned a thing about programming. I have a programming task that I find interesting and would like to share it. But I have to take a shower and go to bed so I will be quick. I have been tasked to make an e-store. I am going to go opencart. The challenge here is that the supplier up the chain doesn't really know what he is doing. He has ordered his store from a contractor and now he has to pay an arm and a leg for the extension needed to export what I need. So I'm not going to get what I need. What I need is an XML or CSV or access to an SQL, something that has the product's name, description, picture and price. Everything you need to sell something. Then I need a way to automatically import the data into the store.
When I started learning PHP there wasn't much of object oriented programming philosophy in it. And there is a simple qbasic feeling to a project that has 4 files that go 1 2 3 4. I really though that this task is small enough for simple linear procedural programming. There was an argument about simple programs not needing objects, and not using objects being for lesser programmers. I decided I would be a great programmer and have been making objects left and right. For some reason not this time. So I hit the wall when I needed a procedure to turn on into itself and call itself from itself. You may think why object why not function. But there is a scope and loop issue here. And then when you resolve it you have a simple aesthetics issue here. Modular programming allows you to make self contained logic blocks that have a few simple lines of code packaged and put away. This allows you to hide things you don't need, makes the code easier to work with and manageable. I now have 4 files, two of them are about a hundred lines long each, and when the script hits an error I wish I would just die. This has made me realize that no task is small enough for you to simplify it. Take all the tricks from the book and just throw them at the task. Instead of assuming that it will be simple you should just diligently build your script from the ground up by the best practices you know. Maybe you will waste some time on some small things but when you get surprised by a task you will be ready for it. A class I always use is my sql class, it extends the PDO build in class and has the routines for writing and reading. I wrote a class that makes curl into a browser for use in a different script. I could have used it for this task since it has methods to get pages and to download files. Instead I made this blob monster of code that can only step through pages, and another one for the images. In retrospect it turns out that I rewrote code I had and it was not as good as the first time I wrote it. I hope my suffering the past 3 weeks is helpful to somebody. You know how to code, don't skip corners.