前端框架和库的区别_库和框架

前端框架和库的区别

前端框架和库的区别

A question I get asked often through emails and other discussions is how I feel about frameworks and libraries, both for scripting and for CSS. I’ve been meaning to share my thoughts on it for awhile, and now that I see NetTuts.com has posted an article about choosing a CSS framework, I figured now is as good a time as any.

通过电子邮件和其他讨论,我经常被问到的一个问题是,我对脚本和CSS的框架和库的感觉如何。 我一直有一段时间想分享我的想法,现在,我看到NetTuts.com发布了一篇有关选择CSS框架的文章,我认为现在是一个好时机。

Any of you who have been reading my site since the beginning might remember I wrote a post about the importance of forcing yourself to reinvent the wheel. I still stand by that, but that doesn’t mean I am entirely against all frameworks. In fact, in the case of scripting libraries, I can definitely see the value in using them. The key point is to be able to tell when to use a library and when not to.

从一开始就一直在阅读我的网站的任何人都可能记得我写过一篇文章,讲述了强迫自己重新发明轮子的重要性。 我仍然坚持这一观点,但这并不意味着我完全反对所有框架。 实际上,对于脚本库,我绝对可以看到使用它们的价值。 关键是要知道何时使用库,何时不使用库。

你为什么要? (Why Should You?)

One nod for using libraries and frameworks is that reusable code is a good thing. It saves you time and money, and I think most developers have at least some amount of code that they reuse on various projects. I am all for that. We programmers are lazy…errr…efficient. If we can create a solution that is flexible and reusable…then more power to us.

使用库和框架的一个观点是,可重用的代码是一件好事。 它可以节省您的时间和金钱,而且我认为大多数开发人员至少可以在各种项目上重复使用一定数量的代码。 我全力以赴。 我们程序员是懒惰的……错误的……高效的。 如果我们能够创建一个灵活且可重复使用的解决方案……那么我们将拥有更多的力量。

Libraries are also quite handy in large teams. They provide a common base for everyone on the team to start from, and if you stick to a certain naming or formatting convention, in combination with a library of some sort (either in-house developed or not), you can make communication very easy and eliminate a lot of the questions that can arise when passing code from developer to developer.

在大型团队中,图书馆也很方便。 它们为团队中的每个人提供了一个通用的基础,如果您遵循某种命名或格式约定,并且与某种类型的库(内部开发的或非内部开发的)结合使用,则可以使沟通非常容易并消除了在开发人员之间传递代码时可能出现的许多问题。

Large applications also provide us a good reason to use a library. In Javascript, for example, there are a fair amount of browser incompatibilities. These incompatibilities are taken care of by most Javascript libraries, allowing a developer to focus on developing the actual logic for the application not the browser differences that arise.

大型应用程序也为我们提供了使用库的充分理由。 例如,在Javascript中,存在很多浏览器不兼容性。 大多数Javascript库都解决了这些不兼容问题,使开发人员可以专注于为应用程序开发实际的逻辑,而不是浏览器出现的差异。

另一方面… (On the Other Hand…)

There are many issues though that can arise from consistent use of libraries and frameworks. If you use a library exclusively, you can become quite dependant on it. It’s important to understand the underlying code that the library is using. If you continue to depend entirely on a library to cover all browser bugs for you, there will come a time when there will be a bug it doesn’t cover, and you aren’t going to know where to turn to troubleshoot it.

但是,由于一致地使用库和框架可能会产生许多问题。 如果您仅使用库,则可能会完全依赖它。 重要的是要了解库正在使用的基础代码。 如果您继续完全依赖于库来为您覆盖所有浏览器错误,那么有时会出现一个无法覆盖的错误,并且您将不知道要去哪里进行故障排除。

Also, and this is particularly true in CSS frameworks, you can become too attached to what the framework provides and start conforming your code to fit in with the framework or library you are using. There is a saying that goes “When the only tool you have is a hammer, everything looks like a nail.” If you are using a CSS framework to create your layout and there is a particular visual style that the framework doesn’t quite get right, the most common approach, unfortunately, is to conform to the framework. You start to look for ways to make the layout fit within the frameworks provided structure.

另外,在CSS框架中尤其如此,您可能会过于依赖该框架提供的内容,并开始使您的代码与所使用的框架或库相适应。 俗话说:“当您仅有的工具是锤子时,一切看起来就像钉子。” 如果您使用CSS框架来创建布局,并且有一种视觉风格使该框架不太正确,那么不幸的是,最常见的方法是遵循该框架。 您开始寻找使布局适合框架提供的结构的方法。

Continuing with CSS frameworks, there is also a definite lack of semantics. You end up with mixing content with presentation by providing HTML markup that uses classes like yui-gb or span-8. I understand that semanticity is not no everyone’s top 10 list of important things to do (though I do feel it should be a priority). But if semantics aren’t particularly important, why not just use tables to mark up the page. It would take less code and would work almost seamlessly browser to browser. (Please note, I am not in any way condoning the use of tables for layout…I’m just making a point.)

继续使用CSS框架,还明确缺乏语义。 通过提供使用yui-gb或span-8之类HTML标记,最终将内容与演示文稿混合在一起。 我了解语义并不是每个人都要做的十件事(尽管我确实认为应该优先考虑)。 但是,如果语义不是特别重要,为什么不只使用表来标记页面。 它将花费更少的代码,并且几乎可以在浏览器之间无缝地工作。 (请注意,我绝不宽容使用表格进行布局……我只是要说明一点。)

对于那些有兴趣的人 (For those Interested)

So, in case you’re wondering…here’s where I stand on using libraries and frameworks. For Javascript, I occasionally use a library for code, usually on larger apps. Most of my code though is hand-created, however I do try to build with reusability in mind. I guess you could say I have my own personal library that I use.

因此,如果您想知道……这就是我坚持使用库和框架的地方。 对于Javascript,我偶尔会在大型应用程序上使用库来存储代码。 虽然我的大多数代码都是手工创建的,但是我在构建代码时会考虑可重用性。 我想你可以说我有自己的个人图书馆。

As far as CSS goes…I don’t use frameworks and can’t see a time where I will actually do so. The lack of semantics rubs me the wrong way and to be honest with you, most of my CSS is not that similar from site to site. That being said, I have used reset styles of some sort on most projects, and there are a few other basic styles that I tend to include on all of my CSS, but it’s no more than a few lines. It doesn’t take me particularly long to get a layout set up in CSS, so I don’t feel like a framework would help increase my efficiency in doing so.

就CSS而言……我不使用框架,也看不到我会真正使用它的时间。 缺乏语义使我误入歧途,老实说,我的大多数CSS在不同站点之间都不太相似。 话虽这么说,我在大多数项目中都使用了某种重置样式,并且我倾向于在所有CSS中包括一些其他基本样式,但是只剩下几行。 在CSS中设置布局并不需要花费特别多的时间,因此我觉得框架不会帮助我提高效率。

That last paragraph sounds a bit harsh…but hopefully you understand that that’s just one man’s opinion. Again, I am not opposed entirely to frameworks and libraries; in fact as I said above I have used Javascript libraries in particular on more than one occasion. I just think it’s important that frameworks are used only when appropriate and as enhancements to your coding abilities…not the foundation for them.

最后一段听起来有些刺耳……但是希望您理解那只是一个人的意见。 再次,我并不完全反对框架和库。 实际上,正如我上面所说的,我已经多次使用了Javascript库。 我只是认为很重要的一点是,仅在适当时使用框架,并且将其用作增强您的编码能力的基础,而不是框架的基础。

翻译自: https://timkadlec.com/2008/05/libraries-and-frameworks/

前端框架和库的区别

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值