Page 1 of 2

Skeleton Framework

Posted: Mon Mar 23, 2009 1:10 pm
by VirtuosiMedia
I know that a few of you are working on Skeleton and I'm curious about your design process. I browse the code now and then and I'm always interested in why and how decisions are made in framework development. What has been the driving design philosophy? What have been some of the hardest classes or features to implement? Is there anything that you wish you had done differently? What lessons have you learned from it? What have you built with it?

Just in general, I'm looking for any insight or advice you might have about the process and design or even the technical aspects of implementation. I've been building my own framework for a while now, but I've been building it by myself up to this point, so I haven't really benefited from group discussion or planning. It does a lot, but not quite everything I want it to yet. I plan to release it once it's a little more complete and polished. For me, I think my driving design philosophy has been easy and consistent API.

Re: Skeleton Framework

Posted: Mon Mar 23, 2009 1:57 pm
by Christopher
First to be clear, the Skeleton Framework is not a formally released project. It is an on-again-off-again experiment -- sometimes fun, sometimes frustrating. It is not hyped as useful, though it gets occasional mention around here because certain modules are good examples of specific solutions. The project has a very long To Do list ... ;)

I clarify that because many programmers, like yourself, have a framework and some have the brash idea if releasing it. I certainly don't want to discourage people from releasing code because it is that one on a thousand project that catches on. But realize that 999 other projects, most probably including yours and mine, are just simply not very good.

Doing a project solo is very fun and rewarding. But until you add a couple other good programmers to the team, the quality of the design and code will not be that good (whatever you might think). Adding a second or third designer is probably the most difficult thing in software. And project management and leadership are both difficult. I know my own failings in both of those areas only too well.

Finally, I think many programmers who release frameworks really don't understand the scope and complexity of the task. I know from experience on the Skeleton Framework that even a group of very good programmers have a difficult time finding elegant solutions to difficult problems and agreeing on design issues big and small. The reason that Skeleton is not released is that it is far from being complete enough or good enough.

I would recommend using a major framework like Zend -- it is really light years ahead of anything a single programmer might build.

Re: Skeleton Framework

Posted: Mon Mar 23, 2009 3:45 pm
by VirtuosiMedia
I'm not really under any illusions about the difficulty of releasing a popular framework, what I'm writing is first and foremost for my personal use because I wasn't completely satisfied with other frameworks, including Zend. Mine is probably overly-simplified in comparison, but that was actually something I wanted. If others like it or want to use it, that'll be entirely up to them, but it'll be there if they do, with a lot of documentation and examples because I actually don't mind writing.

You're right, though, the scope of the task is incredibly immense and I don't think I knew how big it was at the outset. However, now that I'm in the middle of it, I don't mind it so much. A lot of it could probably be better, but every once in a while I stumble across a decent solution. I'm using it to build a CMS for my site, so it's fairly fluid right now as I'm refactoring it as I go along, finding what works and what doesn't. I'm definitely learning a lot and I'd like to think that I'm gradually improving.

Really, I think I'm just looking to compare notes a little and I'm also interested in the process. I know that I still have a lot to learn, so if there any experiences in particular, good or bad, that you'd be willing to share that I could learn from, I'd love to hear them. What was your process when you added that second and third developer? How much of your style remains in the code? What problems are you still trying to overcome?

Re: Skeleton Framework

Posted: Mon Mar 23, 2009 4:07 pm
by Inkyskin
I wrote a small framework for my own use - and would definitely recommend doing so even if it's just to expand your knowledge. The amount I learned from doing this alone was crazy!

When designing, take a look at why you don't want to use any of the existing ones - are they too bulky, do they not do something the way you want? Those are the things you'll want to make sure you get right in your own (and probably the reason you want to make your own!).

Personally, I wanted a partial MVC system, I wanted the Views and Controllers, but didn't want a Modeling system. I wanted it to be lightweight as it would be mainly used on small sites and didn't need the multitude of extras found in typical frameworks.

Once you've decided what you do and don't want, start putting it all together in your head. Take a look at other frameworks, see how they are structured (It's a pretty well tried style these days that most seem to use).

The hardest part for me to get right was the bootstrapping system, and making it correctly control the views and controllers. The other stuff IMO is pretty straight forward.

I'd recommend using a version control system too - it can really help down the line when your trying lots of different ways for the same process!

Just remember, there is no real right or wrong way of setting up a framework - PHP was never meant to be used like that strictly (It's not RoR after all, no matter how much the modern frameworks imitate it), so use a method you feel works for you. So long as it does work, and it's quick enough, your laughing :)

Re: Skeleton Framework

Posted: Mon Mar 23, 2009 6:41 pm
by VirtuosiMedia
Thanks for the insight, Inkyskin. I started using source control a few months ago and I love it. I'm still on the basics, but it's definitely a better way to develop. I've been looking a lot at the way Zend, Cake, Symfony, and CI are designed as well. I read their code, but I don't always know why it's the way it is, hence the question. I haven't run into too many problems, but I probably spend more of my time trying to figure out the right way to do something than actually coding it. Did you release your framework and if so, how was it received?

Re: Skeleton Framework

Posted: Mon Mar 23, 2009 6:50 pm
by Inkyskin
I never released mine, I just use it for my own sites really. It's really to bespoke to be of any use to anyone else as I've tailored it to my own styles and way's of working. That to me is the great advantage of having your own.

Re: Skeleton Framework

Posted: Mon Mar 23, 2009 7:02 pm
by Christopher
Inkyskin wrote:I never released mine, I just use it for my own sites really. It's really to bespoke to be of any use to anyone else as I've tailored it to my own styles and way's of working. That to me is the great advantage of having your own.
Unless, of course, you are unwittingly employing bad practices ... but how would you know ...

Re: Skeleton Framework

Posted: Mon Mar 23, 2009 7:13 pm
by Inkyskin
That is very true - I know for a fact the current version of my framework isn't great, but it's being rebuilt slowly but surely :D .

There's a chance I'll be putting the new version up for people to download (for some reason, I get asked about it about once a week anyhow), so that might help my own debugging and general improvement.

The only thing is, I don't want to start being a support base for those who have trouble using it, and really don't want to sit and write documentation either - but at the same time I don't want to block genuine problems with the code from reaching me... Half the reason I never released it in it's current form.

Re: Skeleton Framework

Posted: Mon Mar 23, 2009 9:40 pm
by VirtuosiMedia
Here is a code sample from my framework for a simple Twitter-like page that just has a form to enter an updated status, filters it, validates it (and displays an error if it doesn't validate), enters it in the database, and then displays all of the statuses for that user. The bootstrap code is from my CMS and loads the autoloader and gets the database connection (PDO), but I might end up moving it to the framework. Other than that, everything is the framework.

Code: Select all

 
require_once('includes/Cielo/Bootstrap.php');
$system = new Cielo_Bootstrap();
$db1 = $system->getDbConnection(); 
 
$userId = 1; //In a real app, you would get this info in a different way
 
$form = new Vm_Form();
$form->textarea('status', array(
    'label'=>array(
        'innerHtml'=>'What are you doing?',
        'class'=>'label'
    ),
    'attributes'=>array('class'=>'textbox'),
    'validators'=>array(
        'maxlength'=>array('You cannot use more than 140 characters', 140), //Custom error message
        'required' //No custom error was entered here, so it just uses the default
    ),
    'filters'=>array(
        'striptags'=>array('a')
    )
));
$form->submit(array('class'=>'input', 'value'=>'update'));
echo $form->render();
 
$status = new Db_UserStatus($db1); //The name of this class depends on which DB table is being manipulated
 
if (($form->submitted()) && (!$form->errorsExist())){
    $status->where('userId', '=', $userId);
    $status->userStatus = $form->getValue('status'); //This is the filtered and validated value
    $status->insert();
    $status->clear();
}
 
$status->where('userId', '=', $userId);
$updates = $status->select('assoc');
 
$xml = new Vm_Xml(); //You could just as easily do without this and just go straight XHTML
 
foreach ($updates as $update){
    echo $xml->p($update['status'], array('class'=>'update'));
}
 
Would you guys be interested in posting similar code examples that do the same type of thing from your frameworks (or from Zend)?

Re: Skeleton Framework

Posted: Mon Mar 23, 2009 10:54 pm
by Christopher
Database abstraction are one of the subjects where there are simple solutions that instantly promote better practices. But then you get into the Models, Gateways and Mappers that sit on top of them, and SQL generation, and the design gets much more complex very quickly.

Forms are another area where a modest system can produce some real productivity gains, and promote better practices. But again, trying to produce a more powerful and generalized system is very difficult. The solution you show is pretty standard, and generally similar to the Skeleton one.

Both discussions often expand into configuration, DI, etc. when they are part of a framework.

So you have picks two challenges where it is pretty easy to produce a system that really benefits a solo programmer, but trying to get several programmers to agree on a design involves a pretty extensive design discussion. They certainly interesting discussions though! ;)

Re: Skeleton Framework

Posted: Mon Mar 23, 2009 10:59 pm
by Christopher
Inkyskin wrote:The only thing is, I don't want to start being a support base for those who have trouble using it, and really don't want to sit and write documentation either - but at the same time I don't want to block genuine problems with the code from reaching me... Half the reason I never released it in it's current form.
Conversely, one of the huge benefits of using a framework supported by a group is that you get that support and documentation done to support your own work -- plus enhancements that you might not have thought of or had time to implement.

Re: Skeleton Framework

Posted: Tue Mar 24, 2009 4:48 pm
by VirtuosiMedia
What would say is the best way for planning and creating a class based on your experiences? After reading through some of your conversations, it seemed like the general method was define terms, define needs, discuss implementation, discuss naming conventions, and then code. Does that sound right?

I found the forms conversation particularly interesting. Our methods are similar, but it seems as if your forms are spread out over several more classes than mine. That's probably a good thing, but I wasn't sure how to break down my form class any further. My setup is basically the following:

Validator - A generic base class extended by specific validation rule classes, like email, url, minlength, etc
Validate - Creates and processes passed in validators, keeping track of all the errors
Filter - A generic base class extended by specific filter rule classes like striptags, trim, etc.
Xml - Generates XML elements based on a tag, content, and attributes; but is not extended by specific classes for each element
Form - Extends Validate and assigns validators, filters, labels, and error messages to each field and uses the Xml class to generate them - also captures the filtered and validated values

Of the above classes, I feel like the one to target would be the Form class, but I just don't know what I would take out. You could easily validate and filter a form without my form class, it would just take a little more code. I know it can be refactored internally some, but since it basically just extends Validate by generating the XHTML for the form itself and adds filters, I don't know what I could justify removing that would make sense to have in a separate class all by itself. It comes in around 600 LOC commented, with just over 20 public methods, most of which are for the different form elements (which I noticed that you actually have separated into individual classes rather than methods, something that I was curious about). The other major piece of code is for checking and processing the array logic that is used to build each field. Any suggestions?

Re: Skeleton Framework

Posted: Tue Mar 24, 2009 7:53 pm
by Christopher
VirtuosiMedia wrote:Any suggestions?
Probably what's in those threads would cover suggestions. There are just too many specifics to give any comments unless you have some specific code.

With Skeleton there are some high level goals that makes it tend toward lots of small classes, and often layers of classes of increasing complexity. The Skeleton Forms code takes that approach so it reuses standard Filters and Rules that are used elsewhere and it reuses HTML rendering classes used as View Helpers. Further we have moved in the direction of having the Form class to extend the base Model class so a Form is a temporary Model. This also allows it to use Filters and Rules provided by a Model class or the Form itself be a Rule for a Model. Generally this design, with it atomic Filter/Rule classes, makes simple Forms harder, but complex forms are not increasingly complex to implement. Since nothing is built-in, adding custom Rules/Filters/Renderers is no different than using the pre-written ones. The Model idea is new and still evolving.

Re: Skeleton Framework

Posted: Thu Mar 26, 2009 9:53 pm
by thinsoldier
I was hoping that the name "skeleton" automatically meant the framework would be "sensibly simplified". Unfortunately by my noob standards at first glance it seems every bit as complicated as something like Zend. So, I'd really like to see what people have built with it in the real world. (the examples in the repository are of no use)

I have a handful of simple sites for friends and family I'd like to use for experimenting with a framework but I can't get anywhere with zend (my server's too old) and I keep running into roadblocks to understand skeleton (code needs more comments and varying degrees of complexity showcased in working examples).



slightly off topic but
am I the only one who get's annoyed/confused by how some frameworks name the model, view, and controller files the same name. Sure they're all in separate appropriately named folders, but when I want to work on the "users" section of a site, it's confusing to have 3 files named "users.php" open.
I can see myself repeatedly uploading the wrong file to the wrong folder (I tend to drag-drop from my editor sidebar to my ftp window).


@VirtuosiMedia
I'd really like to see the source of your form class and database class. How do you customize the html surrounding your classes (tables/divs/fieldsets etc)?

Re: Skeleton Framework

Posted: Thu Mar 26, 2009 11:40 pm
by Christopher
thinsoldier wrote:I was hoping that the name "skeleton" automatically meant the framework would be "sensibly simplified". Unfortunately by my noob standards at first glance it seems every bit as complicated as something like Zend. So, I'd really like to see what people have built with it in the real world. (the examples in the repository are of no use)
I think Skeleton certainly can be implemented every bit as complicated as any other framework. That is more as result of there being a standard, and fairly large, set of practices that non-small applications need. Once you start in the framework style then things start to build up quickly.

Skeleton can be run in a more minimal implementation than many of the major frameworks. That's because things like using a router or inheriting a base Action Controller are optional with Skeleton. It is also generally lighter weight, lazier and less integrated as well. I have certainly built "enterprise" applications with Skeleton, but have also done so with Zend, CodeIgniter and Symfony. I am just finishing a site for Isuzu that uses Skeleton and SwiftMailer, so I know it can do the job.
thinsoldier wrote:I have a handful of simple sites for friends and family I'd like to use for experimenting with a framework but I can't get anywhere with zend (my server's too old) and I keep running into roadblocks to understand skeleton (code needs more comments and varying degrees of complexity showcased in working examples).
Skeleton, as you noted and as I said above, is not a released framework. I certainly encourage anyone interested in contributing to volunteer. If you want to walk through developing an application with Skeleton I would be glad to walk through building it with you. (are you using PHP4?)
thinsoldier wrote:slightly off topic but
am I the only one who get's annoyed/confused by how some frameworks name the model, view, and controller files the same name. Sure they're all in separate appropriately named folders, but when I want to work on the "users" section of a site, it's confusing to have 3 files named "users.php" open.
I can see myself repeatedly uploading the wrong file to the wrong folder (I tend to drag-drop from my editor sidebar to my ftp window).
You can name them usersController, usersModel and usersView if you want. I think most frameworks, including Skeleton, support that.