I felt like I was going some where when I learned that I could put code into separate files and then have it referenced by another bit of code else where. I learned this many many years ago when I first learned about what PHP was. I geustimate this at about 2006 or 2007. I later learned that in Python, I can do the same thing, but the mechanism is different. I hadn’t really gotten far into the coding adventures, due mostly to my inability get a function to return more than one usable item. I had spent months trying to get one function to ‘return’ 2 variables, with out success.
A few months ago, it was suggested that I return an array, and build that array out of the variables I wanted to see in the first place. It was a life changer. After starting my KN-FSM project, I natively started breaking down certain parts of the html and codes into separate file, so that I could manage them a little more easily. Things like tables and menus could be referenced from the main index and still be easy to change that one line or item with out a lot of distraction. But today, I started to think to myself: “I have 3 charts that I made 3 files for. Then, I have 3 require entries for those charts. But should I be doing that or should I have my charts the result of a function?” This appears to afford me very little, but logically it may more sense.
I would now have 2 requires, instead of the several that I have now. You can see this at line 30 @ https://github.com/kami-nashi/kn-fsm/blob/master/index.php
I’m already thinking, the function doesn’t run unless called, but I would have a file of similar entries. Lets say, a file for functions.core.php for the core items that don’t output anything with formatting. Then another, functions.charts.php, that holds all functions for just building the html/java script for these charts. In my index, I would require both files, then call the functions that are needed. What I don’t know is if this increases the complexity of maintenance on the formatted output or not. I think in code that is so simple, I’d rather do it incorrectly and make it easy instead of over complicating it into a standard.