creating your own framework

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 18392 Views - Last Post: 05 June 2012 - 06:36 PM

#1 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 926
  • View blog
  • Posts: 3,204
  • Joined: 19-January 10

creating your own framework

Posted 10 July 2011 - 05:03 PM

*
POPULAR

Well, I've been working on some scripts recently for a few clients and one thing I notice is I really rewrite code over and over. No I'm not talking about 40 unlinks copied over and over. I'm talking about stuff like functions, member systems, all that stuff. I've been thinking about writing my own framework in order to create stuff faster. I remember a thread awhile ago about some guy who thought that programming should be like making spaghetti, and all you have to do is pick the ingredients and put it together in a special fashion. Someone replied that instead of getting the ingredients, it's more like creating the ingredients by hand.

Well I think a framework is like that. The actual framework are ingredients. Every class is an ingredient like a tomato or noodles, and every function is stuff that makes that ingredient what it is. This will make every future meal (script) easy, because I have already built my ingredients (classes, functions). Then all I will have to do is put it together.



tl;dr: creating your own framework to make scripts for clients easier/faster to create. Good or bad?

Is This A Good Question/Topic? 5
  • +

Replies To: creating your own framework

#2 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 452
  • View blog
  • Posts: 811
  • Joined: 17-June 08

Re: creating your own framework

Posted 10 July 2011 - 06:43 PM

That cooking metaphor made no sense to me, so I'll just reply to the short version. :)

View Postcreativecoding, on 10 July 2011 - 08:03 PM, said:

tl;dr: creating your own framework to make scripts for clients easier/faster to create. Good or bad?

Good or bad as opposed to what? Not using any framework at all and writing repetitive ad hoc scripts for everything? Do you even need to ask that?

Let me put it this way. There are two kinds of PHP developers: 1) those who use a framework in their applications (either a third-party one, one they develop from scratch, or a combination thereof) and 2) those who are incompetent. Seriously, it's not even a choice. For any non-trivial project, if you don't use somebody else's framework, then you will end up writing your own. It's the only sane way to work. Reinventing the wheel for every project just isn't a productive way to use your time.
Was This Post Helpful? 3
  • +
  • -

#3 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 926
  • View blog
  • Posts: 3,204
  • Joined: 19-January 10

Re: creating your own framework

Posted 10 July 2011 - 06:49 PM

View PostAdaHacker, on 10 July 2011 - 07:43 PM, said:

That cooking metaphor made no sense to me, so I'll just reply to the short version. :)

View Postcreativecoding, on 10 July 2011 - 08:03 PM, said:

tl;dr: creating your own framework to make scripts for clients easier/faster to create. Good or bad?

Good or bad as opposed to what? Not using any framework at all and writing repetitive ad hoc scripts for everything? Do you even need to ask that?

Let me put it this way. There are two kinds of PHP developers: 1) those who use a framework in their applications (either a third-party one, one they develop from scratch, or a combination thereof) and 2) those who are incompetent. Seriously, it's not even a choice. For any non-trivial project, if you don't use somebody else's framework, then you will end up writing your own. It's the only sane way to work. Reinventing the wheel for every project just isn't a productive way to use your time.


Ah good point. I am worried about legality. I know it really shouldn't be a problem but I am slightly worried that people will see my framework and say something like "Hey, I can sell this thing!". I'm not exactly the sharing type when it comes to code that brings me money.
Was This Post Helpful? 0
  • +
  • -

#4 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 789
  • View blog
  • Posts: 1,676
  • Joined: 30-January 09

Re: creating your own framework

Posted 10 July 2011 - 06:52 PM

Creating your own framework is one of the nice free perks of programming. Why write new code for each project you work on, when you can write a generic codebase that only requires the application of templates and some customised code? By all means, develop your own framework, it'll cut down your coding time from project to project, and your clients are also more likely to come back to you if they need any extensions on your work, as you're the expert in that framework.
Was This Post Helpful? 0
  • +
  • -

#5 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: creating your own framework

Posted 22 July 2011 - 07:05 AM

*
POPULAR

It really depends on what you define a framework to be, if you're going to build something as "full-featured" or "complex" as Zend Framework, for example I wouldn't bother.

However, to gather a lot of reusable code into your own little script/library over the years is only natural. Even with writing your own MVC "Framework" this is probably good practice, as most people don't require what the larger frameworks provide.

I know a lot of people who will use Zend Framework to simply acheive an MVC structure in their application, such as automatically routing a request to a specific Controller and Action. The whole Zend Framework project is located within the source of the application, yet only a few portions are used. This not only creates massive overhead for a single request by initialising all of Zend Framework's crap, but it's something that you could write yourself in around 15 minutes and have a much faster, automatic and reliable system on your hands.
Was This Post Helpful? 6
  • +
  • -

#6 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3712
  • View blog
  • Posts: 5,964
  • Joined: 08-June 10

Re: creating your own framework

Posted 23 July 2011 - 07:36 PM

*
POPULAR

View Postcreativecoding, on 11 July 2011 - 12:03 AM, said:

tl;dr: creating your own framework to make scripts for clients easier/faster to create. Good or bad?

Good. Definitely good.
... Unless you're getting payed payed by the hour, with a flexible deadline :)

Just make sure whatever contract you have with your client doesn't hand the ownership of your framework over to them. Make it so they are buying a modified copy of your work. As I understand this: as an "employee" your work actually belongs to your "employer"... unless you make sure it doesn't.

(Not that I'm exactly an expert on stuff like this. I steer clear of situations where things like this would be an issue :))

View PostRudiVisser, on 22 July 2011 - 02:05 PM, said:

I know a lot of people who will use Zend Framework to simply acheive an MVC structure in their application, such as automatically routing a request to a specific Controller and Action. The whole Zend Framework project is located within the source of the application, yet only a few portions are used. This not only creates massive overhead for a single request by initialising all of Zend Framework's crap, but it's something that you could write yourself in around 15 minutes and have a much faster, automatic and reliable system on your hands.

Agreed. In the time it took me to get vaguely familiar with the basics of Zend Framework I could have written my own framework to do exactly what I needed, and nothing else.

<rant>
tl;dr: Personally I think ZF, and other such frameworks, are bloated and not worth the effort. It's not hard to create simple frameworks that will work just as well, if not better, for your specific needs.

I mean, look at how Zend Framework handles database queries. I get wanting to abstract things like that, but it not only makes the "query" code less readable, but it has you learning a whole new, harder to use syntax.

How hard is it to write standard SQL code?
SELECT * FROM clients cl
JOIN client_roles cr
	ON cl.role_id = cr.id
JOIN countries co
	ON cl.country_id = co.id
WHERE cl.id = ?


But then ZF comes along with stuff like this:
$select = $tbl->select()->setIntegrityCheck(false);
$select->from('clients')
       ->join('client_roles',
              'clients.role_id = client_roles.id',
              array('role_name' => 'client_roles.name'))
       ->join('countries',
              'clients.country_id = countries.id',
              array('country_name' => 'countries.name'))
        ->where('clients.id = ?', $id, 'integer');


Who really needs that? Will you perhaps be regularly swapping out database systems?

If you're switching to a database system that is so alien that standard SQL queries can't be used with minimal changes, your probably not going to be able to use the old schema anyways, so this code will have to be changed in any case!


Also, the damn class names!
$inst = new Zend_Random_Feature_That_Is_Hardly_Ever_Useful_At_All(new Zend_Another_Random_Feature_That_The_Other_One_Uses_As_A_Parameter());


After having used namespaces in previous projects, those things were driving me mad.

</rant>
Was This Post Helpful? 5
  • +
  • -

#7 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: creating your own framework

Posted 24 July 2011 - 11:49 PM

I completely agree with everything you said in your rant about ZF.

Having to "bootstrap" a web application is just the stupidest thing I've ever heard of, not to mention the additional overhead of all of ZF's crap initializing every time :)
Was This Post Helpful? 0
  • +
  • -

#8 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 944
  • View blog
  • Posts: 2,353
  • Joined: 15-February 11

Re: creating your own framework

Posted 26 July 2011 - 09:53 AM

A framework's not a bad idea. Especially if you have to implement the same objects or process.. etc over and over. I recently tried CodeIgniter and I must say learning it takes longer than writing my own framework.
Was This Post Helpful? 0
  • +
  • -

#9 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,437
  • Joined: 23-August 08

Re: creating your own framework

Posted 26 July 2011 - 10:24 AM

Using CakePHP now after never having used a framework before, and it's a bit of a test. You don't want to do things the wrong way, and yet the docs aren't always quite clear on what exactly IS the right way to do something.

Or, I'm just not able to spend the time on it because of the impossible deadlines imposed fairly arbitrarily.

Now, if I can just stop my boss from continuing his bad habits...
Was This Post Helpful? 0
  • +
  • -

#10 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 944
  • View blog
  • Posts: 2,353
  • Joined: 15-February 11

Re: creating your own framework

Posted 26 July 2011 - 11:35 AM

Truly if I was an employer and I knew a certain employee is very much capable of handling his or herself then I definitely won't demand the use of any framework.
Was This Post Helpful? 0
  • +
  • -

#11 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10397
  • View blog
  • Posts: 38,475
  • Joined: 27-December 08

Re: creating your own framework

Posted 26 July 2011 - 11:48 AM

Coming from a Java background, I had a bit of a different perspective with PHP. I found that there was a function for most of the simple tasks, where a lot of that had to be manually written in Java, or at least there were more steps within the API to get to the same result. On the flipside, I feel like the various frameworks are more full and succinct in Java. In PHP, there are more third party APIs at the forefront than in Java it seems. With Java, practically everything you need comes with the JDK. So when learning the language, it is inevitable but to learn some of the frameworks. PHP doesn't enforce this as much, from my experiences. To be fair, I don't work with PHP everyday, nor am I an expert or well-versed in the language.

In general, my view with frameworks is that they should do the job delegated well and be succinct. Verbose frameworks tend to be cumbersome, and this means combining multiple jobs under one framework can be cumbersome to sift through. From what little I've looked at the PHP frameworks, this seems to be one of the problems.

So if you choose to create your own frameworks, make sure to:
-Identify the problem the framework will solve
-Provide the tools to fully solve the problem, and no more

Just my $0.02. :)
Was This Post Helpful? 0
  • +
  • -

#12 Denis1  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 32
  • View blog
  • Posts: 102
  • Joined: 29-July 09

Re: creating your own framework

Posted 01 August 2011 - 03:52 PM

View Postcodeprada, on 26 July 2011 - 05:53 PM, said:

A framework's not a bad idea. Especially if you have to implement the same objects or process.. etc over and over. I recently tried CodeIgniter and I must say learning it takes longer than writing my own framework.


I know what you mean. A few months back i began codeigniter, before that i was rewriting code over and over copying and pasting from old projects. but it took about a week to get used to codeigniter and that has increased my productive by 900%. Things are so much faster with forms, database, url, etc etc. You cant be creating php applications without using a framework.
Was This Post Helpful? 0
  • +
  • -

#13 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: creating your own framework

Posted 01 August 2011 - 03:58 PM

View PostDenis1, on 01 August 2011 - 11:52 PM, said:

You cant be creating php applications without using a framework.

Well that's just not true, frameworks such as CI and ZF for simple (or most) projects are simply an expensive overhead that is not required.

I haven't used any framework for any of my PHP developments, apart from when I was forced to use ZF for a commercial project.

What I have used, however, is a reusable library of code that I have written and understand. Call that a framework if you will.

This post has been edited by RudiVisser: 01 August 2011 - 03:58 PM

Was This Post Helpful? 0
  • +
  • -

#14 nightscream  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 237
  • Joined: 04-December 08

Re: creating your own framework

Posted 26 August 2011 - 04:59 PM

View PostRudiVisser, on 01 August 2011 - 04:58 PM, said:

View PostDenis1, on 01 August 2011 - 11:52 PM, said:

You cant be creating php applications without using a framework.

Well that's just not true, frameworks such as CI and ZF for simple (or most) projects are simply an expensive overhead that is not required.

I haven't used any framework for any of my PHP developments, apart from when I was forced to use ZF for a commercial project.

What I have used, however, is a reusable library of code that I have written and understand. Call that a framework if you will.

I have to agree, I never used any framework in my life but I wrote my own (if you can call it a framework). My framwork uses MVC and a routings file that routs my urls in the right direction. I have a lot of classes I reuse in every project.
Was This Post Helpful? 0
  • +
  • -

#15 Munawwar  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 162
  • View blog
  • Posts: 457
  • Joined: 20-January 10

Re: creating your own framework

Posted 24 September 2011 - 01:17 PM

So the question is how to increase productivity without using huge frameworks. Some questions in my mind: How do you guys normally organize your app? What libraries do you frequently use?

I have skimmed through many frameworks and in each framework there are stuffs I like and dislike. Most of the time, a few selected features is all that I need. I am trying to find libraries for those specific stuff.

Here are some of my findings:
  • Architecture/URL routing: TinyMVC.
  • Template System: phpti brings a concept of "template inheritance". Those who have used template engines like Smarty may have heard of it.
  • Database: idiorm. No models and stuff. jQuery like chaining for SQL building. For complex stuff, its possible to write SQL.
  • Form validation: Looking into Phorm. Still searching for a good one.
  • Permission system: Searching for a RBAC or ACL system. So far I liked the Yii RBAC/ACL system.

I'd stop here. But I think we could add more to the list (web service,I18N,caching,security...). Feel free to share your thoughts.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2