benhowdle89
benhowdle89

Reputation: 37464

relationship between size of project and need to use PHP framework

What size of PHP project do people think "i really need a framework for this"...

Take this code:

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$dbname = 'test';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) 
        or die("Cannot connect to mysql server");
mysql_select_db($dbname) or die("Cannot select database");
$delete_item_id = mysql_real_escape_string($_POST['id']);
$result = mysql_query("delete from `timesheet` where id ='".$delete_item_id."'") 
          or die(mysql_error());
?>

This would take 5 minutes to write by hand in Notepad++, surely a framwork would be overkill for this script!

Or do people who use frameworks...always use frameworks?

Upvotes: 5

Views: 541

Answers (3)

mpdonadio
mpdonadio

Reputation: 2941

In addition to the responses here, I would add that frameworks often encourage programming practices that can lead to code reuse for future projects (especially MVC controllers). Well written code can often be adapted for use in another project, but I have had more success using modules as-is when then they are framework-based.

I will also say that as someone with 17 years of professional experience, that I write better code when I am working within the restrictions of a framework. I think this is because my code ends up being more consistent and the conventions of the framework prevent me from cutting corners / taking shortcuts.

Upvotes: 0

DampeS8N
DampeS8N

Reputation: 3621

I stand in a very different place than most people on this issue.

The size of the project is irrelevant. The size of the team and all future teams is what is important.

A framework, regardless of what you've been told, will slow down development if you are a quality programmer. What you gain from a framework are way more important than that. Firstly, you'll create more maintainable code. Secondly, you'll create more standardized code. Lastly, you'll create more segregated code.

All of these things only matter, with the possible exception of the first one, to teams.

If you are a solo dev, and you know what you are doing, you can spring up the core bits of frameworky doodads you need very quickly. You can maintain a personal library of classes and functions that you come back to all the time, and you can decide what you need for each project as you need it.

You are right, something small that only needs to take 5 min to make, should just take that 5 min to make. Take my silly little Genetic Algo Funny Image Generator at http://www.twitterandom.info/GAFunny/ which is little more than a couple database tables, some directories, and one page. But with a bunch of really hardcore classes to do all the GA work.

How would a framework have made that project easier or better? It wouldn't have. Yet it IS a reasonably complex project.

Turn the table. What if I were building that with a team and we needed to all work on it at the same time? What if the plan was for me to stop working on it a year from now and 10 other people would need to pick up where I left off?

Then a formal framework becomes vital. That is where using something standard, in this case something like smarty or symphony, would really make finding new programmers to work on it easier.

That is where a framework becomes a requirement. With a team. And the larger the team, and more often it turns over, the more important it becomes.

Upvotes: 8

user253984
user253984

Reputation:

You need a framework (no matter if existing or self-made) as soon as either of those is true:

  1. you want multiple programmers to work on one project
  2. you want to be easily able to modify/replace parts of your project later
  3. you want your project to be easily extendable
  4. you want new programmers to get into the code quickly
  5. you want to seperate logic, presentation and data from each other

Yes, short one-shot scripts don't need a framework, but as soon as it gets more complex you need one, even if you write one yourself (i recommend to use any existing framework though, as you can then hire people who already know it which reduces the effort to train them on your code)

Upvotes: 3

Related Questions