是否有可能的解决方案使编码过程可扩展?

发布于 2024-07-25 19:49:56 字数 202 浏览 3 评论 0原文

我们的每个程序都有一些共同点,

这都是浪费时间和精力。

当公共部分很简单时很好,但情况并非总是如此。

有没有人想过这样的问题?

目标是:

当我们进行编码时,我们只做新的部分,比如与之前完成的任何部分不相似的部分。

如果有一个好的解决方案,对于很多程序员来说将会是一个很大的安慰!

Each of our programs has something in common,

which is a waste of time and mind.

It's fine when the common part is simple,but not always the case.

Has anyone ever thought of this kind of question?

The goal is:

When we do coding,we only do the new,say,the part not similar with any part done before.

If there is a good solution,it'll be a great relief for many programmers!

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

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

发布评论

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

评论(4

天煞孤星 2024-08-01 19:49:56

这是任何库、编程语言或设计模式的要点:抽象出已解决的问题,这样就不必再次解决它们。

当然,总会有新的、更复杂的问题需要解决。 人们对于解决这些问题的正确方法存在分歧。 所以还有很多事情要做。

This is the point of any library, programming language, or design pattern: to abstract away solved problems so they don't have to be solved again.

Of course, there will always be new, more complex problems to solve. And people disagree about the right way to solve them. So there's a lot more to be done.

北座城市 2024-08-01 19:49:56

是的,我每天都在思考这个问题 - 解决方案并不简单,但它是可以实现的:始终尝试将代码中的共同点分解为可重用的工件。 这就是解决方案,但它的发生并非偶然——而是每天的努力。

Yes, I thought and think about that every single day - the solution is not simple but it is attainable: always try to factor out what is common among your code into reusable artifacts. That is the solution, but it doesn't happen by accident - it is a daily effort.

筱武穆 2024-08-01 19:49:56

有很多解决方案,从 goto、函数、类、模块或组件到库。 所有这些都允许您重用代码。

即使是最简单的 hello world 应用程序也会大量使用它。 您不必自己编写所有输出功能,您可以利用该语言的标准库以及将文本打印到屏幕的操作系统例程。

例如,即使是像 C 这样的原始语言也提供了 printf 函数来将文本打印到屏幕上,这样您就不必自己编写它。

There are plenty of solutions, ranging from gotos, to functions, to classes, to modules or components, to libraries. All of these allow you to reuse code.

Even the simplest hello world app makes heavy use of it. You don't have to write all the output functionality yourself, you can make use of the language's standard library, and the OS routines for printing text to the screen.

Even a primitive language such as C offers a printf function for printing text to the screen, for example, so that you don't have to write it yourself.

真心难拥有 2024-08-01 19:49:56

当然,代码重用是理想的情况,但存在许多实际障碍。 例如(这里主要考虑库重用):

  1. 您可能不了解现有功能,或者不知道它是否满足您的需求。 有时,找出可重用功能所需的时间比自己实现它所需的时间还要长。

  2. 现有代码可能与您需要的略有不同。 有时,直到您充分尝试重用代码之前,差异可能并不明显。

  3. 现有代码可能存在错误,这些错误只有在您的应用程序中使用时才会显现出来(#2 的特殊情况)。 调试其他人的代码通常是一个真正的挑战,特别是如果您没有可用的可修改源代码。

  4. 现有代码可能带有不适合您的整个项目的许可证限制。

  5. 现有代码可能对其他库和代码有很多依赖性,这会使您的可执行文件膨胀,使其更加脆弱,或限制您将其部署到某些环境的能力。

  6. 现有代码可能与您还想与应用程序链接的其他库冲突。

    现有

Code reuse is the ideal, of course, but there are many practical obstacles that get in the way. For example (thinking primarily of library reuse here):

  1. You might not know about the existing functionality, or know if it meets your needs. Sometimes the time needed to find out about reusable functionality is greater than the time needed to implement it yourself.

  2. The existing code may differ slightly from what you need. Sometimes the differences may not be apparent until you are well into trying to reuse the code.

  3. The existing code may have bugs that only become apparent when used in your application (a special case of #2). Debugging into other people's code is often a real challenge, particularly if you don't have modifiable source available.

  4. The existing code may come with license restrictions that are inappropriate for your project as a whole.

  5. The existing code may come with a lot of dependencies on other libraries and code, that bloat your executable, make it more fragile, or restrict your ability to deploy it to some environments.

  6. The existing code may conflict with other libraries you also want to link with your application.

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