Performance

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Bruno De Barros
Forum Commoner
Posts: 82
Joined: Mon May 12, 2008 8:41 am
Location: Ireland

Performance

Post by Bruno De Barros »

What I hate the most about my way of coding is bothering with performance, and dependencies. And permissions. I'll explain.

I am currently rebuilding my whole PHP Framework. I wanted something lightweight, that I know top to bottom, has MVC, uses Unit Testing, is easily extensible, but is extremely powerful.

YAGNI tells me I shouldn't code more features than what I really need, and I am trying to do that. I only code the features when I need them. This ends up being a major pain in my rear end, because I have dozens different customers, dozens different websites, with the same framework, but all different features and everything. And when I try to reorganize my framework, I end up rebuilding it.

But my problem is I start concerning about dependencies. And I start worrying about what the pages (Models, Views and Controllers) can do. For example, I try to make the view as isolated as possible, the controller not able to access $_POST, $_GET or $_COOKIE without having validated the data firstly... And it's useless! I mean, I am the single user of this framework, and I don't plan on releasing it to public that soon because I want to make sure I have everything ready for that. Then I start thinking about performance issues, and about naming conventions.

All of these are things that I should indeed worry about, but it's driving me mad! And my framework goes nowhere, because I end up feeling hopeless about it.

Any of you got the same feeling?

P.S. I am also trying to get the perfect, more user-friendly interface for my code. I want easier, faster website development. And that involves a lot of thought. Basically, when I start a website, I want to have a set of already provided features, like the internationalization, different templates, session handling, database abstraction, etc., and that is what my framework is for. So that I don't have to reinvent the wheel all the time, and my code is better organized, and prepared from the beginning to deal with big features (for example, if my customer wants different templates or decides he wants to translate his website).
User avatar
allspiritseve
DevNet Resident
Posts: 1174
Joined: Thu Mar 06, 2008 8:23 am
Location: Ann Arbor, MI (USA)

Re: Performance

Post by allspiritseve »

Bruno De Barros wrote:Any of you got the same feeling?
Definitely. Almost exactly, actually. I think mine stems from being too much of a perfectionist. The way I've decided to deal with that is to code using TDD, and tackle one problem/client at a time. Don't worry about anything but the features that particular client needs, and code to that. Sure, it might turn out to be some horrible code. But that's ok. As soon as you start adding to it (additional requirements from client, or maybe trying to make it work for another client) you start to see where the friction points are, and where your code could work better. Tackle those problems one at a time, and if you don't know how, then isolate the problem and post it here. I know too well how easy it is to get stuck worrying about everything that could possibly go wrong in an app. In my opinion, until you see the actual effects of your design choices, it's hard to write code that accounts for those effects. Maybe some people can just sit down and write the perfect app in one go, but I can't. I have to work on it iteratively, and learn from my mistakes.

Hope that helps,

Cory
Bruno De Barros
Forum Commoner
Posts: 82
Joined: Mon May 12, 2008 8:41 am
Location: Ireland

Re: Performance

Post by Bruno De Barros »

Yep, unit testing is extremely helpful for that matter. For example, I don't use ORM, or anything, but instead, I do models manually to deal with each of the tables. Takes more time than ORM, I know, but it gives me more flexibility, because for the "users" table, for example, I can have login() and logout() methods, as well as the normal getting and setting of records on the database. I just make the methods as I need them.

With everything separated, I can make a test for example to register several different users, with different inputs, to see if their "input" is processed properly and all of that.

That's how it works, and it makes me feel happy about that, but when I look inside the framework is where I see the most possible situations for errors :P. That's why I am now working on a small project of my own, while using the framework, to identify possible errors with the framework, perfect it, and make it better, overall. And whenever I find errors, I make tests to avoid regressions.

Regarding TDD, I find writing the tests before the code much easier. When I write the tests AFTER coding, I find myself too lazy to write proper tests, because either I already tested the code on some situations (for example, when I am trying to make unit tests for existing applications), or I just know that if one situation works, all other will work (or so I think).
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Performance

Post by Christopher »

I hate to say it, but the framwwork is not the problem -- you are. ;) Your framework is just a symptom of the problem.

Frameworks are a great example of the law diminishing returns. When we first started programming, frameworks produce large productivity returns on the time invested. The projects and problems we worked on were simpler. The basic organization and patterns of frameworks produced big benefits. But we all eventually reach a point where the problems became more complex and more difficult. After that we started experiencing the feelings and difficulties your are having. It is worse for contractors because the time we spend struggling to make increasingly smaller improvements to our frameworks -- we are not making money.

The truth is that software design and development is very hard, and distilling it into a framework is even more difficult. We simply do not have the intelligence, wisdom and experience to produce a great framework on our own. Programmers starting out, or those with very high opinions of themselves, will argue with me, but everyone else who has programmed long enough will confirm this (though they may not admit their limited intelligence like I do ;)).

The solution is to start using a framework produced by a team. Groups of programmer can have sufficient intelligence, wisdom and experience to produce high quality designs and implementations. Pick one that suits you and start improving your profit margin. Or get involved in a project if you still need that experience.

This has certainly been my own experience. I use several popular frameworks to develop sites for clients -- Zend, CodeIgniter, and Cake. I am also involved with the Skeleton framework which started as a collection of cut-down, minimal versions of things common to many frameworks. It began way back from a discussion of some PEAR classes that I though were bloated. Out of that forum discussions we came up with some minimal implementations. Other simple version of basic classes, like filters and validators, were added along the way. Minimal controllers were then added and it grew from there. But even with 3-4 smart programmers, we are constantly challenged trying to improve the design. Especially now that we are attempting to maintain both the minimal layer and add more full featured layers on top. Look at the frameworks I listed above. I can identify many annoying design problems in them and they were built by better programmers than myself. It is a real challenge.

To make an analogy, it is difficult juggling to just keep all the balls in the air. But with framework design you are increasing the number of balls, their speed, height, accuracy beyond what a single juggler or even a small group of jugglers can really do.
(#10850)
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: Performance

Post by Ollie Saunders »

User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Performance

Post by Eran »

Great slides, thanks!
Bruno De Barros
Forum Commoner
Posts: 82
Joined: Mon May 12, 2008 8:41 am
Location: Ireland

Re: Performance

Post by Bruno De Barros »

@arborint, I hear you. And I am trying to use different frameworks made by other people. Just trying to find the right one for me :P. It's like what happened with SimpleTest. Just too darn afraid (read FRIGGIN' LAZY) to learn other people's code. It's awful, I know, but I truly hate it. Until I get to know the code, like I did with SimpleTest, and then I just love it xD, and can't stop it.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: Performance

Post by Ollie Saunders »

hehe of course there is the fact that SimpleTest is really well written. Most frameworks aren't and when I say most I really mean pretty much all.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Performance

Post by Christopher »

Ollie Saunders wrote:This seems highly relevant. http://olliesaunders.net/?id=apiDesignVideo
We should start a new thread to go through that talk and discuss it as it relates to PHP practice (although you are a RoR guy now ;))
(#10850)
Post Reply