如何有效管理 Perl 模块以实现代码重用?

发布于 2024-07-10 00:23:06 字数 566 浏览 12 评论 0原文

我的公司使用 mod_perl、axkit 和 apache 组合开发 Web 应用程序。 我们有大量的 Perl 模块、javascript 等,全部都在 unix 操作系统中。

每当我需要编写新函数时,我都会尝试重用一些代码,但问题是所有 Perl 模块和 javascript 都分散在文件夹中。

我讨厌写一些代码,后来才发现已经有一个函数做了同样的事情,我当前的方法包括尝试 grep 查找表名以查看是否存在冗余函数,但除此之外,我几乎会只是放弃并编写一个新函数,因为我不想花太多时间搜索并一无所获。

有一个更好的方法吗? 或者更好的是,是否有我可以安装的免费软件工具,它可以帮助我正确管理所有功能和模块,甚至允许开发人员记录评论等。

编辑

这个关于使用工具检测c++上的代码重复的讨论,对于unix平台中的perl代码,我们有类似的东西吗?

谢谢 〜史蒂夫

My company develop web apps using combination of mod_perl, axkit and apache.
We have tons of Perl modules, javascripts, etc, all in unix operating system.

Whenever I need to write a new function, I try to do some code reuse, but the thing is all the Perl modules and javascripts are scattered across folders.

i hate to write some code only later to discover that there's already a function which done the same thing, my current method involves trying to grep for the table name to see if there's a redundant function, but besides that, i'm pretty much will just give up and write a new function because i don't want to spend too much time searching and finding nothing.

Is there a better way to do this? Or even better, are there freeware tools that I can install which can help me properly manage all the functions and modules, and even allow developers to log comments, etc.

EDIT

There is this discussion on detecting code duplication on c++ using tools, do we have anything like this for perl codes in unix platform?

thanks
~steve

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

笔芯 2024-07-17 00:23:06

组织您的源目录,以便每个功能都只有一个位置,并且可以轻松找到某些内容。

确保共享命名约定以防止重复。

设计您的模块,使其只做一件事 - 并且做得很好。

检查代码以确保名称和位置正确。

提供基于代码索引器的高效搜索引擎,以便轻松查看是否已经有函数在执行特殊任务。

不要低估概括现有组件的时间,以便可以有效地重用它。

使用 API 文档和/或单元测试记录模块。

在团队内沟通,以便每个人都能很好地掌握可能已经编写的内容、谁拥有或知道谁可能正在处理/使用某个模块。

Organize your source directory so that each functionality has only one place where it should be and it's easy to find something.

Make sure to share naming convention to prevent duplication.

Design your module so that they do one thing only - and do it well.

Review the code to make sure names and locations are correct.

Provide a efficient search engine based on a code indexer so that it's easy to look if there is already a function doing a peculiar task.

Don't underestimate the time to generalize an existing component so that it can effectively be reused.

Document the modules, with API documentation an/or unit-tests.

Communicate within the Team so that every one has a good grasp of what has possibly been already written, who has or knows who may have working on/used a module.

还给你自由 2024-07-17 00:23:06

我相信您有某种形式的版本控制软件(svnMercurial、git,等等,但不是 VSS)? 如果您还没有,现在是时候购买并开始使用它了。 这样,您至少知道正在使用哪些模块以及代码在哪里。 您还可以使用 ctags-like 来索引您已编写(或正在使用)的所有模块)。

IDE(尽管我不喜欢这些)也可以帮助查找代码和重构。

I trust you have some form of version control software (svn, Mercurial, git, whatever but not VSS)? If you don't now is time to get one and start using it. That way, you have at least an idea of which modules you are using and where the code is. You can also use a ctags-like to index all the modules you have written (or are using).

An IDE (as much as I dislike these) can also help finding code and refactor.

迟月 2024-07-17 00:23:06

这是我非常感兴趣的事情。

使用像 svn、git 或 bazaar 这样的简单版本控制软件并不完全是我想要的。 除了这样的系统之外,VCS也是强制性的,但它不是这个系统。 经过一番研究后,我被告知要研究包装才能实现这一目标,我认为某种包装系统是可行的方法。

如果您想要打包系统的示例,请查看 debians APT。 每个包都具有版本、描述和源代码的依赖关系,并且给定一个良好的打包系统,您可以像“神奇搜索集方程固定点”一样,神奇的打包系统将找到解决问题的模块。 如果您在源代码中包含该包,它还会添加所有缺少的依赖项,例如图表等。

然而,在我的笔记本电脑硬盘坏掉之前不久就开始了对此的研究,这推迟了对该方向的进一步研究和实际结果,但也许您能够找到一些有趣的东西(并告诉我推动,推动

HTH ,
特萨

This is something I am very interested in.

Using a simple version control software like svn, git or bazaar is not exactly what I want. A VCS is mandatory in addition to such a system, but it is not this system. After some research, I have been told to look into packaging in order to achieve this, and I think, some sort of packaging system is the way to go.

If you want an example of packaging systems, look at debians APT. Each package has dependencies with versions a description and sourcecode and given a good packaging system, you can go like "magic search set equation fixpoint", and the magic packaging system is going to find a module that solves the problem. If you include the package in your source code, it would also add all missing dependencies like probably a graph and such.

However, the research into this started shortly before my laptop's hdd died, which deferred further research and actual results into this direction, but maybe you are able to find something interesting (and tell me nudge, nudge)

HTH,
Tetha

傲性难收 2024-07-17 00:23:06

如果您的模块包含 POD 文档并且安装在一个公共目录或一组目录下,那么它应该相对容易使用 pod2html 生成 HTML 文档。 获得 HTML 文档后,添加一个全文搜索索引(带有 fts3、MySQL、Lucene、KinoSearch 等的 SQLite)和一个简单的搜索表单应用程序(CGI 或 mod_perl),然后就可以开始了。

如果您使用 trac,有一个 插件 可以创建 trac wiki 页面.pod 和 .pm 文件中的页面,再次使您的文档易于搜索。

If your modules include POD documentation and are installed under a common directory or set of directories, it should be relatively easy to use pod2html to generate HTML documents. Once you have the HTML documentation, throw in a Full Text Search index (SQLite with fts3, MySQL, Lucene, KinoSearch, whatever) and a simple search form app (CGI or mod_perl) and you're ready to go.

If you're using trac, there's a plugin that will create trac wiki pages pages from your .pod and .pm files, again, making your documentation easy to search.

雨轻弹 2024-07-17 00:23:06

我曾经在一家使用 Perl 的公司工作过,也遇到过类似的问题。 我们提出的解决方案是重新组织文件中的功能,同时考虑 3 层架构(表示、业务和持久性)以及所操作的元素。

因此,我们为数据库中的每个主表分配一个 perl 文件,为每个实体分配一个 perl 文件来操纵其业务操作,依此类推...这样,很容易避免代码重复,因为您确切地知道在哪里查找给定的函数。

I've once worked in a company that used Perl, and have similar problems. The solution we come up with, was to reorganize the functions in files, taking in consideration a 3-tier architecture (presentation, business and persistence), and the elements being manipulated.

So, we have one perl file to each main table in database, one perl file for each entity to manipulate their business operations, and so on ... with this, it's easy to avoid code duplication, because you know exactly where to look for a given function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文