我应该使用框架还是编写自己的MVC?

时间:2022-01-15 11:09:34

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

我有一个项目,目前到处都是,我正在考虑将其作为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.

问题是系统当前正在使用,我无法更改界面(它在框架中:s)还有一些我需要自己处理的事情,如密码生成,登录和用户级别。

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?

我已经有了MVC的模型方面,所以我想知道是否值得使用像Zend Framework或CakePHP这样的框架,或者仅仅编写我自己的View和Controllers来解决这个问题?

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.

我将不得不慢慢地工作,如果我使用其中一个现成的框架,我不确定我是否能够这样做。

8 个解决方案

#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:

通常情况下,我会惊恐地退缩并建议不要再将另一个网络MVC框架带入世界,但值得注意的是,我们的主持人Joel和Jeff对此事有另一种看法:

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.

我为Coldfusion编写了自己的MVC框架,因为当前的“当月风味”Mach-II非常缓慢。切换后我的页面生成时间从2-5秒下降到9毫秒。

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..)

在过去的3年里,我已经将这个框架开发成了我所使用的任何商业或开源框架(我已经使用了很多)的竞争对手,通过在函数库和组件中构建一系列常见任务( CMS,CC处理,图像处理等。)

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.

我说去吧,生活在边缘一点点。也许在5年后你会发布下一个“Mach-II”或者其他什么,我们都可以讨厌它。

#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.

你会发现CakePHP特别具有“侵入性”。恕我直言,你应该使用轻量级框架或编写自己的框架。我通常不会建议你自己写这类东西但是当你处理软件时你不能改变它有时候是最好的解决方案。此外,PHP中的控制器并不难写,因此如果您使用的预制解决方案太重或者不适合您当前的约束,您有时会不必要地过度复杂化解决方案。

For lightweight MVC frameworks I highly recommend CodeIgniter.

对于轻量级MVC框架,我强烈推荐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.

车轮改造很糟糕。使用像Zend Framework这样经过测试的框架,除非你有一个非常非常特殊的理由不这样做。

#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.

这取决于你的任务。一些琐碎的任务已经有了很好的解决方案,但有时候修复bug或者为你的需求提供解决方案比编写自己的需求更难。

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.

问题是系统当前正在使用,我无法更改界面(它在框架中:s)还有一些我需要自己处理的事情,如密码生成,登录和用户级别。

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.

不知道你的情况的细节,我会说系统当前正在运行的事实将使通用MVC框架难以集成。

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.

话虽如此,许多MVC框架由可用作独立实体的模块化组件组成。您可以在项目中使用这些框架的某些功能。

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.

问题是陈旧的,但仍然有效。就个人而言,我是一个“从头开始”的人。我喜欢节省时间,但不是全部费用。所以我可以互换使用框架。这意味着我在任何框架之外的TDD流程中创建我的所有业务类/规则,然后将它们集成到一个框架中,该框架允许将我的工作与标准服务和库。但我的工作并没有与他们联系在一起。它们分离且快速。

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 :)

为了更直接地回答这个问题。我创建了自己的CMS。而且我可以告诉你,如果你想了解某些事情,就要创造属于自己的东西。即使你永远不会分享它。您最终会更好地了解其他系统,这将使您更容易选择一个。然后你可能再也不想使用另一个了。但这通常发生在几次修改后:)

So yes create your own, but study others.

所以,是创建自己的,但研究其他人。

#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:

通常情况下,我会惊恐地退缩并建议不要再将另一个网络MVC框架带入世界,但值得注意的是,我们的主持人Joel和Jeff对此事有另一种看法:

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.

我为Coldfusion编写了自己的MVC框架,因为当前的“当月风味”Mach-II非常缓慢。切换后我的页面生成时间从2-5秒下降到9毫秒。

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..)

在过去的3年里,我已经将这个框架开发成了我所使用的任何商业或开源框架(我已经使用了很多)的竞争对手,通过在函数库和组件中构建一系列常见任务( CMS,CC处理,图像处理等。)

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.

我说去吧,生活在边缘一点点。也许在5年后你会发布下一个“Mach-II”或者其他什么,我们都可以讨厌它。

#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.

你会发现CakePHP特别具有“侵入性”。恕我直言,你应该使用轻量级框架或编写自己的框架。我通常不会建议你自己写这类东西但是当你处理软件时你不能改变它有时候是最好的解决方案。此外,PHP中的控制器并不难写,因此如果您使用的预制解决方案太重或者不适合您当前的约束,您有时会不必要地过度复杂化解决方案。

For lightweight MVC frameworks I highly recommend CodeIgniter.

对于轻量级MVC框架,我强烈推荐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.

车轮改造很糟糕。使用像Zend Framework这样经过测试的框架,除非你有一个非常非常特殊的理由不这样做。

#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.

这取决于你的任务。一些琐碎的任务已经有了很好的解决方案,但有时候修复bug或者为你的需求提供解决方案比编写自己的需求更难。

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.

问题是系统当前正在使用,我无法更改界面(它在框架中:s)还有一些我需要自己处理的事情,如密码生成,登录和用户级别。

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.

不知道你的情况的细节,我会说系统当前正在运行的事实将使通用MVC框架难以集成。

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.

话虽如此,许多MVC框架由可用作独立实体的模块化组件组成。您可以在项目中使用这些框架的某些功能。

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.

问题是陈旧的,但仍然有效。就个人而言,我是一个“从头开始”的人。我喜欢节省时间,但不是全部费用。所以我可以互换使用框架。这意味着我在任何框架之外的TDD流程中创建我的所有业务类/规则,然后将它们集成到一个框架中,该框架允许将我的工作与标准服务和库。但我的工作并没有与他们联系在一起。它们分离且快速。

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 :)

为了更直接地回答这个问题。我创建了自己的CMS。而且我可以告诉你,如果你想了解某些事情,就要创造属于自己的东西。即使你永远不会分享它。您最终会更好地了解其他系统,这将使您更容易选择一个。然后你可能再也不想使用另一个了。但这通常发生在几次修改后:)

So yes create your own, but study others.

所以,是创建自己的,但研究其他人。