5

Ok so I've been programming in PHP for several years now. I always enjoyed building content systems from the ground-up for practice (forums, blogs, comics, general CMSs etc), however in the past few months I have come to the conclusion I am focusing too much time in doing redundant work like building the base content system every time - fetching information from databases, making the basic layout actually work before bringing any valuable content management to it, etc. Now, im aware of development frameworks such as Zend, CakePHP, etc; but I've always failed to work with them to my satisfaction, and seemed to give up on them rather quickly.

So my questions are:

  • How customizable are those frameworks? Can I really get full freedom with them once I learn to use them properly and get to work on actual features instead of wasting weeks on getting a simple base ground up and running?
  • How much can I write my own functions for doing stuff in the background?
  • Are the results usually fast? Or do the frameworks provide slow and heavy code?
  • How intuitive is it to really get them working in my favor and how easy is it to get past the basics nd working with what's really important?

I'd love any insights in this subject. Also I'd love to know if any of you have any preferred frameworks to work with. Thanks in advance!

casraf
  • 21,085
  • 9
  • 56
  • 91
  • Like you I build my code from the ground up and particularly enjoy building my own frameworks. I don't understand why you start from scratch everytime... I consistently re-use my frameworks (SQL access, Template management, Cacheing etc.) in new projects and re-write my access layer to suit the application/site. For me this is a very valid reason to use abstract classes for base code that never changes and then extending the abstract class with an access layer class. – David Barker Oct 25 '11 at 07:38
  • I always try to make a reusable framework, but I end up improving it while making a project, and never able to export it fully. There's always some project specific code that screws me and forces me to rewrite the whole pack. Guess I suck at writing frameworks :) – casraf Oct 25 '11 at 07:50
  • Good way to get around this is by abstracting methods that never change. i.e. how you access data in a SQL DB. This will give you a solid code base to work with that you can modify and change to your hearts content without modifying the base code. e.g. my data access abstraction layer has 7 methods to set, get and execute single or multiple queries. That code never changes. My extension class will always have a runQuery method that uses a 'try{ } catch(){ }' to manage exceptions generated by my base code. I then build all extra functionality into the extension class. – David Barker Oct 25 '11 at 07:55
  • I definitely do that for database handling, but it seems to stop at that. I have a class I built a while ago and I am constantly expanding it. – casraf Oct 25 '11 at 07:58
  • 1
    Apply the same rules to all your other code. It's a difficult rut to get out of, I still find myself re-inventing the wheel occasionally. It just takes a little bit of discipline to break old habits. :) – David Barker Oct 25 '11 at 08:03
  • *(related)* http://martinfowler.com/bliki/HarvestedFramework.html – Gordon Oct 25 '11 at 08:57

6 Answers6

4

How customizable are those frameworks? Can I really get full freedom with them once I learn to use them properly and get to work on actual features instead of wasting weeks on getting a simple base ground up and running?

It depends. If you get a framework that have everything included you'll spend time to find out the right way to use it. One approach I could recommend is to get a micro framework and to add everything you need by yourself. I. e. you get microframework like Slim or Glue, that provide routing, add you favourite ORM like propel, doctrine, red bean or Pear DB, add your favorite view engine like smarty, twig or anithing else, add Zend modules that you need in your application or Pear classes, add third party tools. This is a longer, but more flexible approach.

How much can I write my own functions for doing stuff in the background?

This method allows your to write everything that you cannot find ready for your work.

Are the results usually fast? Or do the frameworks provide slow and heavy code?

Thus performance completely depends on you. It does not much depend on the factors that you cannot control.

How intuitive is it to really get them working in my favor and how easy is it to get past the basics nd working with what's really important?

It depends on the complexity of your planned project. You can add parts as you need more functionality.

idm
  • 1,728
  • 2
  • 19
  • 26
4

A while ago I wrote an answer to similar question;

Firstly you have to ask yourself some questions;

  • Do you really need to use Framework? If you are working on a small project, working it with such frameworks will just make your web pages work slower than they normally would. They have too many features which you might not need and eventually those features which you don't even use will use resources.
  • Do you really want to go through all user guide? Don't forget even for the simple query you want to make, you have to read the user guide. Security measures, queries, URLs, forms, templates etc.. etc.. You might want to save yourself sometime but eventually you would have to spare some time first to learn how to use them.

If you want to use framework, use it for bigger projects. This might save you time (considering you don't have all the features they offer in your library). Make sure Framework you are going to use can do better than you can.

Generally their requirements will match many hosts. Asking for extra requirements to run, will decrease their popularity so you won't have problems with hosting.

I never used framework, instead I coded my own but I took a look at CodeIgniter. If you want to use framework, I wouldn't suggest to use CakePHP. I heard it is using too much memory. I believe CodeIgniter is rising star.

To answer your question shortly; They are easy to install. You can learn quickly in time. CodeIgniter has very well documentation. If you want to use it on small projects, they will just make the page heavier than it normally would be. Coding your own small framework for such projects is the best way to approach it. No need to discover a land twice. If they offer and their code is better than yours (generally speaking) then why not to use it? If you have time and knowledge, I would recommend you to starting building your own.

Revenant
  • 2,942
  • 7
  • 30
  • 52
2

There are lots of frameworks available and tons of sites on google and here on stackoverflow that discuss the in's and out's of each framework.

Myself personally, I prefer a barebones type framework like kohana or codeignitor, they do the basics for you and are fairly lite weight. So you end up with some help doing the basics, but largely you are left to your own devices to create a website.

bumperbox
  • 10,166
  • 6
  • 43
  • 66
2

How customizable are those frameworks?

How customizable is a toolbox?
Do not confuse framework with CMS. Framework is a merely a toolbox. And some sort of application carcass too.

Can I really get full freedom.

Definitely NO.
Framework is mostly an ideology. You will have to be baptized into particular framework's religion and do things the way it propose.

How much can I write my own functions for doing stuff in the background?

I can't get the question.

Are the results usually fast? Or do the frameworks provide slow and heavy code?

frameworks usually provide slow and heavy code.
but the code itself is very seldom being a bottleneck.

From the way the question asked, I'd suggest to learn some framework and then proceed to create your own one.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
1

I always think of people who use matured PHP frameworks as lazy people (or in a major hurry). In the long run, using frameworks will not increase your knowledge base anymore and therefore it's good for your time, but not good for you. I have to agree with David Parker, use something you've built from ground-up so you wouldn't have to anymore and whatever you do, do not stop learning because a developer who doesn't develop himself is no developer, right?

askome
  • 83
  • 1
  • 1
  • 6
  • True. But I was thinking I spend too much time rewriting things completely because I suck at writing frameworks. I always end up using a different approach and methods on each project, and as my experience grows I am left with no choice but to rewrite everything from scratch. I was wondering how a framework would aid me at that... I never thought of it as something that would slow down my learning. This is an interesting point to think about. – casraf Oct 25 '11 at 07:56
  • 1
    This is nuts. Are people who use jQuery lazy? Frameworks take time to understand, and (hopefully) are built with great principles and strict adherence to standards. I would never accuse a framework-user of being lazy... maybe biased if they never wanted to try any other frameworks, but *never* lazy. And besides, laziness is one of the vaunted characteristics of good programmers... – Drew Oct 25 '11 at 08:03
  • How about for starters create a framework that can handle simple routing? Then, if you feel the need, add query management. Just keep the framework and the application as far part as possible, that will make it easier for you to update your framework and application separately. – askome Oct 25 '11 at 08:05
  • Andrew, I've worked at quite many companies that hire some college-kid-turned-programmer people who are with very primitive mindset due to the fact that they've worked all they're lives with frameworks and haven't really built anything big-scale from ground-up, so if you hand them a big assignment and don't allow frameworks, they can't think beyond the framework. By no means meant I lazy as a bad thing, but lazy usually don't develop people. This market grows rapidly and we need to grow even faster. – askome Oct 25 '11 at 08:08
  • @askome I'd like you to elaborate if possible, a) about what you meant by 'routing', and b) what would you consider good practice? As in methods, not ways of training. I know the basics of the term 'MVC', and logic always allowed me to code along the basics of it, but always a bit vaguely and not always to the full extent. I'd love to understand the principles better, I think it will help me in making my own, extensible and extendable framework which I would have an easier time working with at all times and improving slowly. – casraf Oct 25 '11 at 08:19
  • If usually you would use $_GET to view pages or sorts of stuff like that, then you could instead use RESTful approach like Laravel (http://laravel.com/, framework) does. In other words, if URI matches a class or a function then that class or a function will be initialized. Good practice, well... I've always learned most when I take something that already exists, break it apart and investigate - then try to build the same thing from scratch. – askome Oct 25 '11 at 08:22
  • You mean having data fetched by using textual response from another file? Basically like fetching data from Twitter, for example? – casraf Oct 25 '11 at 08:24
  • Uhm, I believe your talking about an API here? (not a native English speaker here). What I mean is that first create a simple system which allows you to create view files without the need to rewrite how-you-get-the-view-files, then create a database class which would simplify your code - database relationship and on top add just about whatever you want. Remember, a framework is supposed to help you so start by figuring out what are the things you most need in a framework, then do some research and build. – askome Oct 25 '11 at 08:33
  • Yeah, the word RESTful always reminds me of the Twitter API, cause that's the method they're using. So I thought you were talking about that :P – casraf Oct 25 '11 at 09:06
0

well you are complaining about php frameworks. but how about java and .net?

do you think people know everything about them or even how it works. not really!

Point is that, most of the time people are trying to get their job done.

IMO, zend is great framework to work with php especially when you integrate it with smarty. and yes you can extend it.

DarthVader
  • 52,984
  • 76
  • 209
  • 300
  • I'm not particularly addressing PHP, but in this case yes, I do use PHP. So I was asking specifically about it. I'm not very fond of. Net or Java, but I think it fails to make a point in this discussion. – casraf Oct 25 '11 at 08:21