What Is a Glue Code?

胶水代码是一种特殊的计算机代码,用于连接不同的程序或软件组件,使它们能够协同工作。这种代码通常不执行计算或运算任务,而是作为两个不兼容软件间的中介。它可以在不同编程语言之间传递信息,也可以在相同语言的不同部分间建立联系。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

What Is a Glue Code?

Glue code is computer code that unites programs or software components that would not be compatible otherwise. This code usually does not serve a purpose such as computation or calculation, but serves exclusively as a proxy between two incompatible pieces of software. Object-oriented programming languages can be connected to scripting languages, two object-oriented languages can be connected together, or large pieces in the same language can be united by this code.

Although glue code can be used to transfer information between computer languages, it is not required to do so. Generally, it allows one piece of code to call functions in the other, or allows small data values to be passed between code blocks. Some glue code generators allow user-specified data structures to be passed between code modules, but not all of them do. Moving large pieces of data through the connecting code may not always be reliable.

Generated glue code, particularly when it connects distinct computer languages, often containscode pieces specific for each connected code module. For example, to connect C++ with Java, the generated code may include both a C++ file and a Java file. As long as no major changes are made to the structures of the connected code modules, the generated files do not need to be changed, but they may need to be updated over the course of development. Generated files such as these rarely need to be changed or maintained by a developer, and never by an end user.

Glue code can be used to connect code modules of any size, from small functions to large libraries. Depending on the amount of proxy code generated for this purpose, there may be a significant amount of code bloat and overhead, so connecting small pieces of code in this way may not always be ideal. When synchronizing calls to large libraries or merging large coderepositories, on the other hand, a small amount of glue code can be an invaluable way to bring functionality where it might otherwise be unavailable.

Extensible Markup Language (XML) data is sometimes mistaken for glue code, but the purpose of each is quite different. XML is a markup language, that is, it adds organizational and descriptive information to existing data for easier interpretation. Both can serve as a proxy to move information, but XML is static and far more limited in terms of the data it can transfer between code blocks. XML annotates and classifies data, while glue code allows for movement and manipulation of data.


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值