Mar 03, 2013; 21:54
Jussi Hirvi
Cleaning up
I have been refactoring my own framework now for a couple of weeks. It
takes huge amounts of time and does not add a single new feature, but
it's kind of addictive. I want to share a little of what I have learnt.
For newcomers I would heartily recommend using some established
framework like maybe Knop or Pageblocks (I am going to try Knop myself
soon). It takes some time to learn them, but at the end it will save
very much time. I have seen that maintaining code over the years takes
many times more time than first writing it. Writing bad code is a good
way to learn things but you have to be prepared to babysit it for a long
time until it grows up.
Years ago I started with procedural code and loads of loose page
variables going here and there. Not to mention colon syntax. Now I clean
things up along these guidelines:
* I move codeblocks from procedural pages to ctags and types. The ctags
should have clear-cut inputs and outputs. This makes code easier to
debug, and also easier to understand. It is a great tool to make the
code better. (My ctags still take some page options etc. on the side,
though i try to avoid it in principle.)
Using OOP in my mind is about adding hierarchical levels. Which always
happens in all kinds of evolution. So it's very natural and good.
* I group loose variables into maps, which represent functional groups
of options etc. I have site options, folder options (especially for
admin pages), page options, upload options, search data, editform data.
All of these are (going to be) maps. Using maps makes the code a little
longer - I now have $uplopts->find(-path) instead of $upload_path. But
the map name is useful, it tells me where the variable comes from. Also
it's easier to pass a map to a ctag than pass a diverse amount of
variables.
* I used to have a giant file called monster.inc which did everything -
it took input from searchform, editform, uploadform, displayed a search
form, edit form and upload form, managed CRUD and uploads. Now I am
gradually making monster.inc slimmer until it's just a short scheme -
orchestrator. If I sometimes want to orchestrate my page a little
differently, for example display the elements in different order, it
will be easily manageable - until now it has been nearly impossible
without writing everything anew.
I am still not sure if I will carry on with my own framework of start
using something else. Anyway my own code starts to be almost
presentable. It is a relief to know that when problems arise, debugging
will not be a nightmare.
- Jussi
#############################################################
This message is sent to you because you are subscribed to
the mailing list Lasso
Lasso@lists.lassosoft.com
To unsubscribe, E-mail to: <Lasso-unsubscribe@lists.lassosoft.com>
Send administrative queries to <Lasso-request@lists.lassosoft.com>