重用或不重用 [英] To reuse or not to reuse

查看:67
本文介绍了重用或不重用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在有一个有趣的讨论在Slashdot中运行,关于代码

重用。


讨论的主题在这里:


<引用>

Susan Elliot Sim问:在科幻小说中,''天空中的深度','Vernor Vinge描述了软件未来的未来由

''程序员考古学家'创建的,他们搜索档案中现有的

代码,将它们上下文化,并将它们组合到新的应用程序中。所以

很多复杂性和自动化已经内置到代码中,它只是不可能从头开始构建。虽然这似乎是最终代码重用幻想(或梦魇),但我们认为随着开源软件的推出,它开始发生了b $ b。我们观察了一些

项目,其中软件开发由

标识,选择和工作软件系统组合驱动。

更多通常情况下,这些组成部分是开源软件

系统,通常不能用作组件。然后使这些部分

通过包装器和粘合代码进行互操作。我们认为

这一趋势预示着未来的发展。你怎么看?

如何流行这种新软件开发的方法?什么软件

开发人员会考虑以这种方式使用他们的项目?


<结束语>


我认为这对我们来说是一个有趣的讨论。我们都做代码

重用,但不知何故,假设代码重用只能用

" advanced"有OO编程的语言和你有什么。


C,作为一种语言,我们被告知,不鼓励代码重用,它是

也是低水平。


但我期待。我实际上读过天空中的深度,

它给人留下了深刻的印象,这是一部精彩的小说。


那部分关于软件重复使我认为实际上这已经很久以前就已经发生了,因为实际上没有人从头开始

。我们都重用了其他人为我们创造的东西。


当我开始用C编写新软件时,我重用编译器系统,

编辑器,显然所有的软件和硬件都需要在处理器,电脑等上创建。不需要从头开始。


书中的那个场景也是实现

软件的分层性质。当我们重复使用一些软件时,我们会生成一个新的

代码层,希望能让我们更快地获得更高层和

的层并不代表出租的风险当我们攀登它时,我们失败了摇摇欲坠它们:-)


C中的代码重用需要很多方法,但最常见的可能是

剪切/粘贴。


我们从其他软件中获取一些软件,甚至没有b $ b有明确的界面和根本不打算重复使用。

我们只是重复使用算法。


我们主要使用一个函数或一个函数做一个简单的
任务。比如今天我想知道我是否可以写一个有理数

包(数字如2 / 3,3 / 4等),特别是最不常见的

多重算法(lcm )。所以我开始四处寻找

(软件考古学)并记得我已经为1989年已经做到这一点的lisp口译员写了这样一个包

。经过好几个小时后,在一堆旧软盘上四处看看,我找到了它,并且它似乎可以重复使用。


但是我并不满意,也许有错误,即使测试回来

然后从未显示任何错误。


Google。


Google有一个名为

http://www.google.com/codesearch


允许您搜索公共领域的广泛数据库

软件。我搜索了lcm算法,发现了一个点击


gnc-numeric.c - 一个用于会计的精确数字库

*版权所有(C) 2000 Bill Gribble


包裹中的gnotime。我看了一下这个算法,它几乎和我做的一样多了b $ b,这让人感到安心。


今天的重用或多或少都是这样的那。你搜索(考古学)

a旧软件的数据库并从该软件中取出

将它们插入到新软件中,或多或少总是用

一些修改。


显然,重用软件时有许多隐藏的假设。

最关键的一点是你只能重用一些东西如果您使用的

软件环境与旧的

软件兼容。


在小说中,Vernor Vinge假设一个稳定的社会/环境,数百万年,人类生活了数千年。

显然,这是一个理想的再利用环境,不可缺少的是什么

来自软件专家Vinge。


软件重用可以用这种方式在C中完成,因为C提供稳定的

软件环境taht现在已经很老了,即使我们的整个领域都是比较新的。

其他语言由于其最近的起源,以这种方式为软件重用提供了更少的b $ b b机会。例如,C#,

最多只有几岁,将永远不会有相同的数据库

代码为C.具有相同参数的搜索不会产生

单一匹配C#。

以下是一些语言的结果:

C 9

C ++ 3

Java 1

Ada零

C#零

Asm零

Lisp zero

Smalltalk零

Fortran零

Delphi零


显然必须有其他算法,这是不同,

,因为有些语言专门用于数值计算,或者用于IA算法中的其他语言等等。


这些只是一些想法开始讨论。


jacob

解决方案

[{snip]
< blockquote class =post_quotes>
>

C,作为一种语言,我们被告知,不鼓励代码重用,它是

太低了VEL" ;.



他们自己的语言不鼓励重复使用 - 程序员(或者是一组程序员)可以节省额外的工作在开发

和未来的维护中,无论他们写什么语言,都会隔离和重复使用

中的常用功能。

[snip]


C中的代码重用需要很多方法,但最常见的是

cut / paste。



剪切和粘贴很少见。优秀的程序员 - 和大多数C程序员一样好b $ b好​​;-) - 用任何语言知道为什么不去,也不要剪切和粘贴 -

他们称现有函数或重构现有的函数使得他们想要的

位可以作为可重复使用的函数调用。


今天的重用或多或少都是这样的。你搜索(考古学)

a旧软件的数据库并从该软件中取出

将它们插入到新软件中,或多或少总是用

一些修改。



您对考古学的使用是不是很正确 - 因为考古学不是为了重新使用而寻找东西 - 它正在研究一个较旧的文明的文物,并试图弄清楚它们是什么正在思考 - 作为一名维护分析师/程序员,我经常使用执行

考古学这个术语。在一个不同的(我认为更清楚的)意义上,试图找出一个(没有充分记录的)系统的意图是什么(b
)。

我对英格兰的古代henges也特别感兴趣 -

这些henges(土方工程)已被不同文明重复使用

数千年 - 重点他们的仪式从重点转移到月球上,专注于太阳 - 原始作品被用于与其构造完全不同的目的 - 这是真的

重新使用:-)


jacob navia< ja *** @ jacob.remcomp.frwrites:

[...]


C,作为一种语言,我们被告知,不鼓励代码重用,它是

也是低级别。



告诉谁?我不记得有人提出过这样的主张。


-

Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *< http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。


clovermanaécrit:


[{snip]


>> C,作为一种语言,我们被告知,不鼓励代码重用,它也是低级别。



他们自己的语言不鼓励重复使用 - 程序员(或者是一组程序员)可以节省额外的工作在开发

和未来的维护中,无论他们写什么语言,都会隔离和重复使用

中的常用功能。

[snip]


>> C中的代码重用需要很多方法,但最常见的可能是剪切/粘贴。



剪切和粘贴很少见。优秀的程序员 - 和大多数C程序员一样好b $ b好​​;-) - 用任何语言知道为什么不去,也不要剪切和粘贴 -

他们称现有函数或重构现有的函数使得他们想要的

位可以作为可重复使用的函数调用。



仅当代码是用于以这种方式重复使用。

通常情况下,你会发现某些函数中的代码与你想要的东西类似。例如,我在互联网上找到的代码

,lcm算法嵌入在

a更大的函数中,可以执行很多其他操作。

带有剪切/粘贴的代码重用可以只是从一个示例或另一个构建管道的软件中剪切几行

,例如,
,或者是特定的东西。


There is an interesting discussion running in Slashdot now, about code
reuse.

The thema of the discussion is here:

< quote >
Susan Elliot Sim asks: "In the science fiction novel, ''A Deepness in the
Sky,'' Vernor Vinge described a future where software is created by
''programmer archaeologists'' who search archives for existing pieces of
code, contextualize them, and combine them into new applications. So
much complexity and automation has been built into code that it is
simply infeasible to build from scratch. While this seems like the
ultimate code reuse fantasy (or nightmare), we think it''s starting to
happen with the availability of Open Source software. We have observed a
number of projects where software development is driven by the
identification, selection, and combination of working software systems.
More often than not, these constituent parts are Open Source software
systems and typically not designed to be used as components. These parts
are then made to interoperate through wrappers and glue code. We think
this trend is a harbinger of things to come. What do you think? How
prevalent is this approach to new software development? What do software
developers think about their projects being used in such a way?"

< end quote >

I think it would be an interesting discussion for us. We all do code
reuse, but somehow, it is supposed that code reuse is only done with
"advanced" languages with OO programming and what have you.

C, as a language, we are being told, doesn''t encourage code reuse, it is
too "low level".

But I am anticipating. I have actually read "A deepness in the Sky",
and it made a lasting impression, it is a wonderful novel.

That part about software reuse made me think that actually this has
already happened a LONG time ago already since actually nobody starts
from scratch. We all reuse what other people have created for us.

When I start writing a new software in C, I reuse the compiler system,
the editor, and obviously all the software and hardware needed to create
the processor, the computer, etc. Nobody starts from scratch.

That scene in the book made also realize the LAYERED nature of
software. When we reuse a bit of software we make a new LAYER of
code, hopefully a layer that allows us getting higher quicker and
doesn''t represent a risk of letting us down and crumbling when we climb
to it :-)

Code reuse in C takes many approaches, but probably the most common is
cut/paste.

We take a piece of software from some other software, that doesn''t even
have an explicit interface and wasn''t even intended to be reused at all.
We just reuse the algo.

Mostly we reuse a function, or a piece of a function doing a simple
task. For instance today I was wondering if I could write a rationals
package (numbers like 2/3, 3/4 etc), specifically a least common
multiple algorithm (lcm). So I started looking around
(software archeology) and remembered that I wrote already such a package
for a lisp interpreter back in 1989 that already did that. After several
hours looking around in the pile of old floppy disks, I found it, and
it seemed reusable.

But I wasn''t satisfied, there are maybe errors, even if the tests back
then never showed any errors in it.

Google.

Google has a feature called

http://www.google.com/codesearch

that will allow you search an extensive data base of public domain
software. I searched for lcm algorithm and found a hit in

gnc-numeric.c -- an exact-number library for accounting use
* Copyright (C) 2000 Bill Gribble

In the package "gnotime". I looked at the algorithm and it did almost
the same thing as I did, what was kind of reassuring.

Reuse today is done more or less like that. You search ("archeology")
a data base of old software and take pieces out of that software
incoporating them into the new one, more or less always with
some modifications.

Obviously there are many hidden assumptions when reusing software.
The most crucial one is that you can only reuse something if the
software environment that you are using is compatible with the old
software.

In the novel, Vernor Vinge supposes a stable society/environment of
millions of years, with human beings living several thousands of years.
Obviously that is an ideal reuse environment, what couldn''t be absent
from the mind of Vinge, a software expert.

Software reuse can be done in this way in C since C offers a stable
software environment taht is now quite old, even if our whole field
(data processing) is comparatively new.

Other languages, due to their more recent origins, offer less
opportunities for software reuse in this way. C#, for instance,
being just a few yers old at most, will never have the same database
of code as C. A search with the same parameters yielded not a
single match for C#.
Here are the results for some languages:
C 9
C++ 3
Java 1
Ada zero
C# zero
Asm zero
Lisp zero
Smalltalk zero
Fortran zero
Delphi zero

Obviously there must be other algorithms where this is different,
because some languages are specialized in numerical calculations,
others in IA algorithms, etc etc.

These are just some thoughts to start a discussion.

jacob

解决方案

[{snip]

>
C, as a language, we are being told, doesn''t encourage code reuse, it is
too "low level".

Languages in them selves do not encourage re-use - programmers (or a
group of programmers) with an eye to saving extra work, in development
and future maintenance, will isolate and re-use common functionality in
whatever language they write.
[snip]

Code reuse in C takes many approaches, but probably the most common is
cut/paste.

Cut and paste is rare. Good programmers - and most C programmers are
good ;-) - in any language know why not to, and do not cut and paste -
they call existing functions or refactor existing functions so that the
bits they want are callable as re-usable functions.

Reuse today is done more or less like that. You search ("archeology")
a data base of old software and take pieces out of that software
incoporating them into the new one, more or less always with
some modifications.

Your use of "archeology" is not quite right - because archeology is not
finding things to re-use - it is looking at the artefacts of an older
civilization, and trying to work out what they were thinking - I, as a
maintenance analyst/programmer, have often used the term "doing the
archeology" in a different (and I think clearer) sense as trying to
find out what an (insufficiently documented) system was intended to to
do.
I also have a particular interest in the ancient henges of England -
these henges (earth works) have been reused by different civilizations
over thousands of years - the focus of their rites change from focus on
the moon to focus on the sun - the original work was used for a
completely different purpose to its construction - that''s true
re-usability :-)


jacob navia <ja***@jacob.remcomp.frwrites:
[...]

C, as a language, we are being told, doesn''t encourage code reuse, it is
too "low level".

Told by whom? I don''t recall anyone making such a claim.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


cloverman a écrit :

[{snip]

>>C, as a language, we are being told, doesn''t encourage code reuse, it is
too "low level".


Languages in them selves do not encourage re-use - programmers (or a
group of programmers) with an eye to saving extra work, in development
and future maintenance, will isolate and re-use common functionality in
whatever language they write.
[snip]

>>Code reuse in C takes many approaches, but probably the most common is
cut/paste.


Cut and paste is rare. Good programmers - and most C programmers are
good ;-) - in any language know why not to, and do not cut and paste -
they call existing functions or refactor existing functions so that the
bits they want are callable as re-usable functions.

That works only if the code was intended to be reused in that fashion.
Most often than not, you find code that within some function does
something similar to what you want to do. For instance in the code
I found in the internet, the lcm algorithm is embedded within
a larger function that does a lot of other things.

Code reuse with cut/paste can be just snipping a couple of lines
from an example or from another software that builds a pipe,
for instance, or does eomething specific.


这篇关于重用或不重用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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