可重用的图书馆:好还是坏? [英] Reusable Libraries: Good or Evil?

查看:52
本文介绍了可重用的图书馆:好还是坏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于这个主题已经在其他主题中多次出现过,我以为我会给b $ b做一个单独的帖子并从(希望)收集更多变化的意见

各种新闻组参与者。


您对开发和使用广义,可重复使用的
javascript库有什么看法?


讨论要点:


1)对于典型的

(公共),25k(例如).js文件的开销是否过高网站?如果它被缓存并在许多页面上使用怎么办?

如果在内联网上使用它?如果库是25k,但用户

实际上只使用了大约15k的代码怎么办?可重复使用的库有可接受的限制吗?


2)创建包含解决方案的通用库是否有益

是否存在各种问题,并在多个页面上重复使用该库?

或者这些页面是否应仅包含所需的确切功能/代码?

3)如果可以创建一个库,它将以某种方式解决一个复杂的问题

可以重复使用,并且可以由用户在没有
$ b的情况下实现到工作页面中$ ba很多javascript知识,这是一个有效的和推荐的事情吗?

即使图书馆解决了问题,个人用户可能永远不会遇到他们的情况,导致
,导致在特定情况下,图书馆的增长幅度大于它需要的价格吗?


4)开发可重用库有什么好处?什么是

坏点?哪一个胜过另一个,在什么情况下,

对应的是真的?


我期待听到这个群体中其他人的想法!


-

Matt Kruse

Javascript工具箱: http://www.mattkruse.com/javascript/

解决方案

< blockquote> 2004年5月19日星期三22:48:10 -0500,Matt Kruse

< ne ******** @ mattkruse.com>写道:

1)对于典型的
(公共)网站,25k(例如).js文件的开销是否过高?如果它被缓存并在许多页面上使用怎么办?关于它是否在内联网上使用的方式如何?如果库是25k,但用户实际上只使用了大约15k的代码怎么办?可重用库的可接受大小是否有限制?


这是昂贵的,但谁在乎,我有更多的问题倾向

这样的作者将它传播到20个以上影响的脚本文件中/>
下载性能远远超过一些额外的k。 75k我会开始担心
担心。更大的问题不在于绝对大小,而是在它为您的页面带来的开销上,用户时间减少5%

可能无关紧要,150%可能会这样做。

2)创建一个包含广泛问题的解决方案的通用库,并在多个页面上重用该库是否有益?




这是一个难题,困难在于需要(我相信)在所有行为的这一面上提供合理的退化,

这很少适用于图书馆,你最终得到的所有

无论如何都要从图书馆中分离出降级代码,使它全部成为

有点狡猾,否定了图书馆的很多价值。


我对图书馆的体验是,它们往往会增加10美元b $ b脚本的数量或者是特定解决方案的20倍,因为不是最后的解决方案节省了大量的时间 - 人们倾向于花费更多的时间来玩他们的库中从未使用的功能

的生产代码,并且额外的复杂性很少在
中测试
愤怒。


吉姆。

-

comp.lang.javascript常见问题 - http://jibbering.com/faq/


Matt Kruse写道:

由于这个主题在其他主题中出现过几次,我以为我会单独创建一个帖子并收集意见来自(希望)更多样化的新闻组参与者。

您对开发和使用广义,可重用的JavaScript库有什么看法?


我不在乎他们。


不确定它是否符合图书馆的条件。 (可能是这样),但如果我曾经设法完成动态加载的.js文件页面,我会把它放在

外部文件中,以供超过一页。不使用

库本质上,但是为了便于维护。

讨论要点:

1)对于典型的
(公共)网站?如果它被缓存并在许多页面上使用怎么办?关于它是否在内联网上使用的方式如何?如果库是25k,但用户实际上只使用了大约15k的代码怎么办?可重用库的可接受大小是否有限制?


如果他们只需要1K的话怎么办? 25K是很多代码。我个人拥有的最大.html

文件对互联网有任何用处,只有10K以下的b $ b bad,这是最大的。并且该页面的大部分是

CSS声明。

2)创建包含解决方案的通用库是否有益于解决各种问题,并在许多页面上重用该库?
或者这些页面是否只包含它需要的确切功能/代码?


就个人而言,我更喜欢为页面量身定制的方法。

3)如果可以创建一个可以解决复杂问题的库
这是可重用的,并且可以由用户在没有大量javascript知识的情况下实现到工作页面中,这是一个有效且推荐的事情吗?
即使库解决了个别用户可能遇到的问题在他们的情况下永远不会遇到
,导致图书馆在特定情况下变得比它需要的更大?


这是我不喜欢图书馆的一部分。从未遇到/使用过的b $ b代码以及对作者使用的内容缺乏了解。它也减少了讨论。如何使用代码。

4)开发可重用库有什么好处?什么是坏点?哪一个胜过另一个,在什么情况下可能相反?




我不知道有什么好处,基于我的个人信仰。不是吗?b $ b让我变得正确,不会让我错,只是意味着我不在乎他们。

对我来说,他们属于众所周知的鱼类。给一个男人一条鱼,他吃了一天,教一个人钓鱼,他吃了一辈子。


给男人一个图书馆.. ......


-

兰迪

机会有利于准备好的心灵

comp .lang.javascript常见问题 - http://jibbering.com/faq/


Randy Webb写道:

如果他们只需要1K的话怎么办? 25K是很多代码。我个人拥有的最大的
.html文件对互联网有用,
只有10K以下,这是最大的。


我会说你是一般规则的罕见例外,然后!

网站上的大多数网站都有5万的_graphics_或更多。我有内部

应用程序的页面,这些应用程序单独有超过200k的内容(yuck)。我不确定

25k的缓存javascript - 它增加了一个页面的功能,不像

图像 - 是很多。

随着更快的互联网连接和更快的计算机被越来越多的人使用,我不知道是否关注小页面尺寸和密集

内容真的得到了回报。

根据我的个人信仰,我不知道有什么好处。


没有好处?

在团队开发网络应用程序的环境中怎么样

of比方说,15名开发人员。大多数人都有很少的javascript知识,但他们必须能够执行基本的javascript验证,实现动态选择

列表,实现弹出控件来选择数据,工具提示等?在那个

的情况下,开发一个包含最常用的

函数的库,并解释如何将它们集成到屏幕中,节省了

相当大的开发/调试/故障排除时间,以及时间

用于修复由不知道该怎么做的人写的javascript

正确的东西。不是每个人都可以成为每种技术的主人。

对我而言,它们属于众所周知的鱼类。给一个男人一条鱼,他吃了一天,教一个人钓鱼,他吃了生命。
给一个男人一个图书馆.......



希望每个希望使用javascript的人完全了解它是如何工作的,并且具备实施的技能和知识是公平的>
复杂的功能?


Javascript是一个工具。如果该工具可以用在黑匣子中,方式,

允许人们以最小的努力执行复杂的任务,

这不是一件好事吗?看看Perl,即使在CGI环境中,负载时间和代码膨胀也是一个问题 - perl社区生活并死于

模块。座右铭是,有不止一种方法可以做到这一点,但为什么要重新发明其他人已经以非常强大的方式解决的问题,

考虑到考虑到比你想象的更多的问题?这不是

同样适用于javascript吗?


事实上,我昨天使用了一个库提供工具提示:
http://www.walterzorn.com/tooltip/tooltip_e.htm
我完全知道我想做什么,这就做到了。它有比我需要的功能更多的b $ b功能,但是我能够在不到15美元的时间内实现它并且可以在各种各样的浏览器上运行,并且行为正确

我的期望。我可以从头开始写自己的,但为什么呢?这节省了大量的时间和精力。为什么要重新发明轮子,节省一些

千字节的下载?


公平地说你的主要反对意见归结为:

1)包含太多额外代码,这不是必需的,增加页面大小



2)隐藏开发人员的实施细节并不是'' t让他们学习

怎么做自己




-

马特Kruse

Javascript工具箱: http://www.mattkruse.com / javascript /


Since this topic has come up several times in other threads, I thought I''d
make a separate thread and gather opinions from (hopefully) a more varied
range of newsgroup participants.

What are your thoughts on the development and use of generalized, reusable
javascript libraries?

Discussion points:

1) Is the overhead of a 25k (for example) .js file too much for a typical
(public) web site? What if it''s cached, and used on a number of pages? How
about if it''s used on an Intranet? What if the library is 25k, but the user
only actually uses about 15k of the code? Is there a limit to acceptable
size of a reusable library?

2) Is it beneficial to create a generalized library that contains solutions
for a wide range of problems, and reuse that library on a number of pages?
Or should those pages only include the exact functions/code that it needs?

3) If a library can be created which will solve a complex problem in a way
that is reusable and can be implemented into a working page by users without
a lot of javascript knowledge, is this a valid and recommended thing to do?
Even if the library solves problems an individual user may never encounter
in their situation, causing the library to grow bigger than it needs to be
in the given situation?

4) What are the good points of developing reusable libraries? What are the
bad points? Which one outweighs the other, and in what situations might the
opposite be true?

I''m looking forward to hearing what others in this group think!

--
Matt Kruse
Javascript Toolbox: http://www.mattkruse.com/javascript/

解决方案

On Wed, 19 May 2004 22:48:10 -0500, "Matt Kruse"
<ne********@mattkruse.com> wrote:

1) Is the overhead of a 25k (for example) .js file too much for a typical
(public) web site? What if it''s cached, and used on a number of pages? How
about if it''s used on an Intranet? What if the library is 25k, but the user
only actually uses about 15k of the code? Is there a limit to acceptable
size of a reusable library?
It''s expensive but who cares, I have more problems with the tendency
of such authors to spread it over 20 script files which impacts
download performance much more than a few extra k. 75k I''d start to
worry. The bigger question though is not in absolute size, but in
overhead it brings to your page, a 5% decrease in time for the user
probably doesn''t matter, a 150% probably does.
2) Is it beneficial to create a generalized library that contains solutions
for a wide range of problems, and reuse that library on a number of pages?



This is a difficult problem, the difficulty comes in the need (that I
believe) to offer sensible degradation in this face of all behaviour,
this very rarely works well with libraries, and you end up with all
the degradation code seperate from the library anyway, making it all a
bit crufty and negating a lot of value in the library.

My experience of libraries is that they tend to increase the amount of
script by 10 or 20 times what a specific solution would do, for not a
whole lot of saved time on the final solution - People tend to spend
more time playing with features in their library that are never used
in production code, and the extra complications are rarely tested in
anger.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/


Matt Kruse wrote:

Since this topic has come up several times in other threads, I thought I''d
make a separate thread and gather opinions from (hopefully) a more varied
range of newsgroup participants.

What are your thoughts on the development and use of generalized, reusable
javascript libraries?
I don''t care for them.

Not sure if it would qualify as a "library" (probably so), but if I ever
manage to finish my dynamic loading of .js files page, I will put it in
an external file for use on more than one page. Not for the use of a
"library" per se, but to ease maintenance.
Discussion points:

1) Is the overhead of a 25k (for example) .js file too much for a typical
(public) web site? What if it''s cached, and used on a number of pages? How
about if it''s used on an Intranet? What if the library is 25k, but the user
only actually uses about 15k of the code? Is there a limit to acceptable
size of a reusable library?
What if they only need 1K of it? 25K is a lot of code. The largest .html
file I personally possess that is of any use to the internet, is only a
tad under 10K, and thats the largest. And the majority of that page is
CSS declarations.
2) Is it beneficial to create a generalized library that contains solutions
for a wide range of problems, and reuse that library on a number of pages?
Or should those pages only include the exact functions/code that it needs?
Personally, I prefer a tailored approach to the page.
3) If a library can be created which will solve a complex problem in a way
that is reusable and can be implemented into a working page by users without
a lot of javascript knowledge, is this a valid and recommended thing to do?
Even if the library solves problems an individual user may never encounter
in their situation, causing the library to grow bigger than it needs to be
in the given situation?
That is part of my dislike for libraries. The never encountered/used
code and the lack of understanding of what the author is using. It also
cuts down on the "discussion" of the use of the code.
4) What are the good points of developing reusable libraries? What are the
bad points? Which one outweighs the other, and in what situations might the
opposite be true?



I don''t know of any good points, based on my personal beliefs. Doesn''t
make me right, doesn''t make me wrong, just means I don''t care for them.
To me, they fall into the category of the proverbial fish. Give a man a
fish, he eats for a day, teach a man to fish, he eats for life.

Give a man a library.......

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/


Randy Webb wrote:

What if they only need 1K of it? 25K is a lot of code. The largest
.html file I personally possess that is of any use to the internet,
is only a tad under 10K, and thats the largest.
I would say you''re a rare exception to the general rule, then! Most sites on
the web have 50k of _graphics_ or more. I''ve had pages on internal
applications that have over 200k of content alone (yuck). I''m not sure that
25k of cached javascript - which adds functionality to a page, unlike
images - is "a lot".
With faster internet connections and faster computers being used by more and
more people, I don''t know if such a focus on small page sizes and dense
content really pays off at all.
I don''t know of any good points, based on my personal beliefs.
No good points at all?
What about in an environment where a web app is being developed by a team
of, say, 15 developers. Most have little javascript knowledge, yet they must
be able to perform basic javascript validation, implement dynamic select
lists, implement popup controls for selecting data, tooltips, etc? In that
case, developing a single library containing the most commonly-used
functions, with an explanation of how to integrate them into a screen, saves
considerable development/debugging/troubleshooting time, as well as time
spent fixing javascript written by people who don''t really know how to do
things correctly. Not everyone can be a master of every technology.
To me, they fall into the category of the proverbial fish. Give
a man a fish, he eats for a day, teach a man to fish, he eats for
life.
Give a man a library.......



Is it fair to expect everyone who wishes to use javascript to fully
understand how it works, and have the skill and knowledge to implement
complex functionality?

Javascript is a tool. If the tool can be used in a "black box" manner,
allowing people to perform complex tasks with a minimal amount of effort,
isn''t that a good thing? Look at Perl, even in a CGI environment where load
time and code bloat is a concern - the perl community lives and dies by
modules. The motto is, there''s more than one way to do it, but why reinvent
something that someone else has already solved in an extremely robust way,
taking into consideration far more issues than you''ll think of? Wouldn''t the
same apply to javascript?

In fact, I used a library just yesterday for tooltips:
http://www.walterzorn.com/tooltip/tooltip_e.htm
I knew exactly what I wanted to do, and this did it. It has more
functionality than I needed, but I was able to implement it in under 15
minutes and have it work on a wide variety of browsers, and behave exactly
how I expect. I could have written my own from scratch, but why? This saved
me considerable time and effort. Why re-invent the wheel, to save a few
kilobytes of download?

Is it fair to say that your main objections come down to:
1) too much extra code included that isn''t necessary, increasing page size
and
2) Hiding implementation details from developers doesn''t allow them to learn
how to do it themselves
?

--
Matt Kruse
Javascript Toolbox: http://www.mattkruse.com/javascript/


这篇关于可重用的图书馆:好还是坏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆