Should I use a framework or write my own MVC?

2020-02-10 07:28发布

问题:

I have a project that is currently all over the place and i'm thinking of making it MVC.

The problem is that the system is currently being used and I can not change the interface (It's in frames :s) Also there are certain things that I will need to handle myself such as password generation, login and user levels.

I already have the model side down of the MVC so I am wondering is it worth using a framework like Zend Framework or CakePHP or just to code my own View and Controllers to work around this problem?

I am going to have to work this in slowly and I'm not sure if i will be able to do that if I use one of the ready made frameworks.

回答1:

Normally I would recoil in horror and advise against bringing yet another web MVC framework into the world, but it's fair to note that our hosts Joel and Jeff have another opinion on the matter:

From Joel: In Defense of Reinventing the Wheel From Jeff: Don't Reinvent the Wheel

One last thought: If it's a one-person project, then you only affect yourself with this choice. My resistance would spike up if a team developing a long-lived product was involved. You may do a disservice to the team and the customer if you roll your own.



回答2:

I wrote my own MVC framework for Coldfusion because the current "flavour of the month" Mach-II was horrendously slow. After switching my page generation time dropped from 2-5 seconds down to 9 milliseconds.

Over the last 3 years I've developed this framework into a rival for any commercial or open-source framework I've used (and I've used quite a few) by building in function libraries and components for a range of common tasks (CMS, CC processing, Image manipulation, etc..)

Although there was no doubt some "re-inventing the wheel" the wheel I ended up with was exactly what I need to do my job. I understand how it works with an intimacy that no documentation could ever provide.

Of course, one day some future programmer may be cursing over my code wishing a pox on me for not using their favorite library - but frankly - I just couldn't care less. I wrote it for ME, it does what I need and it does it well. I also learned a lot in the process.

Having said that you are NOT automatically doing your customers/co-workers a disservice by writing your own framework. Public frameworks tend to have no real direction so they tend to bloat massively trying to keep everyone happy. This bloat means more to learn, more that can go wrong. Your framework will be meeting a much smaller set of requirements and with good documentation could be a lot easier to understand and setup than a more established public one.

I say go for it, live on the edge a little. Maybe in 5 years you'll release the next "Mach-II" or whatever and we can all bitch about it.



回答3:

You will find CakePHP in particular to be quite "invasive". IMHO for this you should use a lightweight framework or write your own. I don't normally advise writing your own for this kind of thing but when you're dealing with software you can't change it can sometimes be the best solution. Also, a controller in PHP is not a hard thing to write so you can sometimes end up unnecessarily overcomplicating the solution if you use a prefab solution that's either too heavyweight or just not a good fit for your current constraints.

For lightweight MVC frameworks I highly recommend CodeIgniter.



回答4:

Wheel reinvention is bad. Use a tried and tested framework like Zend Framework unless you have a really, really special reason not to.



回答5:

It depends on your task. Some trivial tasks already have exellent solutions, but sometimes it's harder to fix bugs or to fit a solution for your needs than to write the own one.

Anyway when you start using a framework - you have to spend some time to learn it. And sometimes writing is faster than learning.

Just google about solutions you need, find some mature, look at their functionality, read open bugs and decide if you want to use it. That's all I can tell you without detailted task.



回答6:

The problem is that the system is currently being used and I can not change the interface (It's in frames :s) Also there are certain things that I will need to handle myself such as password generation, login and user levels.

I am going to have to work this in slowly and I'm not sure if i will be able to do that if I use one of the ready made frameworks.

Not knowing the details of your situation, I'd say that the fact that the system is currently running would make a general purpose MVC framework difficult to integrate.

Having said that, many MVC frameworks are composed of modular components that can be used as stand-alone entities. You may be able to pull off certain features of those frameworks for use in your project.

User authentication, session management, and password handling is one area in particular that should only be built from scratch if you have a great deal of experience in that area.



回答7:

Developing a framework is not an easy task, by the way, you should code, test, patch, more test and develop new features constantly. So if you aren't going to make it open source, which will we a good idea for having a huge community of testers-developers, you should not think about reinventing the wheel. It's round, it spins well, so choose the best one that fits your needs and take profit of some months of coding and testing of the community.

Best wishes



回答8:

The question is old, but is still valid. Personally I am a "from scratch" type of guy. I like saving time, but not to all cost. So I use frameworks interchangeably. Which means that I create all my business classes/rules in a TDD process outside of any framework, and then integrate them to a framework that allows to merge my work with standard services and librairies. But my work is not tied into them. They are decoupled and fast.

For a more direct answer to the question. I created my own CMS. And I can tell you that, if you want to learn about something, create your own. Even if you never share it. You end up with a much better understanding of others systems and it will make it much easier for you to choose one. Then again you might never want to use another one then yours. But that usually happens after a few revisions :)

So yes create your own, but study others.